View Single Post
Old Sep 10th, 2005, 6:06 PM   #11
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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 Class

And 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
Dameon is offline   Reply With Quote