Help me with a Drawing Program
Author |
Message |
Juno
|
Posted: Fri May 12, 2006 1:54 pm Post subject: Help me with a Drawing Program |
|
|
I am trying to make a Paint Program and I need some help making a Drag and drop circle i have the recatngle done and have no clue how to make a circle work. Here is code for Rectangle see if you can figure it out.
code: |
Dim drawing As Boolean, my_x As Long, my_y As Long
Dim old_x As Long, old_y As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
drawing = True
old_x = X
old_y = Y
my_x = X
my_y = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If drawing Then
Me.DrawMode = vbNotXorPen
Line (my_x, my_y)-(old_x, old_y)
Line (my_x, my_y)-(X, Y)
End If
old_x = X
old_y = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
drawing = False
DrawMode = vbCopyPen
Line (my_x, my_y)-(X, Y)
End Sub |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Juno
|
Posted: Fri May 12, 2006 1:59 pm Post subject: Sorry my mistake |
|
|
This is the code for the Rectangle the other is for a line
code: |
Dim drawing As Boolean, my_x As Long, my_y As Long
Dim old_x As Long, old_y As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
drawing = True
old_x = X
old_y = Y
my_x = X
my_y = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If drawing Then
Me.DrawMode = vbNotXorPen
Line (my_x, my_y)-(old_x, old_y), , B
Line (my_x, my_y)-(X, Y), , B
End If
old_x = X
old_y = Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
drawing = False
DrawMode = vbCopyPen
Line (my_x, my_y)-(X, Y), , B
End Sub
|
|
|
|
|
|
|
Brightguy
|
Posted: Wed May 24, 2006 3:17 pm Post subject: Re: Help me with a Drawing Program |
|
|
Nice use of DrawMode there. Here's how to do ellipses just like it's done in Paint:
VisualBASIC: | Dim oldRadius As Single, newRadius As Single, oldAspect As Single, newAspect As Single
If my_x <> old_x Then
oldRadius = Max(Abs(my_x - old_x) / 2, Abs(my_y - old_y) / 2)
oldAspect = Abs((my_y - old_y) / (my_x - old_x))
Me.Circle ((my_x + old_x) / 2, (my_y + old_y) / 2), oldRadius, , , , oldAspect
End If
If my_x <> X Then
newRadius = Max(Abs(my_x - X) / 2, Abs(my_y - Y) / 2)
newAspect = Abs((my_y - Y) / (my_x - X))
Me.Circle ((my_x + X) / 2, (my_y + Y) / 2), newRadius, , , , newAspect
End If |
Put that in your Form_MouseMove, also in Form_MouseUp although only one would be necessary and you could additionally check if it'll be a horizontal line. VB doesn't have a Max function, but it's simple:
VisualBASIC: | Private Function Max(a As Single, b As Single) As Single
Max = b
If a > b Then Max = a
End Function |
|
|
|
|
|
|
|
|