Solved

How to make User Control always on top ?

Posted on 2013-06-05
3
405 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

6 Experts available now in Live!

Get 1:1 Help Now