tags:

views:

2004

answers:

4

How can I make my window not have a title bar but appear in the task bar with some descriptive text? If you set the Form's .Text property then .net gives it a title bar, which I don't want.

        this.ControlBox = false;
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.ShowInTaskbar = true;
        this.Text = "My title for task bar";

I've found a partial solution, to override CreateParams:

    protected override System.Windows.Forms.CreateParams CreateParams
    {
        get
        {
            System.Windows.Forms.CreateParams cp = base.CreateParams;
            cp.Style &= ~0x00C00000; // WS_CAPTION
            return cp;
        }
    }

However this causes my window to be resized as if they have a title bar, ie it's taller than it should be. Is there any good solution to this?

A: 

Just set the border style to None.

this.FormBorderStyle = FormBorderStyle.None;
amcoder
+4  A: 

One approach to look into might be to set the FormBorderStyle property of your Form to None (instead of FixedDialog).

The drawback to this approach is that you lose the borders of your window as well as the Titlebar. A result of this is that you lose the form repositioning/resizing logic that you normally get "for free" with Windows Forms; you would need to deal with this by implementing your own form move/resize logic in the form's MouseDown and MouseMove event handlers.

I would also be interested to hear about better solutions.

Jon Schneider
+1  A: 

Once you have removed the borders with the FormBorderStyle, as mentioned already, you can make it draggable fairly easily. I describe this at http://www.blackwasp.co.uk/DraggableBorderless.aspx.

BlackWasp
Nice and example, but in the real world, but there are often more considerations with dragging the form, for instance, we don't want to drag if the mouse is over a control or between controls, or want to resize if it's close to borders.
dbkk
Absolutely. You need to capture that also, testing how close you are to the form boundary, changing the mouse pointer, getting the preferred border size from Windows, etc. A bit too much for one example though - perhaps I'll create another.
BlackWasp
+1  A: 

In my case I have a Form with FormBorderStyle = FormBorderStyle.SizableToolWindow and the following CreateParams override did the trick (i.e. I now have a form without caption and without additional margin for the title, but it keeps the title in the task bar):

protected override CreateParams CreateParams {
    var parms = base.CreateParams;
    parms.Style &= ~0x00C00000; //WS_CAPTION
    parms.Style &= 0x00040000; //WS_SIZEBOX
    return parms;
}
Lck