在vb的picturebox中画均匀大小的方框,能在方框中输入数字,且能根据数字的大小来改变方框的颜色,谢谢指 20
展开全部
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 270
Left = 2760
TabIndex = 3
Text = "1"
Top = 2400
Width = 855
End
Begin VB.TextBox Text2
Height = 270
Left = 1320
TabIndex = 2
Text = "1"
Top = 2400
Width = 855
End
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 1695
Left = 840
ScaleHeight = 1665
ScaleWidth = 2865
TabIndex = 0
Top = 480
Width = 2895
Begin VB.TextBox Text1
Appearance = 0 'Flat
BackColor = &H00FFFFFF&
Height = 375
Index = 0
Left = 120
MultiLine = -1 'True
TabIndex = 1
Top = 120
Visible = 0 'False
Width = 1095
End
End
Begin VB.Label Label2
Caption = "列数"
Height = 255
Left = 2280
TabIndex = 5
Top = 2400
Width = 495
End
Begin VB.Label Label1
Caption = "行数"
Height = 255
Left = 840
TabIndex = 4
Top = 2400
Width = 495
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Text1(0).Height = Picture1.Height
Text1(0).Width = Picture1.Width
Text1(0).Left = 0
Text1(0).Top = 0
load text1(1)
text1(1).Visible = True
End Sub
Private Sub Text1_Change(Index As Integer)
On Error Resume Next
Text1(Index).BackColor = Text1(Index).Text
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii > 57 Or KeyAscii < 48 Then KeyAscii = 0
End Sub
Private Sub Text2_Change()
On Error Resume Next
If Text2.Text = "0" Then Text2.Text = "1"
If Text3.Text = "0" Then Text3.Text = "1"
k = 1
For i = 1 To Text3.Text
For n = 1 To Text2.Text
Load Text1(k)
Text1(k).Visible = True
Text1(k).Height = Picture1.Height / Val(Text2.Text)
Text1(k).Width = Picture1.Width / Val(Text3.Text)
Text1(k).Left = (i - 1) * Text1(k).Width
Text1(k).Top = (n - 1) * Text1(k).Height
k = k + 1
Next
Next
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii > 57 Or KeyAscii < 48 Then KeyAscii = 0
End Sub
Private Sub Text3_Change()
On Error Resume Next
If Text2.Text = "0" Then Text2.Text = "1"
If Text3.Text = "0" Then Text3.Text = "1"
k = 1
For i = 1 To Text3.Text
For n = 1 To Text2.Text
Load Text1(k)
Text1(k).Visible = True
Text1(k).Height = Picture1.Height / Val(Text2.Text)
Text1(k).Width = Picture1.Width / Val(Text3.Text)
Text1(k).Left = (i - 1) * Text1(k).Width
Text1(k).Top = (n - 1) * Text1(k).Height
k = k + 1
Next
Next
End Sub
另存为FORM1.FRM就可以了!
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 270
Left = 2760
TabIndex = 3
Text = "1"
Top = 2400
Width = 855
End
Begin VB.TextBox Text2
Height = 270
Left = 1320
TabIndex = 2
Text = "1"
Top = 2400
Width = 855
End
Begin VB.PictureBox Picture1
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 1695
Left = 840
ScaleHeight = 1665
ScaleWidth = 2865
TabIndex = 0
Top = 480
Width = 2895
Begin VB.TextBox Text1
Appearance = 0 'Flat
BackColor = &H00FFFFFF&
Height = 375
Index = 0
Left = 120
MultiLine = -1 'True
TabIndex = 1
Top = 120
Visible = 0 'False
Width = 1095
End
End
Begin VB.Label Label2
Caption = "列数"
Height = 255
Left = 2280
TabIndex = 5
Top = 2400
Width = 495
End
Begin VB.Label Label1
Caption = "行数"
Height = 255
Left = 840
TabIndex = 4
Top = 2400
Width = 495
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Text1(0).Height = Picture1.Height
Text1(0).Width = Picture1.Width
Text1(0).Left = 0
Text1(0).Top = 0
load text1(1)
text1(1).Visible = True
End Sub
Private Sub Text1_Change(Index As Integer)
On Error Resume Next
Text1(Index).BackColor = Text1(Index).Text
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii > 57 Or KeyAscii < 48 Then KeyAscii = 0
End Sub
Private Sub Text2_Change()
On Error Resume Next
If Text2.Text = "0" Then Text2.Text = "1"
If Text3.Text = "0" Then Text3.Text = "1"
k = 1
For i = 1 To Text3.Text
For n = 1 To Text2.Text
Load Text1(k)
Text1(k).Visible = True
Text1(k).Height = Picture1.Height / Val(Text2.Text)
Text1(k).Width = Picture1.Width / Val(Text3.Text)
Text1(k).Left = (i - 1) * Text1(k).Width
Text1(k).Top = (n - 1) * Text1(k).Height
k = k + 1
Next
Next
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii > 57 Or KeyAscii < 48 Then KeyAscii = 0
End Sub
Private Sub Text3_Change()
On Error Resume Next
If Text2.Text = "0" Then Text2.Text = "1"
If Text3.Text = "0" Then Text3.Text = "1"
k = 1
For i = 1 To Text3.Text
For n = 1 To Text2.Text
Load Text1(k)
Text1(k).Visible = True
Text1(k).Height = Picture1.Height / Val(Text2.Text)
Text1(k).Width = Picture1.Width / Val(Text3.Text)
Text1(k).Left = (i - 1) * Text1(k).Width
Text1(k).Top = (n - 1) * Text1(k).Height
k = k + 1
Next
Next
End Sub
另存为FORM1.FRM就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
picturebox不能接收文字,需要画一个文本框(名称为Text1)。然后编写程序如下,即可。
我用QBColor表示的颜色,还可以用rgb等函数,但是需要输入多个数据(参考相关书籍)。
Private Sub Text1_Change()
If Val(Text1.Text) >= 0 And Val(Text1.Text) <= 15 Then
Picture1.BackColor = QBColor(Val(Text1.Text))
Else
MsgBox "数据输入错误,请重新输入!"
End If
End Sub
我用QBColor表示的颜色,还可以用rgb等函数,但是需要输入多个数据(参考相关书籍)。
Private Sub Text1_Change()
If Val(Text1.Text) >= 0 And Val(Text1.Text) <= 15 Then
Picture1.BackColor = QBColor(Val(Text1.Text))
Else
MsgBox "数据输入错误,请重新输入!"
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询