开发者

Generic method to get a control name when moused over?

I am writing an application that I am working 开发者_如何学Pythonon a skinning feature to it. What I want to do is allow a user to create an XML document that my code will parse through and set properties of the controls on a form. This is the easy part. Where I am stuck is giving the user a way to find out the control names/types with minimal coding/documentation effort.

My idea was to have a tool tip that when they moused over a control, it got the name of the control and type to show. Anyone know of a way to do this? I was thinking something like how Spy++ can find control, but I want to get the .NET properties also.

If someone has another idea I'm open ears.

Thanks Much.


Figured it out. The issue was because the mouse location wasn't relative to the client location. Thus the code below will resolve this issue. I put it in a polling thread that I already had going, but it should work with a timer or other event. Didn't work in MouseMove for some reason though. Thanks everyone for the help.

                Point p = this.PointToClient(MousePosition);
                Control x = this.GetChildAtPoint(p);
                if (x != null)
                {
                    MessageBox.Show(x.GetType().ToString() + " - " + x.Name);
                }


You'll need to set up some ToolTip objects (one for each field), looping through all of the controls in your form to obtain the text for each tooltip.

http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.aspx


Are you willing to register for each controls mouse over event? If so, the sender would be the type, etc...maybe I'm missing something here? Furthermore you can get the control out of the visual tree in WPF/SL, why not port over to WPF?


You could recursively install a OnMouseOver eventhandler. Then if an OnMouseOver event occures the control is in the sender argument of the event handler.


Why wouldn't this work? I'm putting it in the base form, don't really see what it wouldn't work next to GetChildAtPoint being buggy.

    protected override void OnMouseMove(MouseEventArgs e)
    {
        Control c = this.GetChildAtPoint(e.Location);
        if (c != null)
        {
            MessageBox.Show(String.Format("Your control name is: {0} and type is {1}.", c.Name, c.GetType().ToString()));
        }
        base.OnMouseMove(e);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜