I have a connected a standard ContextMenuStrip to different controls. It works well except with the UltraTextEditor control. If I click in the UltraTextEdit control, the SourceControl obejct is empty.
If I rightclick on the UltraTextEdit control without clicking first (left) on the control, it is working like expected.
Thanks for help!
Cheers,
Herbert
Private
Sub ContextMenuStrip1_Opened(sender As Object, e As System.EventArgs) Handles
ContextMenuStrip1.Opened
mySourceControlName = ContextMenuStrip1.SourceControl.Name
'is empty if I click first in the cotnrol getting focus
ContextMenuStrip1.Items(0).Text = mySourceControlName
End
Hi,
The control is not empty, it's just that it has no name. When an UltraTextEditor control enters edit mode, it creates a child control and positions it over itself. This child control is a derived TextBox control which allows to the user to edit.
So what you could do walk up the parent chain until you get a control that has a name.
Private Sub contextMenuStrip1_Opened(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles contextMenuStrip1.Opened Dim contextMenuStrip As ContextMenuStrip = CType(sender, ContextMenuStrip) Dim sourceControl As Control = contextMenuStrip.SourceControl While String.IsNullOrEmpty(sourceControl.Name) sourceControl = sourceControl.Parent End While Debug.WriteLine(sourceControl.Name) End Sub
Excellent! Works very well! Thanks you!