在 C# 中运行时创建的对象中处理鼠标事件
我正在编写 ac# windows 应用程序,作为一项任务,我正在运行时创建 Panel 对象。我有我的自定义面板,其定义为:
class FlowState : Panel
{
:
:
}
我有一个 init 方法来设置大小、位置等。但是,一旦在 Windows 窗体上创建此面板,我想处理鼠标事件,例如 mouseDown 和 mouseUp。如果您在设计时创建了一个面板并使用 GUI 来定义这些事件,您将获得如下方法(对于名为“panel1”的面板):
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
//do stuff
}
如何将代码放入扩展 Panel 来处理鼠标事件的 FlowState 对象中比如这个?
I'm writing a c# windows app, and as one task, I am creating Panel objects at runtime. I have my custom Panel which is defined as:
class FlowState : Panel
{
:
:
}
I have an init method to set size, location, etc. However once this panel is created on the windows form, I want to handle mouse events, such as mouseDown and mouseUp. If you created a panel at design time and used the gui to define these events, you would get methods like the following (for a panel named 'panel1'):
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
//do stuff
}
How do I put code into my FlowState object which extends Panel to handle mouse events such as this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样附加事件...
you can attach the event like this...