Results 1 to 7 of 7

Thread: [RESOLVED] [2005]bringing panels to the front

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    263

    Resolved [RESOLVED] [2005]bringing panels to the front

    How do I give focus to a particular panel on a tabpage that has several panels?
    Last edited by Psychlotron; Apr 3rd, 2008 at 01:06 PM.

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: bringing panels to the front

    focus is given when you call the .focus() method of a given control. Usually you want to focus to a control that accepts input, so you would actually call the focus() method on the control that is inside the panel that you want to be focused.

    However focus is not the same thing as Z-Order which is the logical order of controls stacked on the form. To bring a control on top of another (or send it behind) you want to use .BringToFront() and .SendToBack() which are methods available on any control class.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    263

    Re: bringing panels to the front

    That helped, but it still works a little funky. So, in total, I've created some buttons at runtime and added them to a panel named 'pnlDual' which is itself initially on TabPage1 of TabControl1. If pnlDual is the only panel in my TabControl, then everything works fine. At each TabControl1.SelectedIndexChanged I add pnlDual to the selected tabpage's control list.

    But as soon as I add another panel (Panel1) to any TabPage at design time, suddenly I can never see pnlDual at runtime.

    So I tried the pnlDual.BringToFront() procedure and that didn't work. But if I did this:

    Code:
    pnlDual.BringToFront()
    Panel1.SendToBack()
    then it works. Is this just something that I am going to have to live with, or is there a way to make the BringToFront procedure work on its own?

    Thanks!

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005]bringing panels to the front

    are you sure when you added panel1 at design time, you didn't add it to pnlDual (panels can contain other panels), instead of the TabPage itself?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    263

    Re: [2005]bringing panels to the front

    Ahh, so clever. I think you got it. I'm going to work around with it for a while, thank you!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    263

    Re: [2005]bringing panels to the front

    It did work! That little problem of having one panel inside another and not knowing about it was really shaking my confidence in .net. I figured something like "BringToFront()" ought to work like the name said. Of course, it does, so long as it isn't bringing itself to the front, covered by its own "clothing".

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005]bringing panels to the front

    yeah, when dragging around controls in the IDE, you will see the icon change if releasing the mouse at that given moment means the controls container is going to change. Keep that in mind when moving controls around on forms, especially when you have a lot of container controls like it sounds you do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width