请使用vb.net如何在picturebox上绘制点 [英] pls, pls , how to draw point on picturebox using vb.net

查看:625
本文介绍了请使用vb.net如何在picturebox上绘制点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请,如何使用vb.net在小盒子上绘制点,你可以认为,

pls, pls , how to draw point on picturebox using vb.net with small example as you can , thinks

推荐答案

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
		allLines.Add(l)
		Me.pictureBox1.Invalidate()
	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)
	Next
End Sub





希望这有帮助



Hope this helps


这是一个双坏主意。首先,你真的需要画一点吗?我对此表示怀疑。通常,您需要绘制许多点,因此逐点绘制任何点都非常慢。如果需要,只需要在位图上进行,使用:

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx [ ^ ]。



WPF也有类似的方法,你可能不会在这里使用。



另一个很大的误解是使用 PictureBox 。除了静态图像之外,您永远不需要将此控件用于任何其他操作。原则上你可以,但它完全是多余的,根本没有帮助你,只会浪费你的开发时间和运行时资源。您需要在位图或屏幕上渲染一些图像。 PictureBox 只是一个中间人,为了简化家务,但仅限于最简单的情况。如果你需要在屏幕上绘制任何东西,我会解释做什么,这总是意味着在一些控制中。画在这个控制中,没有其他地方!请看我过去的答案:

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ],

在图片框中附加图片 [ ^ ]。



欲了解更多详情,请参阅:

mdi子表单之间的绘制线 [ ^ ],

捕捉面板上的图纸 [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

如何加速我的vb.net应用程序? [ ^ ]。



正如我所说,如果你真的需要逐点绘制一些点,您仍然应该更好地绘制位图(位图,而不是 PictureBox !),然后使用 System.Drawing.Graphics.DrawImage 。请注意,在这种情况下,您不应该使用双缓冲,至少是您绘制此位图的情况。



-SA
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:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

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 vb.net 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.

—SA


你好!



在表格上放一个PictureBox

点击并按住鼠标左键进行绘制点击鼠标右键单击清除!

复制下面的代码和运行!!!





进口系统.Drawing.Bitmap



Public Class Form1



Dim bmp As Bitmap



Private Sub Form1_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load

bmp =新位图(PictureBox1.Width,PictureBox1.Height)

End Sub



Private Sub Clear(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs)处理PictureBox1.MouseClick

如果e.Button = Windows.Forms.MouseButtons.Right那么

bmp = New System.Dr awing.Bitmap(PictureBox1.Width,PictureBox1.Height)

Me.PictureBox1.Image = bmp

结束如果

End Sub





Private Sub DrawPoint(ByVal sender As Object,ByVal e As System.Windows.Forms.MouseEventArgs)处理PictureBox1.MouseMove

如果e.Button = Windows.Forms.MouseButtons.Left那么

bmp.SetPixel(eX,eY,Color.Red)

Me.PictureBox1.Image = bmp

结束如果



End Sub

End Class
hello!

Drop A PictureBox on Form
Click and Hold left mouse key to draw points an Right mouse click to Clear!
Copy bellow Code and RUN!!!


Imports System.Drawing.Bitmap

Public Class Form1

Dim bmp As Bitmap

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
End Sub

Private Sub Clear(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
If e.Button = Windows.Forms.MouseButtons.Right Then
bmp = New System.Drawing.Bitmap(PictureBox1.Width, PictureBox1.Height)
Me.PictureBox1.Image = bmp
End If
End Sub


Private Sub DrawPoint(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
bmp.SetPixel(e.X, e.Y, Color.Red)
Me.PictureBox1.Image = bmp
End If

End Sub
End Class


这篇关于请使用vb.net如何在picturebox上绘制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆