English 中文(简体)
如何从该构成部分中点击子
原标题:How to trace from which component a button was clicked
  • 时间:2012-01-14 01:08:17
  •  标签:
  • c#

我在C#中做了一个具有多个组成部分的指南。 每个构成部分有一个纽州。 我要知道,被点击的纽顿中哪一部分来自何处。 我不知道从头开始的构成部分数目,因为如果用户想要的话,允许他们增加更多,因此我可以把这些内容或任何东西引出。 感谢!

问题回答

假设你们的每个“支持者”都 on到纽克州的活动。

在此情况下,根据你(全心全意)已知的控制树结构,使用“电离层”参数。

void button_Clicked(object sender, EventArgs e)
{
    var button = sender as Button;
    var ownerControl = button.Parent as MyControl; // But you may need to walk up more levels if need be... Depends on your UI structure.

    // Do stuff with button and owner control
}

更糟糕的是,你“串通”的“布布尔”活动,这样它就能够有自己的活动:

public event EventHandler ButtonClicked;

protected virtual void OnButtonClicked()
{
    var handler = ButtonClicked;
    if (handler != null)
    {
        handler(this, EventArgs.Empty);
    }
}

void button_Clicked(object sender, EventArgs e)
{
    OnButtonClicked(); // Bubble the event
}

然后,你的主控(所有“伙伴”)将围绕每个生产项目进行ButtonClicked活动,直接从手稿< ender参数中找到该项目。

我建议设立一个事件。 ButtonClicked on each part, 然后将部件作为object sender 在事件的手稿中使用。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签