473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Draw Straight line on picutrebox?

Im having trouble making a Paint.exe straight line draw.

You know the one where you point out where to start then hold down the
mouse button and release it to finish the drawing. My problem is that
if i move the mouse back the line should move back with it and if i
spin the mouse the line should spin and dont draw anything before i release
the button.
im using Microsoft visual stuido.net 2003


Heres my code now:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ritfält.Image = New Bitmap(ritfält.Width, ritfält.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Grafik = Graphics.FromImage(ritfält.Image)
Grafik.Clear(Color.White)
End Sub

'mouse move in the picturebox
Private Sub ritfält_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ritfält.MouseMove
If drawing = True Then
If Not e.Button = MouseButtons.Left Then Exit Sub Else
Grafik = ritfält.CreateGraphics
Färg = Color.FromName(CStr(PennFärg))
Penna = New Pen(Färg, 2)
Grafik.DrawLine(Penna, sngx, sngy, e.X, e.Y)
sngx = e.X
sngy = e.Y
'force a redraw
Me.ritfält.Refresh()
End If
End Sub

'mouse down in the picturebox
dragging = true
sngx = e.X
sngy = e.Y

'mouseup in the picturebox
dragging = false
Dec 19 '06 #1
0 1203

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

Similar topics

5
by: Matt | last post by:
I am writing a recursive program to draw the lines recursively, given the range and number of intervals (n) between the range. The problem is I don't know how to draw the line in point 0.375, as...
1
by: Michael Rodriguez | last post by:
In Delphi there was a control called a Bevel. It would let you draw straight lines, top, left, right, or bottom, anywhere on your screen. What is the equivalent in C#? How can I draw a straight...
1
by: Juan Romero | last post by:
Hey guys, I am trying to draw a vertical line in a class of mine that inherits from the RichTextBox control, but for some reason the line won't be drawn. Here is the code, fairly straight...
4
by: thomasp | last post by:
I found the following code on MSDN to draw a line in VB2005. Public Sub DrawLinePoint(ByVal e As PaintEventArgs) ' Create pen. Dim blackPen As New Pen(Color.Black, 3) ' Create points that...
2
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I...
4
by: Jason Huang | last post by:
Hi, In my C# Windows Form, how do I draw a Line? Thanks for help. Jason
1
by: balakrishnan.dinesh | last post by:
Hi frnds, Im creating function to plot line graph in javascript . I have marked the points in graph. but what i need to do is, i want to draw the line between those marked point, but i dont...
5
by: lgeastwood | last post by:
I have tweaked the PictureBox97.mdb (Stephen Lebans <www.lebans.com>) code to nicely draw lines, rectangles and circles to the specs that I input. I'm at a loss though with trying to setup an...
9
by: zhaow | last post by:
Hi, All Greetings! I want to develop as appllication that requires a line-drawing function in the blank area between two forms. I have looked up the MSDN, it says that a graphics object need a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.