I have an Infragistics Tab Control that is showing two tabs. There is a ListBox on each tab. I need to be able to Drag From one list box, to the tab, have the tab activate and switch pages, and then complete the operation with a drop.
I can capture the mouse enter of the tab control, but how do I determine which tab it is over? The mouse events give me the x and y, but I don't see a way to do a hit test to find out which tab should be displayed.
Any advice would be appreciated.
Greg
Hi Greg,
You can do this with UIElements. What you do is use tabControl.UIElement.ElementFromPoint. This will give you the element at that point. Then you call GetContext on the element and pass in a type of UltraTab and see if it returns a tab.
There are lots of KB articles on this technique: Knowledge Base Results - ElementFromPoint
One thing to watch out for - if you are using a Mouse event, then the X and Y coords are in control coords, so it's okay. If you use a DragDrop event, the coords will be in screen coords, so that won't work. You will need to call PointToClient on the control to convert the point to client coords.
Thanks, got this working. Here is the test code in case anyone else needs to do this. private void TabControl_Treeview1_DragOver(object sender, DragEventArgs e){e.Effect = DragDropEffects.All;UltraTabControl tabControl = sender as UltraTabControl;Point point = new Point(e.X, e.Y);Point pointToClient = tabControl.PointToClient(point);UIElement uIElement = tabControl.UIElement.ElementFromPoint(pointToClient);if (uIElement != null){UltraTab tab = uIElement.GetContext(typeof(UltraTab)) as UltraTab;if (tab != null){tab.TabControl.SelectedTab = tab; }else{Debug.WriteLine("Null");}}else{//Debug.WriteLine("Null");}}
Thanks, got this working. Here is the test code in case anyone else needs to do this.
{
UltraTabControl tabControl = sender as UltraTabControl;
Point pointToClient = tabControl.PointToClient(point);
UltraTab tab = uIElement.GetContext(typeof(UltraTab)) as UltraTab;
tab.TabControl.SelectedTab = tab;
}
else
//Debug.WriteLine("Null");
There is also a TabFromPoint helper method on the UltraTabControl which could be used.