tags:

views:

344

answers:

3

Is it any possible to get my listbox to be shown outside of the form's bounds?

One of the solutions is to make the form itself transparent, and add the panel instead of the form for the background.

But is there any other, more delightful way to do that?

UPD: i need to make a custom autocomplete for textbox, to support wildcards. so i want a listbox to be shown below the textbox. my form's size should be about the size of the textbox. so, stretching the form vertically doesn't work in this case.

thx

+3  A: 

Could you use a second form that only contains the listbox? You'd need a little code to move it relative to the main form, but it should work...

Marc Gravell
so, basically, there's no way to fit it all into the one form?
ifesdjeen
No, I think the only way to get a control to be "graphically independent" of the main for is to put it in a owned form, perhaps with a transparent background. I did a bit of playing around with this when I wanted a couple of forms to hav snap-lines to the edges of the screen. I ended up with a transparent form that I place under the windows and draw on them with GDI
Charlie boy
+1  A: 

Not really, no. That runs counter to the fundamental winforms model. You can probably cheat with a lot of manual munging or interop, but that would hardly be worth the cost.

Instead, ask yourself why you're doing this. It looks like you're trying to reimplement a combobox for the sole purpose of adding autocomplete. Perhaps you should simply subclass the combobox control to add your autocomplete functionality to the control that does all the hard stuff for you and already exists.

In the course of my current job, I've seen at least three different home-grown comboboxes that were all broken in various ways, amounting to a lot of work with no real payoff. My favorite was the combobox whose dropdown listbox stole the owning forms focus. It was really funny watching the broken code cause anything that used it to flicker.

Edit:

Modifying the combobox to be a search/filter with wildcards is still possible via inheriting from ComboBox, and still easier than rolling your own combobox, but at that point I'd suggest considering a more appropriate ui paradigm. Comboboxes don't filter their drop-down list (unless you use lousy software as inspiration coughSAP*cough*).

Greg D
well :) it's all clearbut the problem is not to add proper values into the textbox autocomplete.the problem is to make it work with wildcards.... if the text starts with "*", textbox starts seeking with "*"((( that's why i want to create a separate listbox for it...
ifesdjeen
+1  A: 

Actually, its possible. Here's the way:

public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
    private System.Windows.Forms.Control _content;
    private System.Windows.Forms.ToolStripControlHost _host;

    public PopupWindow(System.Windows.Forms.Control content)
    {
        //Basic setup...
        this.AutoSize = false;
        this.DoubleBuffered = true;
        this.ResizeRedraw = true;

        this._content = content;
        this._host = new System.Windows.Forms.ToolStripControlHost(content);

        //Positioning and Sizing
        this.MinimumSize = content.MinimumSize;
        this.MaximumSize = content.Size;
        this.Size = content.Size;
        content.Location = Point.Empty;

        //Add the host to the list
        this.Items.Add(this._host);
    }
}


popup = new PopupWindow(listbox1);
ifesdjeen