VB Form: Controlbox = False

M

Miro

I can use the property of the Form to remove the "x" from the top of the
form.

Is there a way in VB to leave the X there but program something so you
cannot close the form?

Or like an ONCLOSE event that you can just put "cancel" ?

If i remember correctly...back in vb 1.0 days or so there was a canclose on
the form.

Form1.canclose = False or something like that.

Im looking thru msdn and all i found so far is the Controlbox Y/N
 
G

gene kelley

I can use the property of the Form to remove the "x" from the top of the
form.

Is there a way in VB to leave the X there but program something so you
cannot close the form?

Or like an ONCLOSE event that you can just put "cancel" ?

If i remember correctly...back in vb 1.0 days or so there was a canclose on
the form.

Form1.canclose = False or something like that.

Im looking thru msdn and all i found so far is the Controlbox Y/N

I think without exception, a user would fully expect the "X" button to
close the form, otherwise, consider it a bug.

What is the logic of a non-functioning "X" button?

Gene
 
G

gene kelley

in the form closing event just type, e.cancel()

e.Cancel () by itself would prohibit the form from closing under any
circumstance - would it not?

Gene
 
H

Herfried K. Wagner [MVP]

Miro said:
I can use the property of the Form to remove the "x" from the top of the
form.

Is there a way in VB to leave the X there but program something so you
cannot close the form?

Or like an ONCLOSE event that you can just put "cancel" ?

If i remember correctly...back in vb 1.0 days or so there was a canclose
on the form.

Form1.canclose = False or something like that.


Check out the form's '*Closing*' (and '*Closed*') events. Inside the event
handler, set 'e.Cancel' to 'True'
 
C

Cor Ligthert [MVP]

Miro,

In addition to Gene, without a message box telling that it is not closing
and telling the reason why, this is considered as a bug in your program.

Cor
 
G

Guest

Add this to your Form's Code and you can do whatever you want then the user
clicks the "X":


<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Protected Overrides Sub WndProc(ByRef m As Message)
Dim SC_Close As Integer = &HF060
Dim WM_SysCommand As Integer = &H112
Select Case (m.Msg)
' The WM_ACTIVATEAPP message occurs when the application
' becomes the active application or becomes inactive.
Case &H112 'WM_SYSCOMMAND
Select Case m.WParam.ToInt32
Case &HF060 'SC_Close 'User clicked on "X"
'DO WHATEVER YOU WANT HERE
Exit Sub
End Select
End Select
MyBase.WndProc(m)
End Sub
 
M

Miro

Thank you,

I just couldnt figure out where vb.net is hiding all these events.

You are correct, if there is a "X" box a user would expect it to close. I
agree,

I am trying to play with events and disable and enable things to find out
where "everything is" in vb.net

I just found out now how to access all the events on a form. I could never
find them.

I kept pulling up my "form" in my "CLASS NAME" drop down and looked for the
events in the "METHODS" drop down there.
I just now found the Base Class Events ... so i can now see all the events
for the form.
- I couldnt figure out how to access all the other events for the form.

But going back to the original question, I was thinking of a form where the
"X" is showing, but i only allow someone to close
it if an event or something else isnt partially being worked on - that
cannot be stopped 1/2 way thru.

Thank you again,

My basic questions - as basic as they seem, this one turned on a light with
actually being able to find how to access all the events.

Im slowely teaching myself vb.net and having a hard time adjusting to some
things. Im use to using a pure "coder" where everything is written in text.

Miro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top