473,473 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Line Help

9 New Member
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
Nov 28 '07 #1
7 1244
Killer42
8,435 Recognized Expert Expert
You haven't made it clear which one works, and which doesn't. Or what happens when it doesn't work.
Nov 28 '07 #2
CyberSoftHari
487 Recognized Expert Contributor
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?
Nov 28 '07 #3
sandezco
9 New Member
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.
Nov 28 '07 #4
CyberSoftHari
487 Recognized Expert Contributor
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.)
Nov 28 '07 #5
sandezco
9 New Member
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.)
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:

Expand|Select|Wrap|Line Numbers
  1. graphicsObject.DrawLine(New Pen(Color.Black), x1, y1, x2, y2)
  2.  
  3. Public Class LineLengthForm
  4.  
  5.     Dim x1 As Integer
  6.     Dim x2 As Integer
  7.     Dim y1 As Integer
  8.     Dim y2 As Integer
  9.  
  10.     ' specify whether moving the mouse should erase
  11.     Private shouldErase As Boolean = False
  12.  
  13.     ' specify whether moving the mouse should draw
  14.     Private shouldDraw As Boolean = False
  15.  
  16.     ' set diameter of MouseDown line
  17.     Private Const DIAMETER As Integer = 8
  18.  
  19.     ' create and initialize Graphics object
  20.     Private graphicsObject As Graphics = CreateGraphics()
  21.  
  22.     ' handles LineLength's MouseDown event
  23.     Private Sub LineLengthForm_MouseDown(ByVal sender As Object, _
  24.     ByVal e As System.Windows.Forms.MouseEventArgs) _
  25.     Handles Me.MouseDown
  26.  
  27.         ' draw on Form if the left button is held down
  28.         If e.Button = Windows.Forms.MouseButtons.Left Then
  29.             shouldDraw = True
  30.             ' erase black lines if right button is held down
  31.         ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
  32.             shouldErase = True
  33.         End If
  34.     End Sub ' MouseDown
  35.  
  36.     ' handles LineLengthForm's MouseMove event
  37.     Private Sub LineLengthForm_MouseMove(ByVal sender As Object, _
  38.     ByVal e As System.Windows.Forms.MouseEventArgs) _
  39.     Handles Me.MouseMove
  40.  
  41.         ' draw line if mouse button is pressed
  42.         If shouldDraw = True Then
  43.             graphicsObject.DrawLine(New Pen(Color.Black), _
  44.             e.X, e.Y, DIAMETER, DIAMETER)
  45.             ' mouse pointer "erases" if right mouse button is pressed
  46.         ElseIf shouldErase = True Then
  47.             graphicsObject.DrawLine(New Pen(BackColor), _
  48.             e.X, e.Y, DIAMETER, DIAMETER)
  49.         End If
  50.     End Sub 'LineLength_MouseMove
  51.  
  52.     ' handle LineLength's MouseUp event
  53.     Private Sub LineLengthForm_MouseUp(ByVal sender As Object, _
  54.     ByVal e As System.Windows.Forms.MouseEventArgs) _
  55.     Handles Me.MouseUp
  56.  
  57.         shouldDraw = False ' do not draw on the form
  58.         shouldErase = False ' do not erase
  59.     End Sub 'LineLength_MouseUp
Nov 28 '07 #6
CyberSoftHari
487 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. graphicsObject.DrawLine(New Pen(Color.Black), _
  2.             e.X, e.Y, DIAMETER, DIAMETER)
here you have to change like
Expand|Select|Wrap|Line Numbers
  1. graphicsObject.DrawLine(New Pen(Color.Black), _
  2.             X1, Y1, e.X, e.Y)
and in mouse down event

Expand|Select|Wrap|Line Numbers
  1. Private Sub LineLengthForm_MouseDown(ByVal sender As Object, _
  2.     ByVal e As System.Windows.Forms.MouseEventArgs) _
  3.     Handles Me.MouseDown
  4.  
  5.         ' draw on Form if the left button is held down
  6.         If e.Button = Windows.Forms.MouseButtons.Left Then
  7.             shouldDraw = True
  8.             ' erase black lines if right button is held down
  9.         ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
  10.             shouldErase = True
  11.         End If
  12.         X1 = e.X
  13.         Y1 = e.Y
  14.     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).
Nov 29 '07 #7
sandezco
9 New Member
Thanks for the insight!!!!!!!!!!!
Nov 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
11
by: name | last post by:
Here is a first attempt at a line/word wrapping utility. Seems to work okay, but lacks some checking stuff, etc. --------------------------------------------------------- #include <stdio.h>...
9
by: Steve Long | last post by:
Hello, (total GDI newbie) I'm having trouble drawing just a simple line to display in a picturebox. I just want a straight, dotdash line. I have two methods, one works and one doesn't (it cause...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
13
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or...
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
4
by: Vernon Wenberg III | last post by:
I'm not really sure how readline() works. Is there a way to iterate through a file with multiple lines and then putting each line in a variable in a loop?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.