Solved

How to make User Control always on top ?

Posted on 2013-06-05
3
413 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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now