计时器绘制事件会自动禁用计时器刻度事件 [英] Timer tick event is automatically disabled by Picturebox paint event
问题描述
大家好,
我正在使用计时器记录我在图片框中执行的点击位置达到定时器计时的指定时间。作为下一步,我添加了PictureBox绘制事件,以显示我在pictureBox中点击的小圆圈。它工作得很好但计时器滴答以某种方式变得禁用。接下来我注意到如果我从FORM
Hi Everyone,
I am using a timer to record the location of clicks I perform in a picturebox for a specified amount of time that is timed by the timer. As a next step I added PictureBox paint event to show small circles where I hit in the pictureBox. It works perfectly but timer ticks somehow becomes disabled. Next I noticed that if I comment out the following line from the FORM
InitializeComponent()
函数中注释掉以下行,则计时器开始工作:
function, timer starts working:
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
因此我可以一次使用其中一个,但不能同时使用这两个功能。请帮我解决这个问题。
Hence I can use one of them at a time but unable to use both functionalities at the same time. Please help me resolve this issue.
推荐答案
Dave Kreskowiak是对的,请看他对这个问题的评论。没有取消或禁用任何内容。
不仅处理绘制
PictureBox的事件
毫无意义,使用PictureBox
来渲染图形根本没有任何意义(尽管可能)。这只是一个控件,旨在以简化的方式显示一些静态图像,这是为方便起见而创建的图像的包装器。它的功能完全是多余的。您可以在自己的自定义控件或许多其他控件上渲染图形,例如面板
。
请参阅我的过去的答案解释了几乎所有内容:
附加一个图片框内的图片 [ ^ ],
画一个C#中的矩形 [ ^ ],
如何从旧图纸中清除面板 [ ^ ]。
有关System.Windows.Forms $中图形渲染的说明c $ c>使用
System.Drawing
,请查看我过去的答案:
什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],
在面板上捕获绘图 [ ^ ],
mdi子表单之间的绘制线 [ ^ ],
如何加快我的vb.net应用程序? [ ^ ],
用C#.net鼠标滚轮缩放图像 [ ^ ]。
-SA
Dave Kreskowiak is right, please see his comment to the question. Nothing is cancelled or disabled.
Not only handlingPaint
event of thePictureBox
makes no sense, usingPictureBox
for rendering graphics makes no sense at all (even though it is possible). This is just a control designed to show some static image in a simplified way, a wrapper of an image created just for convenience. It's functionality is totally redundant. You can render graphics on your own custom control or many other controls, such asPanel
.
Please see my past answers which explain pretty much everything:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].
For explanation of graphics rendering inSystem.Windows.Forms
usingSystem.Drawing
, 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[^],
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^].
—SA
这篇关于计时器绘制事件会自动禁用计时器刻度事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!