Link to home
Start Free TrialLog in
Avatar of TaibaDXB
TaibaDXB

asked on

How to make User Control always on top ?

I have a user control and it has one janus combo box.  While dropping down the combo I increased the Height of the user control to show some other controls below the combo box.
Its working fine, but the problem is : if I place the UC inside any panel or group box the User Control hiding inside the parent control. Its not always on top.

I tried in Designer that right clicking on the controls and Bring to Front
and also by code.( this.BringtoFront())

How can I bring the User control always on top..?
Please help me. Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you truly need a "bring to front" mechanism you can switch the container of the UserControl to the FORM at run-time so that it won't be clipped by the original container.  Use PointToScreen() and PointToClient() to keep the UserControl in the same position when it changes containers:
Public Class UserControl1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim pt As Point = Me.PointToScreen(New Point(0, 0))
        pt = Me.ParentForm.PointToClient(pt)
        Me.ParentForm.Controls.Add(Me)
        Me.Location = pt
        Me.BringToFront()

        Me.Height = Me.Height * 2
    End Sub

End Class

Open in new window

Avatar of TaibaDXB
TaibaDXB

ASKER

AutoSize() property of the GroupBox  messes up the sizing. So I  simply manually increase the size of the container and set the Anchor property correctly. Now its working fine! Thanks :)