Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
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
Old Sep 10th, 2005, 7:11 PM   #12
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
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 Class


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

I 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.
brokenhope is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC