Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
pls, pls , how to draw point on picturebox using with small example as you can , thinks
Posted 31-Jan-13 1:23am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This is a double bad idea. First, do you really need to draw one point? I doubt it. Usually, you need to draw many points, so drawing anything point by point is prohibitively slow. If you need it, you need to do it only on a bitmap, using this:[^].
There is a similar approach for WPF, which you are probably not using here.
Another big misconception is using PictureBox. You never ever need to use this control for anything except a static image. In principle you could, but it would be totally redundant, not helping you at all, only wasting your development time, and run-time resources. You need to render some image on a bitmap or on screen. PictureBox is nothing but a middleman for this, to simplify the chores, but only for the simplest situation. I will explain what to do instead, if you need to draw anything on screen, which always means in some control. Draw in this control, nowhere else! Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].
For more detail, please see:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my application?[^].
As I say, if you really need to draw something point-by-point with many points, you still should better draw on a bitmap (a bitmap, not PictureBox!), and then draw it, if you need, using System.Drawing.Graphics.DrawImage. Note that in this case you should not use double buffering, at least is the situation where this bitmap is all you draw.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Public Class Lines
	Public startPoint As New Point()
	Public endPoint As New Point()
End Class
Private l As New Lines()
Private allLines As New List(Of Lines)()
Private Sub pictureBox1_MouseMove(sender As Object, e As MouseEventArgs)
	'collect endPoint when mouse moved
	If (e.Button And MouseButtons.Left) = MouseButtons.Left Then
		l.endPoint = e.Location
		'Line completed
	End If
End Sub
Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs)
	'collect startPoint when left mouse clicked
	If (e.Button And MouseButtons.Left) = MouseButtons.Left Then
		l = New Lines()
		l.startPoint = e.Location
	End If
End Sub
Private Sub pictureBox1_Paint(sender As Object, e As PaintEventArgs)
	For Each aLine As var In allLines
		e.Graphics.DrawLine(Pens.Blue, aLine.startPoint, aLine.endPoint)
End Sub
Hope this helps

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
0 Guruprasad.K.Basavaraju 446
1 Sergey Alexandrovich Kryukov 360
2 Shai Vashdi 318
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 9,109
1 OriginalGriff 5,290
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263

Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid