473,387 Members | 1,497 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 a line as in MSPaint

hi all,

I'm trying to draw lines from an origin to the coordinate of the mouse. As
the mouse moves, the line will follow the mouse's movement and previous
lines are then erased.

any suggestions on how to achieve this efficiently? Thanks in advance.
Nov 20 '05 #1
5 1157
Cor
Hi Kerpall,

In this are a lot of samples that helps you in the right direction

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbr...q/#installvdir

I hope this helps a little bit?

Cor

I'm trying to draw lines from an origin to the coordinate of the mouse. As the mouse moves, the line will follow the mouse's movement and previous
lines are then erased.

any suggestions on how to achieve this efficiently? Thanks in advance.

Nov 20 '05 #2
"kerpal" <l@m.n> schrieb
hi all,

I'm trying to draw lines from an origin to the coordinate of the
mouse. As the mouse moves, the line will follow the mouse's movement
and previous lines are then erased.

any suggestions on how to achieve this efficiently? Thanks in
advance.

Not 1:1 what you need, but you can change it to fit your needs:
Private Class PaintControl
Inherits Control

Private m_IsPainting As Boolean
Private m_StartPos, m_EndPos As Point

Public Sub New()
setstyle( _
ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.ResizeRedraw Or _
ControlStyles.UserPaint, _
True)
End Sub

Protected Overrides Sub OnMouseDown( _
ByVal e As System.Windows.Forms.MouseEventArgs)

If Not m_IsPainting AndAlso e.Button = MouseButtons.Left Then
m_StartPos.X = e.X
m_StartPos.Y = e.Y
m_EndPos = m_StartPos
m_IsPainting = True
End If

MyBase.OnMouseDown(e)
End Sub

Protected Overrides Sub OnMouseMove( _
ByVal e As System.Windows.Forms.MouseEventArgs)

If m_IsPainting Then
If (e.Button And MouseButtons.Left) = MouseButtons.Left Then
m_EndPos.X = e.X
m_EndPos.Y = e.Y
Else
m_IsPainting = False
End If
Invalidate()
End If

MyBase.OnMouseMove(e)
End Sub

Protected Overrides Sub OnPaint( _
ByVal e As System.Windows.Forms.PaintEventArgs)

If m_IsPainting Then
e.Graphics.DrawLine(Pens.White, m_StartPos, m_EndPos)
End If
End Sub

Protected Overrides Sub OnMouseUp( _
ByVal e As System.Windows.Forms.MouseEventArgs)

If m_IsPainting AndAlso e.Button = MouseButtons.Left Then
m_IsPainting = False
Invalidate()
End If
End Sub

Public ReadOnly Property IsPainting() As Boolean
Get
Return m_IsPainting
End Get
End Property
End Class
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Cor
Hi Armin,

Is this original by you?
(I add that when I give this code to some else you know)
(waiting if you would do that of course or in a newsgroup where you are not
active)

And thanks for that hind about chrismass.

I say merry chrismas to you on a later time of the day.

:-)

Cor

Nov 20 '05 #4
"Cor" <no*@non.com> schrieb
Hi Armin,

Is this original by you?
yes
(I add that when I give this code to some else you know)
Why only to someone else I know? *g*
(waiting if you would do that of course or in a newsgroup where you
are not active)
yes yes, of course
And thanks for that hind about chrismass.

I say merry chrismas to you on a later time of the day.

:-)


Yes, merry ChrisTmas!

:-)))
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Cor
Hi Armin,

Lol about all lines.
Yes, merry ChrisTmas!


Now you can see I do not use a spellchecker.
Nock nock on my head.
I know your normal answer; there is no need to send it.

:-)))

Cor


Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tam | last post by:
Having problems with this code. ProcessStartInfo info = new ProcessStartInfo(); info.FileName = ("mspaint.exe"); info.Arguments = image.getFileName; // returns full path and name...
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: Rich | last post by:
Hello, I have a form with a panel which contains a radiobutton. When I click the radiobutton, I invoke the Paint event of the panel using me.Invalidate. The paint event gets called and runs...
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...
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...
3
by: MLH | last post by:
What's the best way to launch MSPAINT c:\image.bmp from a VBA procedure. Seeking the route with the least number of complications. Hopefully there will be no more complications than if I clicked...
8
by: cobolguy | last post by:
I can execute mspaint using VBA but I have not been successful trying to open a .jpg image file. This command works to execute mspaint but I do not know how to excute and bring up a file at the same...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.