is it possible to make the title property of the form itself visible or invisible via the use of a checkbox?
I'm rather new to C# so i'm not sure how much of a stupid question this is :P
Thanks for reading.

Mike

Edit:

I'm currently using..
this.Text = string.Empty;

Is it possible to make this work into the checked code?

Dani AI

Generated

Good question, . and already pointed out the main tradeoff: removing the window caption also affects the standard system controls and how users move/close the window. Below are a few alternative approaches (with pros/cons and ready-to-use snippets) you can wire into your checkbox CheckedChanged handler as suggested.

Option A — remove the entire frame (simple)
This hides the whole title bar and border. It’s the easiest route but you lose resize, system buttons and the native drag behavior.

private void hideTitleCheckBox_CheckedChanged(object sender, EventArgs e)
{
    this.FormBorderStyle = hideTitleCheckBox.Checked ? FormBorderStyle.None : FormBorderStyle.Sizable;
}

Option B — switch window styles (more control)
Use the Windows API to toggle the caption style at runtime. This is more flexible (you can remove just the caption bit) but requires calling SetWindowPos after changing styles and care on 64-bit processes.

const int GWL_STYLE = -16;
const int WS_CAPTION = 0x00C00000;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_NOSIZE = 0x0001;
const uint SWP_FRAMECHANGED = 0x0020;

[DllImport("user32.dll", SetLastError=true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError=true)]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

void ToggleCaption(bool show)
{
    int style = GetWindowLong(this.Handle, GWL_STYLE);
    style = show ? style | WS_CAPTION : style & ~WS_CAPTION;
    SetWindowLong(this.Handle, GWL_STYLE, style);
    SetWindowPos(this.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}

Option C — custom title area (recommended for polished UI)
If you go borderless, add your own small top panel that can act as a title bar and include a close button. To let users drag the window, handle MouseDown on that panel:

[DllImport("user32.dll")] static extern bool ReleaseCapture();
[DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
const int WM_NCLBUTTONDOWN = 0xA1;
const int HTCAPTION = 0x2;

private void titlePanel_MouseDown(object sender, MouseEventArgs e)
{
    ReleaseCapture();
    SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}

Practical tips: always provide an alternate close (a button that calls Close()), test behavior on 64-bit Windows (use the proper SetWindowLongPtr pattern if needed), and call SetWindowPos/SWP_FRAMECHANGED after style changes so the OS repaints correctly. These approaches let you toggle the visible title without surprising users — follow ’s event-wiring idea and choose the option that best fits how you want resizing and system controls to behave.

Recommended Answers

All 4 Replies

by checked code, I meant making it work with the .Checked line.
An example would be programmerNameLabel.Visible = hideProgrammerCheckBox.Checked;

Mike

To remove a form's title bar you need to set the Form.Text property to string.Empty and set the Form.ControlBox property to false.
Note: This also means there is no X close button, so make sure you have another way to close the form.

Can this be triggered with a checkboxs .Checked property?

Mike

Attach your checkbox's CheckChanged event to the method below.

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                this.Text = string.Empty;
                this.ControlBox = false;
            }
            else
            {
                this.Text = "Title On";
                this.ControlBox = true;
            }
        }

Kordaff

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.