Solved

How to make User Control always on top ?

Posted on 2013-06-05
3
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

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 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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