'Form1 - Форма управления (Стартовая)
'Form2 - Форма рисования
'на Form1 нужно положить
' 5 Label
' 4 TextBox
' 1 ComboBox
' 1 Timer
'В Form1
Option Explicit
Private Type Rect
X1 As Long
Y1 As Long
X2 As Long
Y2 As Long
End Type
Const RECTS_COUNT As Integer = 15
'Если прямоугольников несколько
Private Rects(RECTS_COUNT) As Rect
Private Sub Form_Load()
Dim I As Integer
With Me
.Caption = "Форма управления"
.Left = 0
.Top = 0
.Height = 2355
.Width = 2430
End With
With Label1
.Caption = "1"
.Left = 150
.Top = 1050
.AutoSize = True
End With
With Label2
.Caption = "2"
.Left = 165
.Top = 1440
.AutoSize = True
End With
With Label3
.Caption = "X"
.Left = 765
.Top = 750
.AutoSize = True
End With
With Label4
.Caption = "Y"
.Left = 1635
.Top = 720
.AutoSize = True
End With
With Text1
.Left = 420
.Top = 1005
.Width = 795
.Height = 285
.Text = 0
.Alignment = 1
End With
With Text2
.Left = 1290
.Top = 1005
.Width = 795
.Height = 285
.Text = 0
.Alignment = 1
End With
With Text3
.Left = 420
.Top = 1395
.Width = 795
.Height = 285
.Text = 0
.Alignment = 1
End With
With Text4
.Left = 1290
.Top = 1395
.Width = 795
.Height = 285
.Text = 0
.Alignment = 1
End With
Randomize
With Combo1
.Left = 1485
.Top = 315
.Width = 600
.Clear
For I = 0 To RECTS_COUNT
Combo1.AddItem I
Rects(I).X1 = Rnd() * 400
Rects(I).Y1 = Rnd() * 300
Rects(I).X2 = Rnd() * 400
Rects(I).Y2 = Rnd() * 300
Next I
Combo1.Text = 0
End With
Form2.Show
With Form2
.Left = 2355
.Top = 2430
.Height = 4905
.Width = 6120
.ScaleMode = 3
End With
DrawRect
With Timer1
.Interval = 100
.Tag = "*"
.Enabled = True
End With
End Sub
Private Sub Combo1_Click()
Text1.Text = Rects(Val(Combo1.Text)).X1
Text2.Text = Rects(Val(Combo1.Text)).Y1
Text3.Text = Rects(Val(Combo1.Text)).X2
Text4.Text = Rects(Val(Combo1.Text)).Y2
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text4.SetFocus
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo1.SetFocus
End If
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SetFocus
End If
End Sub
Private Sub Text1_LostFocus()
Rects(Val(Combo1.Text)).X1 = Val(Text1.Text)
DrawRect
End Sub
Private Sub Text2_LostFocus()
Rects(Val(Combo1.Text)).Y1 = Val(Text2.Text)
DrawRect
End Sub
Private Sub Text3_LostFocus()
Rects(Val(Combo1.Text)).X2 = Val(Text3.Text)
DrawRect
End Sub
Private Sub Text4_LostFocus()
Rects(Val(Combo1.Text)).Y2 = Val(Text4.Text)
DrawRect
End Sub
Private Sub DrawRect()
Dim I As Integer
Form2.Cls
For I = 0 To RECTS_COUNT
Form2.ForeColor = QBColor(I)
Form2.GrapchicsRefresh Rects(I).X1, Rects(I).Y1, Rects(I).X2, Rects(I).Y2
Next I
End Sub
Private Sub Timer1_Timer()
If Timer1.Tag = "*" Then
Form2.ForeColor = Form2.BackColor
Form2.GrapchicsRefresh Rects(Combo1.Text).X1, Rects(Combo1.Text).Y1, Rects(Combo1.Text).X2, Rects(Combo1.Text).Y2
Timer1.Tag = ""
Else
Form2.ForeColor = QBColor(Combo1.Text)
Form2.GrapchicsRefresh Rects(Combo1.Text).X1, Rects(Combo1.Text).Y1, Rects(Combo1.Text).X2, Rects(Combo1.Text).Y2
Timer1.Tag = "*"
End If
End Sub
'В Form2
'Option Explicit
'
'Public Sub GrapchicsRefresh(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long)
' Line (X1, Y1)-(X2, Y2),, B
'End Sub
Сейчас этот форум просматривают: С.Т. и гости: 3