|
|
|
|
|
|
|
I can't draw lines!!!
|
|
| Author Name |
Status |
Posted Time |
| Rebbecca Stein |
|
12/6/2007 3:54:25 AM |
| Author is Offline |
|
Hi all, I am working a problem VB-2005 and I am a little confused. If I used the following, I can draw lines. But if I try to use what lesson calls for I cannot draw lines. graphicsObject.DrawLine(New Pen(Color.Black), _ e.X, e.Y, DIAMETER, DIAMETER)
Versus
graphicsObject.DrawLine(New Pen(Color.Black), _ x1, y1, x2, y2) is this because I used the following statement ealier in the program?
' set diameter of MouseDown line Private Const DIAMETER As Integer = 8
|
|
|
| Subject |
Author |
Status |
Date |
Re: I can't draw lines!!!
|
Dang Kettle |
|
12/7/2007 3:14:32 AM |
Rebecca, You haven't made it clear which one works, and which doesn't. Or what happens when it doesn't work. Post Comments |
|
Re: I can't draw lines!!!
|
Evzon Ologio |
|
12/7/2007 3:27:25 AM |
Rebecca You never point which event you are coding this and what is the value of x1,y1 and x2,y2! Is it x1,y1 and x2,y2 are constant or following the mouse pointer?
Post Comments |
|
Re: GraphicsObject.DrawLine(
|
Rebbecca Stein |
|
12/7/2007 3:33:20 AM |
graphicsObject.DrawLine(New Pen(Color.Black), _ e.X, e.Y, DIAMETER, DIAMETER)
This one works (and it is following the mouse) my eventual goal is going to be to calculate the distance between end points of this line. Post Comments |
|
Re: Post what you did in your code
|
Evzon Ologio |
|
12/7/2007 3:34:52 AM |
First post what you did in your code and describe about your problem in detail. (Do not simply post 2 or 3 line of code.)
Post Comments |
|
Re: Here is my Code!
|
Rebbecca Stein |
|
12/7/2007 3:35:55 AM |
Here is what I have so far, most of it was based off of an example. I am suppose to use the following, but when I do I can not draw the line:
Code: ( vbnet ) -
graphicsObject.DrawLine(New Pen(Color.Black), x1, y1, x2, y2) -
-
Public Class LineLengthForm -
-
Dim x1 As Integer -
Dim x2 As Integer -
Dim y1 As Integer -
Dim y2 As Integer -
-
' specify whether moving the mouse should erase -
Private shouldErase As Boolean = False -
-
' specify whether moving the mouse should draw -
Private shouldDraw As Boolean = False -
-
' set diameter of MouseDown line -
Private Const DIAMETER As Integer = 8 -
-
' create and initialize Graphics object -
Private graphicsObject As Graphics = CreateGraphics() -
-
' handles LineLength's MouseDown event -
Private Sub LineLengthForm_MouseDown(ByVal sender As Object, _ -
ByVal e As System.Windows.Forms.MouseEventArgs) _ -
Handles Me.MouseDown -
-
' draw on Form if the left button is held down -
If e.Button = Windows.Forms.MouseButtons.Left Then -
shouldDraw = True -
' erase black lines if right button is held down -
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then -
shouldErase = True -
End If -
End Sub ' MouseDown -
-
' handles LineLengthForm's MouseMove event -
Private Sub LineLengthForm_MouseMove(ByVal sender As Object, _ -
ByVal e As System.Windows.Forms.MouseEventArgs) _ -
Handles Me.MouseMove -
-
' draw line if mouse button is pressed -
If shouldDraw = True Then -
graphicsObject.DrawLine(New Pen(Color.Black), _ -
e.X, e.Y, DIAMETER, DIAMETER) -
' mouse pointer "erases" if right mouse button is pressed -
ElseIf shouldErase = True Then -
graphicsObject.DrawLine(New Pen(BackColor), _ -
e.X, e.Y, DIAMETER, DIAMETER) -
End If -
End Sub 'LineLength_MouseMove -
-
' handle LineLength's MouseUp event -
Private Sub LineLengthForm_MouseUp(ByVal sender As Object, _ -
ByVal e As System.Windows.Forms.MouseEventArgs) _ -
Handles Me.MouseUp -
-
shouldDraw = False ' do not draw on the form -
shouldErase = False ' do not erase -
End Sub 'LineLength_MouseUp
Post Comments |
|
Re: Make some changes
|
Evzon Ologio |
|
12/7/2007 3:36:58 AM |
Code: ( vbnet ) graphicsObject.DrawLine(New Pen(Color.Black), _
e.X, e.Y, DIAMETER, DIAMETER)
here you have to change like
Code: ( vbnet ) graphicsObject.DrawLine(New Pen(Color.Black), _
X1, Y1, e.X, e.Y)
and in mouse down event
Code: ( vbnet ) Private Sub LineLengthForm_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseDown
' draw on Form if the left button is held down
If e.Button = Windows.Forms.MouseButtons.Left Then
shouldDraw = True
' erase black lines if right button is held down
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
shouldErase = True
End If
X1 = e.X
Y1 = e.Y
End Sub ' MouseDown
and in mouse up X1 and Y1 to 0 and same thing apply to errase logic. Note : This code will draw line to start and end point of mouse pointer. so it will not be a single line (it will look like shaded line, you don't draw a Straight line).
Post Comments |
|
Re: Thanks a lot!!!
|
Rebbecca Stein |
|
12/7/2007 3:37:45 AM |
Thanks for the insight!!!!!!!!!!! Post Comments |
|
|
|
|
|
|
|
|
No Related Articles |
|
|
|
|
|