Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
125
Problem with ContextMenuStrip in combination with UltraTextEditor
posted

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

 

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    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

Children