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

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
 
C

Cor Ligthert[MVP]

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
 
J

James Hahn

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

eBob.com

Hi Cor,

I am talking about a winforms ListBox.

James Hahn's reply has solved the problem.

Thanks, Bob
 
E

eBob.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top