How Do I Put a Control On Top of Everything Else?

  • Thread starter Thread starter eBob.com
  • Start date Start date
E

eBob.com

I need to put a ListBox on top of everything else. SetTopLevel would seem
like the Method I need, but that results in a syntax error ("Protected").
BringToFront looked promising but seems to do nothing - certainly not what I
want.

How do I get my ListBox on top of everything else?

Thanks, Bob
 
Bob,

What kind of textbox, I have the idea that you are not talking about a
winforms listbox.

By the way this kind of operations are protected on the Web and annoying in
Winforms for the same reasons.

Cor
 
You will need to use .SendToBack on the controls that the listbox needs to
be in front of. .BringToFront does not give the control any priorority over
other controls that are also at the front.
 
Hi Cor,

I am talking about a winforms ListBox.

James Hahn's reply has solved the problem.

Thanks, Bob
 
Hi James,

Thanks for your reply. It has solved my problem. (Although I have learned
that in my case BringToFront works for me if I use it in the right place.)

For the benefit of anyone who might have the same problem and come across
this thread I will point out that, in my experience, you have to do the
..SendToBack AFTER you do the .Controls.Add(). So in my code ...

Form1.Controls.Add(VarList)
Form1.rec.SendToBack()

where VarList is the ListBox and rec is the thing that was interfering with
the display of VarList.

THEN ... I got to thinking about how inaptly the BringToFront method is
named - I mean what does "bring to front" mean when the instance does not
end up in front. AND THEN I recalled that when I tried BringToFront it was
BEFORE the .Controls.Add. SO ... I thought ... well, why not do a little
experiment in which I do the BringToFront AFTER the .Controls.Add. And, in
my situation, that works too. I.E. the following code, using BringToFront,
worked as well as the code shown above.

Form1.Controls.Add(VarList)
'Form1.rec.SendToBack() ' note that this is a comment here
VarList.BringToFront()

So, while I am able to use, or can get away with using, BringToFront, I
would not have solved my problem and would not have learned that WHERE you
do the SendToBack/BringToFront is critical without your help.

Thanks, Bob
 
Back
Top