一個圖形分割問題[答網友]

新建工程,點“工程”->“部件”,在列表中找到並勾選“Microsoft PictureClip Control 6.0”將其添加到工具箱。

在窗體中添加一個PictureClip控件,設置它的Picture屬性裝載一副圖像,設置PictureClip控件的Col屬性爲3(3列),Row屬性爲3(3行)。

然後添加一個CommandButton控件Command1,設置其Style爲1(圖形按鈕),再複製8個Command1,提示是否創建控件數組時點“是”,再添加一個CommandButton控件Command2,將Caption屬性設爲“轉換”

如下圖:

按此在新窗口瀏覽圖片

在窗體中添加以下代碼:
Option Explicit

Private Sub Command2_Click()
Dim i As Integer, j As Integer

    For i = 0 To 8
        Command1(i).Caption = "" '去掉文字
        Command1(i).Picture = PictureClip1.GraphicCell(i)
        Command1(i).Width = PictureClip1.CellWidth * 15
        Command1(i).Height = PictureClip1.CellHeight * 15
        If i Mod 3 = 0 Then
            j = j + 1
        End If
        
        If i Mod 3 <> 0 Then
            Command1(i).Move Command1(i - 1).Left + Command1(i - 1).Width, Command1(0).Top + (j - 1) * Command1(0).Height
        Else
            If i <> 0 Then
                Command1(i).Move Command1(0).Left, Command1(i - 1).Top + Command1(i - 1).Height
            End If
        End If
    Next
End Sub


運行:


按此在新窗口瀏覽圖片

點擊“轉換”

按此在新窗口瀏覽圖片

實際應用中可能將圖片分成的塊數不一定,所以按鈕可以只創建一個(index設爲0),然後通過程序動態創建其它按鈕。

發佈了46 篇原創文章 · 獲贊 3 · 訪問量 29萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章