473,788 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1180
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.A llPaintingInWmP aint Or _
ControlStyles.D oubleBuffer Or _
ControlStyles.R esizeRedraw Or _
ControlStyles.U serPaint, _
True)
End Sub

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

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

MyBase.OnMouseD own(e)
End Sub

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

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

MyBase.OnMouseM ove(e)
End Sub

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

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

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

If m_IsPainting AndAlso e.Button = MouseButtons.Le ft 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
6165
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 info.ShellExecute = false; Process p1 = ProcessStart(info); Problem arises on complicated pathnames. If the string returned in info.Arguments is in say c:\pics\pic1.bmp then it loads fine. Only when
4
5161
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 define line. Dim point1 As New Point(100, 100) Dim point2 As New Point(500, 100)
2
3138
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 get all kinds of screen artifacts and weirdness. My general goal is: list item with a few areas for text, every other item shaded a light color for readability, font color changes with selection. The listbox is populated with custom structurs...
4
30826
by: Jason Huang | last post by:
Hi, In my C# Windows Form, how do I draw a Line? Thanks for help. Jason
1
2123
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 through code to draw a line. But the line does not draw on the panel until I press either the Alt key or Tab key. Here is my code: Sub rad_Click(...)handles... Me.Invalidate()
1
12721
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 konw how to draw line betwwen the marked points The output for my function will be like this , So the marked point (*) should be connected through lines,
9
4028
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 reference to a control or a form. I guess it means that lines can't be draw on blank area between two forms. Can anybody guarantee this for me? Is there any method can realize this function? I mainly want to draw a line from a button in form1 to...
3
2426
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 START and typed in the command myself.
8
19501
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 time. I am using Access 2007. Dim retVal retVal = Shell("c:\windows\system32\mspaint.exe", vbMaximizedFocus)
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.