Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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

Posted
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...?

It's not impossible, it's Inevitable.
Posted
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...
It's not impossible, it's Inevitable.
Posted

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.

Posted
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

BS - Beer Specialist
Posted
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?
It's not impossible, it's Inevitable.
Posted

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...

It's not impossible, it's Inevitable.
Posted

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()

It's not impossible, it's Inevitable.
Posted

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

It's not impossible, it's Inevitable.
Posted
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...
It's not impossible, it's Inevitable.
Posted (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 by PureSc0pe
It's not impossible, it's Inevitable.
Posted
     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

George C.K. Low

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...