WindowsForms中的StrokeCollected,StrokeErased,StrokeErasing [英] StrokeCollected , StrokeErased , StrokeErasing in windowsForms

查看:149
本文介绍了WindowsForms中的StrokeCollected,StrokeErased,StrokeErasing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF中,我看到了一些事件,例如StrokeCollected,StrokeErased,StrokeErasing,
我希望它们在Windows窗体中用于面板或pcitureBox之类的控件,

是否可以创建一个处理程序来调用该事件?

预先谢谢您.

in WPF i saw some events like StrokeCollected , StrokeErased ,StrokeErasing ,
i want them in my Windows form for my controls like panel or pcitureBox,

is that possible to create a handler to invoke that event ?

thank you in advance

推荐答案

事件处理程序不用于调用事件,而是用于在事件已被调用时处理事件.所以,不,这不可能.

但是,您永远不需要调用任何已创建的类中声明的事件-这已经在该类中完成(当然,它是正确实现的).而且,您永远无法做到,除非这是您的类,并且带有可以修改的源代码.即使您尝试在派生类中执行触发事件,也无法访问它.与委托实例相比,这是事件实例最重要的限制之一.

您可以对已经存在的某个类中声明的事件进行的所有操作就是将事件处理程序添加到其调用列表中,或者删除以前添加的处理程序.当然,您可以对问题中提到的事件进行处理. 这就是您真正需要的.



顺便说一句,PictureBox类被高度滥用,它只能在非常简单的情况下有效使用,并且绝对不需要在WPF中使用它.在大多数情况下,即使在表单中也不应使用它.如果您需要有关WPF图形的帮助,请说明您的最终目标.

您应该更好地将WPF和Forms混合在一个UI中.原则上这是可能的,但不是有益的,非常有限且有问题.它主要用于重用旧版Forms代码.

-SA
An event handler is not used to invoke the event, it is used to handle the event when it is already invoked. So, no, this is not possible.

However, you never need to invoke any event declared in any already created class — this is already done in this class (it it is implemented correctly, of course). Moreover, you never can do it, unless this is your class with the source code which you can modify. You cannot access firing event even if you try to do it in a derived class. This is one of the most important limitation of event instances compared to delegate instances.

All you can do with event declared in some already existing class is to add an event handler to its invocation list or remove previously added handler. Of course you can do it with the events you mentioned in the question. This is all you really need.



By the way, the class PictureBox is highly misused, it can be used effectively only in very simple situations and there is absolutely no need to use it in WPF. In most situations, it should not be used even in Forms. Explain your ultimate goal if you need to get some help on WPF graphics.

You should better through out the idea of mixing WPF and Forms in one UI. This is in principle possible, but not beneficial, very limited and problematic. It''s mostly used for re-using legacy Forms code.

—SA


1.您不通过处理程序调用事件.事件是根据UI中的用户操作(在这种情况下)调用的,并由处理程序进行处理.

2.您也可以拥有这些事件,但是为此,您必须创建自己的图片框.您为什么仍然需要这些事件?如果您可以分享,那么有人可以为您提供解决方案.


您将必须处理Paint事件,并使用Graphics对象在屏幕上绘制事物.利用Mouse事件获取坐标,并使用Paint事件进行绘制.
1. You do not invoke events through handlers. Events are invoked based on user actions in UI (in this case) and handler handles it.

2. You can have those events too but for that, you will have to create your own picture box. Why do you need those events anyways? If you could share that, someone can provide you with a solution.


You will have to handle the Paint event and use the Graphics object to draw the things on screen. Make use of Mouse events to get the coordinates and use Paint event to draw.


这篇关于WindowsForms中的StrokeCollected,StrokeErased,StrokeErasing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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