c#windows窗体应用程序中的drawline [英] drawline in c# windows forms application

查看:176
本文介绍了c#windows窗体应用程序中的drawline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我想绘制线条而鼠标在c#中移动函数绘制线接受对象点数组

i想要在每次更改时将e.location添加到此数组

我该怎么办?

hi all i want to drawtline while mouse moving the function drawlines in c# accept array of object point
i want to add the e.location to this array at every time the posion changed
how can i do it ?

推荐答案

使用 System.Windows.Forms 中的渲染概念使用 System.Drawing 如下所示:您需要执行所有渲染以响应WM_PAINT窗口消息,这是通过处理事件来完成的系统.Windows.Forms.Control.Paint 或在重写的虚方法中 System.Windows.Forms.Control.OnPaint 。因此,您需要以某种模型的形式将所有图形数据保存在内存中,并在事件内存中全部呈现。要防止闪烁,请使用双缓冲。如果数据被修改并需要立即呈现,则通过调用 System.Windows.Forms.Control.Invalidate 来激发事件。



有关详细信息,请参阅我过去的答案:

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

在面板上捕获绘图 [ ^ ],

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



对于某些相关的高级主题,另请参阅:

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

在C#.net鼠标滚轮中缩放图像 [ ^ ]。



-SA
The rendering concept in System.Windows.Forms used with System.Drawing looks like this: you need to do all the rendering in response to the WM_PAINT windows messages, which is done by handling the event System.Windows.Forms.Control.Paint or in your overridden virtual method System.Windows.Forms.Control.OnPaint. Therefore, you need to keep all your graphics data in memory, in the form of some model, and render it all from memory on events. To prevent flicker, use double buffering. If you data is modified and needs immediate rendering, the event is stimulated by calling System.Windows.Forms.Control.Invalidate.

For more detail, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

For some related advanced topics, see also:
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].

—SA


添加一个mousemove事件和一个保存最后一个点的变量:



这样的事情(不完整,只是为了得到这个想法):

Add a mousemove event and a variable where you save the last point:

something like this (not complete, just to get the idea):
Graphics grphx;
Pen MyPen;
Point OldPoint;
private void OnMouseMove(object sender, MouseEventArgs e)
{
  grphx.DrawLine(MyPen, OldPoint.X, OldPoint,Y, e.X, e.Y);
  OldPoint = new Point(e.X, e.Y);
}


这篇关于c#windows窗体应用程序中的drawline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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