 |
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: on line and shape controls Archived to Disk
If you really want to do it at runtime (and not just put the controls on the form, and hide them until needed), see: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q190670 for help (it'd be easier).
Or copy the following text:
Option Explicit
Dim WithEvents ctlLine As VB.Line
Dim WithEvents ctlShape As VB.Shape
Private Sub Form_Load()
Dim i As Integer
' add line
Set ctlLine = Controls.Add("VB.Line", "ctlline", Form1)
With ctlLine
.X1 = 10
.X2 = Me.Width
.Y1 = 1000
.Y2 = 1000
.Visible = True
End With
Set ctlShape = Controls.Add("VB.Shape", "ctlShape", Form1)
With ctlShape
.Move 50, 50, Me.ScaleWidth - 100, Me.ScaleHeight - 100
.Visible = True
End With
End Sub
|
|
23-04-2002 at 05:51 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: on line and shape controls Archived to Disk
Or as another way to move the control:
Option Explicit
Dim WithEvents ctlLine As VB.Line
Dim WithEvents ctlShape As VB.Shape
Dim fMoving As Boolean
Private Sub Form_Load()
Dim i As Integer
' add line
Set ctlLine = Controls.Add("VB.Line", "ctlline", Form1)
With ctlLine
.X1 = 10
.X2 = Me.Width
.Y1 = 1000
.Y2 = 1000
.Visible = True
End With
Set ctlShape = Controls.Add("VB.Shape", "ctlShape", Form1)
With ctlShape
.Move 50, 50, Me.ScaleWidth - 100, Me.ScaleHeight - 100
.Visible = True
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not fMoving And Button = 1 Then
If X >= ctlShape.Left And X <= ctlShape.Width + ctlShape.Left Then
If Y >= ctlShape.Top And Y <= ctlShape.Height + ctlShape.Top Then
fMoving = True
End If
End If
ElseIf Button <> 1 Then
fMoving = False
End If
If fMoving Then
ctlShape.Move X, Y
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
fMoving = False
End Sub
|
|
25-04-2002 at 05:41 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: on line and shape controls Archived to Disk
I would've updated the last post, but it still not possible...
Option Explicit
Private Type tCoords
X As Single
Y As Single
End Type
Private WithEvents ctlLine As VB.Line
Private WithEvents ctlShape As VB.Shape
Private fMoving As Boolean
Private tMoving As tCoords
Private Sub Form_Load()
Dim i As Integer
' add line
Set ctlLine = Controls.Add("VB.Line", "ctlline", Form1)
With ctlLine
.X1 = 10
.X2 = Me.Width
.Y1 = 1000
.Y2 = 1000
.Visible = True
End With
Set ctlShape = Controls.Add("VB.Shape", "ctlShape", Form1)
With ctlShape
.Move 50, 50, Me.ScaleWidth - 100, Me.ScaleHeight - 100
.Visible = True
End With
With tMoving
.X = -1
.Y = -1
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not fMoving And Button = 1 Then
If X >= ctlShape.Left And X <= ctlShape.Width + ctlShape.Left Then
If Y >= ctlShape.Top And Y <= ctlShape.Height + ctlShape.Top Then
fMoving = True
End If
End If
ElseIf Button <> 1 Then
fMoving = False
End If
If fMoving Then
' If values = -1 then we haven't stored the starup X,Y
If tMoving.X = -1 And tMoving.Y = -1 Then
tMoving.X = X
tMoving.Y = Y
Else
' Move the shape the current position - the difference of the mouse move
' if last X-current X = positive, then move to left (current left - x)
' if last X-current X = negative, then move to right (current left - -x = left + x)
ctlShape.Move ctlShape.Left - (tMoving.X - X), ctlShape.Top - (tMoving.Y - Y)
tMoving.X = X
tMoving.Y = Y
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' We're not moving, reset the variables
fMoving = False
With tMoving
.X = -1
.Y = -1
End With
End Sub
|
|
25-04-2002 at 04:13 PM |
|
|
|
|
 |
 |