It is more clear in the picture I attached. The listbox in the picture works like a auto-completion and shows suggestions to the user while he is typing. the problem is that the bottom of this list box goes under other controls so you cannot see the Down arrow for the vertical scroll bar of this list box. How can I keep it on top of other controls?
4 Answers
The ListBox has the wrong Parent. You don't want the splitter panel as the parent, that's going to clip it. You can't easily give it the right parent with the designer. Use View + (Other Windows) + Document Outline. Drag the ListBox out of the splitter panel to the form.

- 922,412
- 146
- 1,693
- 2,536
I'm making a guess here since your picture isn't showing up, but you can use something like ListBox.BringToFront()
or ListBox.SetChildIndex()
? This is kind of similar question to this one:
Bring Winforms control to front
I guess it won't help you much if you don't have direct access to the listbox in question though..
I would imagine however you are adding your ListBox
control to the form is not quite right. I am guessing you are adding it within the place where it is displayed and as such, the control that overlaps it is inside some other part of a container. If you want to display a control over all other controls, then that control is going to need to be over the entire container area. So instead of it being some child control of your "Karyotype Entry" container, it should be a child of the parent container of all three form sections.

- 8,405
- 6
- 33
- 55
You can place the ListBox in a different form and invoke/show the form whenever you need the completion list. This will save you having to worry about the ListBox being topmost or not.
The catch with this method is that you'll have to code your AutoComplete form so that it does not steal focus from the main form.
Here's code to help you just in case you're wondering how to make the form show without activation (stealing focus).
private const int SW_SHOWNOACTIVATE = 4;
private const int HWND_TOPMOST = -1;
private const uint SWP_NOACTIVATE = 0x0010;
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
static extern bool SetWindowPos(
int hWnd, // window handle
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void ShowInactiveTopmost(Form frm)
{
ShowWindow(frm.Handle, SW_SHOWNOACTIVATE);
SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST,
frm.Left, frm.Top, frm.Width, frm.Height,
SWP_NOACTIVATE);
}
You could also try overriding the ShowWithoutActivation
property.
protected override bool ShowWithoutActivation
{
get { return true; }
}
NB: Both code snippets come from this question: Show a Form without stealing focus?.

- 1
- 1

- 12,339
- 9
- 70
- 108