PureSc0pe Posted May 20, 2004 Posted May 20, 2004 How do you make a message box appear when someone clicks the X to close the form? Quote It's not impossible, it's Inevitable.
Leaders dynamic_sysop Posted May 20, 2004 Leaders Posted May 20, 2004 like this ... Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If MessageBox.Show("do you wish to close", Me.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then e.Cancel = False '/// close the form Else e.Cancel = True '/// keep form open End If End Sub Quote
PureSc0pe Posted May 20, 2004 Author Posted May 20, 2004 like this ... Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If MessageBox.Show("do you wish to close", Me.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then e.Cancel = False '/// close the form Else e.Cancel = True '/// keep form open End If End Sub Is it possible to only make that come up if you click the X and not if I'm using me.close with a button or something...? Quote It's not impossible, it's Inevitable.
PureSc0pe Posted May 21, 2004 Author Posted May 21, 2004 Also, if you have 2 forms open and you click a button in form 2 and it closes form 2, how can you make form1 go to a different tab using the button from form 2? I have a module declaring the forms Public, so I just need to know how to make the tab switch... Quote It's not impossible, it's Inevitable.
JABE Posted May 21, 2004 Posted May 21, 2004 Is it possible to only make that come up if you click the X and not if I'm using me.close with a button or something...? In that case, simply introduce a flag variable that you set to True prior to invoking Close, then evaluate this flag in the Closing event. If it's true, then just exit the sub. Quote
PureSc0pe Posted May 21, 2004 Author Posted May 21, 2004 Can you give me an example? Quote It's not impossible, it's Inevitable.
keitsi Posted May 21, 2004 Posted May 21, 2004 Can you give me an example? You really could think on your own too ;) Private bCloseButtonClicked As Boolean = False Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If bCloseButtonClicked Then Return 'close immediately without asking End If If MsgBox("Shall we quit?", MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Confirmation") = MsgBoxResult.No Then e.Cancel = True End If End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click bCloseButtonClicked = True Me.Close() End Sub Quote BS - Beer Specialist
PureSc0pe Posted May 21, 2004 Author Posted May 21, 2004 Thanks...that worked perfectly! I have one final question though. If you have 2 forms open and you click a button in form 2 to close it and bring form 1 from tabpage4 to tabpage3, how would you do the tab part? Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 21, 2004 Posted May 21, 2004 if not mistaken, should be Tab.Index = Tab.Index - 1 Quote George C.K. Low
PureSc0pe Posted May 21, 2004 Author Posted May 21, 2004 very close, I see TabIndex without the . so I tried this f2.TabIndex = TabIndex - 1 no shown errors, but gives me an unhandled exception error when I run it... Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 21, 2004 Posted May 21, 2004 FormName.TabName.TabIndex = FormName.TabName.TabIndex - 1 Quote George C.K. Low
PureSc0pe Posted May 21, 2004 Author Posted May 21, 2004 f2 = Form1 f2.TabPage4.TabIndex = f2.TabPage3.TabIndex - 1 Error:System.NullReferenceException: Object reference not set to an instance of an object. at WindowsApplication1.Form4.Form4_Closing(Object sender, CancelEventArgs e) in C:\Documents and Settings\Alex\My Documents\Visual Studio Projects\Sc0pe's Program\Form4.vb:line 278 at System.Windows.Forms.Form.OnClosing(CancelEventArgs e) at System.Windows.Forms.Form.CheckCloseDialog() Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 21, 2004 Posted May 21, 2004 f2 = Form1 f2.Tab.TabIndex = f2.Tab.TabIndex - 1 Quote George C.K. Low
PureSc0pe Posted May 21, 2004 Author Posted May 21, 2004 Tab is not a member of WindowsApplication.Form1...Here is the whole thing if that helps... Private Sub Form4_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If bCloseButtonClicked Then Return 'close immediately without asking End If If MessageBox.Show("Click Yes to Quit or No to Return", "Sc0pe's TeamSpeak Login", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then e.Cancel = False f2.Tab.TabIndex = f2.Tab.TabIndex - 1 Else e.Cancel = True End If End Sub Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 22, 2004 Posted May 22, 2004 try this..MyFirstApplication.zip Quote George C.K. Low
PureSc0pe Posted May 22, 2004 Author Posted May 22, 2004 That works if you're doing it from the same form...I'm trying to have it execute onto form1 when I close form4...I tried it on both programs, it doesn't seem to work if you do it through another form... Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 22, 2004 Posted May 22, 2004 chekc this outMyFirstApplication.zip Quote George C.K. Low
PureSc0pe Posted May 22, 2004 Author Posted May 22, 2004 (edited) When I put my coding into your layout it works...but it doesn't in mine! :confused: There must be something else I have in it that's messing it up :-\ Take a look if you can :( Form4_Closing is where the tab change coding is and it changes the tabs in form1. Edited May 22, 2004 by PureSc0pe Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 22, 2004 Posted May 22, 2004 Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged If TabControl1.SelectedIndex = 3 And ini2.ReadString("Enable TS Password", "Enable") = 1 And ini2.ReadString("Temporarily Enable TS Password", "Enable") = 0 Then Dim frm As New Form4 frm.parentForm = Me frm.ShowDialog(Me) frm.Dispose() Else Exit Sub End If End Sub Quote George C.K. Low
PureSc0pe Posted May 22, 2004 Author Posted May 22, 2004 As usual, you fix my problems! :D Thanks for all your help. :) Quote It's not impossible, it's Inevitable.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.