busarider29 busarider29 - 1 year ago 113
Vb.net Question

Disable the Close button without hiding the Controlbox

I have an application where I do not want the user to be able to close the form. Okay, easy enough. Just set

ControlBox = false
for the form.

However, I would like to keep the application icon in the upper left corner of the form. Minor I know, but details mean something to me.

Setting the
Controlbox = false
also makes the application's icon go away in the upper left corner of the form. Is there a way around this??

Answer Source

Here is the code I used.

My VB.Net version of it.

Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overrides ReadOnly Property CreateParams() As Windows.Forms.CreateParams
        Dim mdiCp As Windows.Forms.CreateParams = MyBase.CreateParams
        mdiCp.ClassStyle = mdiCp.ClassStyle Or CP_NOCLOSE_BUTTON
        Return mdiCp
    End Get
End Property
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download