![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Something like this
Public Class Form3
Inherits System.Windows.Forms.Form
'Snip
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form4
frm.ShowDialog()
DoWhatYouWantWith(frm.Selection)
End Sub
End Class
Public Class Form4
Inherits System.Windows.Forms.Form
'Snip
Public ReadOnly Property Selection() As Something
Get
Return WhateverTheUserSelected
End Get
End Property
End ClassAnd if all you want to do is select a file to open or a location to save, there's a component for that. Scroll down on the Windows Forms category on the toolbox and look at the <blankity blank>Dialog controls. These actually provide a good example of the pattern above in action. For example, OpenFileDialog has a property name Filename that is set to what the user is selected. You might do something like: If OpenFileDialog1.ShowDialog = DialogResult.OK Then Dim fs As New IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open) 'Do something fs.Close() End If Notice that ShowDialog returns a DialogResult. There's a property called DialogResult on the Button class. So for an OK button, set it to DialogResult.OK so you can easily discern what button the user pressed (For example if they clicked cancel you don't want to do anything when ShowDialog returns)
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#12 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
Alright so I partly understood this, but I dont understand how to send and read the values, or work with the 2nd window... mostly because I didnt understand how dowhatyouwantwith(frm.Selection) would work, because it is only activated when the button on form3 is clicked, so therefore it would be null at all times, unless I misunderstood it.
heres my current code: formMain.vb Public Class formMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub formMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
rtbTextBox.Enabled = False
End Sub
Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click
' Make File New Form Show
Dim formFileNew As formFileNew
formFileNew = New formFileNew
formFileNew.ShowDialog()
rtbTextBox.Enabled = True
rtbTextBox.Text = formFileNew.txtFileName.Text & formFileNew.optCustom.Checked & formFileNew.optHTML.Checked
End Sub
End ClassformFileNew.vb Public Class formFileNew
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.Click
Me.Close()
End Sub
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Me.Close()
End Sub
End ClassI dont think I fully understand how to do it, but I was trying to return the value of optHTML... I wasnt quite sure what it did, but I was just testing... EDIT: Ah alright I got it. I didnt know that using a dialog instead of a window stopped the main windows code until the dialog closed. Thanks for all the help I have it working now. (and I updated my code above) it doesnt check yet how the dialog was closed to see how you want to deal with the values, but right now it works... Last edited by brokenhope; Sep 10th, 2005 at 7:26 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|