标题:[求助][求助]一个图形分割问题[求助][求助]
只看楼主
Pokemon
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-3-8
 问题点数:0 回复次数:4 
[求助][求助]一个图形分割问题[求助][求助]
我想把一个图片框中的矩形图片平均分成3X3的小矩形图片,并使它们成为相对应的9个按钮的图片,请问我该怎么做???
搜索更多相关主题的帖子: 图形 矩形 按钮 
2005-03-08 22:06
Pokemon
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-3-8
得分:0 
各位大虾,帮帮我吧......

2005-03-09 20:34
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

新建工程,点“工程”->“部件”,在列表中找到并勾选“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),然后通过程序动态创建其它按钮。

[此贴子已经被作者于2005-3-11 10:34:42编辑过]


天津网站建设 http://www./
2005-03-11 10:26
时空之蕊
Rank: 2
等 级:新手上路
威 望:3
帖 子:691
专家分:0
注 册:2004-10-31
得分:0 
不错支持

我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!
2005-03-12 00:21
时空之蕊
Rank: 2
等 级:新手上路
威 望:3
帖 子:691
专家分:0
注 册:2004-10-31
得分:0 

Dim rowPictureBox As Integer, colPictureBox As Integer '将一个图片分成多少行和列

Private Sub Command1_Click() Dim i As Integer, j As Integer, pos As Integer Dim detPicWidth As Single, detPicHeight As Single Dim picWidth As Single, picHeight As Single Dim fileName As String CommonDialog1.ShowOpen fileName = CommonDialog1.fileName picHide.Picture = LoadPicture(fileName) picHide.Refresh picWidth = picHide.Width picHeight = picHide.Height detPicWidth = picWidth / colPictureBox detPicHeight = picHeight / rowPictureBox For i = 0 To rowPictureBox - 1 For j = 0 To colPictureBox - 1 pos = i * rowPictureBox + j Picture1(pos).Width = detPicWidth Picture1(pos).Height = detPicHeight Picture1(pos).PaintPicture picHide, 0, 0, detPicWidth, detPicHeight, j * detPicWidth, i * detPicHeight, detPicWidth, detPicHeight Picture1(pos).Left = picHide.Left + picHide.Width * 1.5 + detPicWidth * j Picture1(pos).Top = picHide.Top + picHide.Height * 0.5 + detPicHeight * i Picture1(pos).Visible = True Next j Next i End Sub

Private Sub Form_Load() '如果要修改那个分割的多少情在这里修改 rowPictureBox = 2 colPictureBox = 2 Picture1(0).Visible = Fals picHide.Left = 10 picHide.Top = Me.Height * 0.3 - picHide.Height For i = 0 To rowPictureBox - 1 For j = 0 To colPictureBox - 1 pos = i * rowPictureBox + j On Error Resume Next Load Picture1(pos) Picture1(pos).Visible = False Next j Next i End Sub

[此贴子已经被作者于2005-3-12 14:50:34编辑过]


我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!
2005-03-12 14:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-13018-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.280554 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved