I am working on C#.Net application. My application TablePanelLayout is a container, it has contains lot of child controls(Label,TextBox, Button...). On control mouseover i want to know current control name.
A:
Control.GetChildAtPoint Method (Point) and Control.GetChildAtPoint Method (Point, GetChildAtPointSkip) do what you need.
But in your case you may also do the following: for each child in your panel add a listener to the child's mouseover event and in that listener check the sender parameter.
ULysses
2010-07-19 13:28:36
A:
you can do something like this, use jquery to get the function on mouse over.
$('#outer').mouseover(function() { //get the control here });
WingMan20-10
2010-07-19 13:28:54
The question is about WinForms not web applications.
ChrisF
2010-07-19 14:37:16
A:
I had to do something similar to get the name of the control the user clicked on. Your case is mouse over, but the same approach will probably work. I ended up using:
Application.AddMessageFilter(new MyMessageFilter());
at program startup. The basics of MyMessageFilter looks something like this. You'll have to adapt for mouse moves.
class MyMessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message msg)
{
try
{
const int WM_LBUTTONUP = 0x0202;
const int WM_RBUTTONUP = 0x0205;
const int WM_CHAR = 0x0102;
const int WM_SYSCHAR = 0x0106;
const int WM_KEYDOWN = 0x0100;
const int WM_SYSKEYDOWN = 0x0104;
const int WM_KEYUP = 0x0101;
const int WM_SYSKEYUP = 0x0105;
//Debug.WriteLine("MSG " + msg.Msg.ToString("D4") + " 0x" + msg.Msg.ToString("X4"));
switch (msg.Msg)
{
case WM_LBUTTONUP:
case WM_RBUTTONUP:
{
Point screenPos = Cursor.Position;
Form activeForm = Form.ActiveForm;
if (activeForm != null)
{
Point clientPos = activeForm.PointToClient(screenPos);
RecordMouseUp(clientPos.X, clientPos.Y, GetFullControlName(msg.HWnd));
}
}
}
}
}
private string GetFullControlName(IntPtr hwnd)
{
Control control = Control.FromHandle(hwnd);
return control.Name; // May need to iterate up parent controls to get a full path.
}
}
Scott Langham
2010-07-19 14:58:25