Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to make User Control always on top ?

Posted on 2013-06-05
3
Medium Priority
?
451 Views
Last Modified: 2013-06-06
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!
0
Comment
Question by:TaibaDXB
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 39224699
The UserControl will be clipped by its Container.  BringToFront() only affects its z-order within the container so it's of no help here.  The canned solution is to set the AutoSize() property of the Panel/GroupBox to True so that it automatically expands to accommodate the increased size of your UserControl.  *The default AutoSizeMode() is GrowOnly so you may need to change that to GrowAndShrink if you want the container to shrink back if you decrease the size of your UserControl.  If this messes up the sizing you may need to simply manually increase the size of the container at the same time that you increase the size of your UserControl.,
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39224702
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

0
 

Author Closing Comment

by:TaibaDXB
ID: 39224784
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 :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question