|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Passing Values between formsHi,
I have a "keyboard" form that I would like to reuse through out my application... Let's say in Form1 I have a text box or property I want to populate... I want to be able to call the "FormKeyboard" which has a textbox that gets populated with the value typed by the user. I then want to transfer this value back to the Calling Form... How may I make "FormKeyboard" generic enough to be useable form any form ? Thanks Robbie has brought this to us :
> Hi, There are a number of ways to accomplish this... A form is just a > > I have a "keyboard" form that I would like to reuse through out my > application... > > Let's say in Form1 I have a text box or property I want to populate... I want > to be able to call the "FormKeyboard" which has a textbox that gets populated > with the value typed by the user. I then want to transfer this value back > to the Calling Form... > > How may I make "FormKeyboard" generic enough to be useable form any form ? > > Thanks class. You can expose custom properites, methods, and events to clients of this form just as you would any other class. -- Tom Shelton Robbie wrote:
> Hi, You use a MVP (Model View Presenter) design pattern to make it generic, > > I have a "keyboard" form that I would like to reuse through out my > application... > > Let's say in Form1 I have a text box or property I want to populate... I > want to be able to call the "FormKeyboard" which has a textbox that gets > populated with the value typed by the user. I then want to transfer this > value back to the Calling Form... > > How may I make "FormKeyboard" generic enough to be useable form any form ? > and you use objects. The object that holds the data properties is passed between classes, a form.vb is just another class. Hi,
Specifically... Public Class KeyboardInputs Private m_KeyboardSend As String Public Property KeyboardSend() As String Get KeyboardSend = m_KeyboardSend End Get Set(ByVal value As String) m_KeyboardSend = value End Set End Property End Class 'This is the code in the Keyboard that sends the typed value to KeyboardInputs.KeyboardSend Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click Dim objKeyboardInputs As New KeyboardInputs objKeyboardInputs.KeyboardSend = txtFormValue.Text MsgBox("objKeyboardInputs.KeyboardSend " & objKeyboardInputs.KeyboardSend) Me.Visible = False End Sub Now How do I get this back to the calling Form (generically) without making a reference to the specific form name ? Show quoteHide quote "Mr. Arnold" <Arn***@Arnold.com> wrote in message news:%23C2qg6TALHA.5476@TK2MSFTNGP06.phx.gbl... > Robbie wrote: >> Hi, >> >> I have a "keyboard" form that I would like to reuse through out my >> application... >> >> Let's say in Form1 I have a text box or property I want to populate... I >> want to be able to call the "FormKeyboard" which has a textbox that gets >> populated with the value typed by the user. I then want to transfer >> this value back to the Calling Form... >> >> How may I make "FormKeyboard" generic enough to be useable form any form >> ? >> > > You use a MVP (Model View Presenter) design pattern to make it generic, > and you use objects. The object that holds the data properties is passed > between classes, a form.vb is just another class. > Robbie wrote:
> You need to find an example that includes the statements/terms:> Now How do I get this back to the calling Form (generically) without making > a reference to the specific form name ? > "Private WithEvents" "Public Event" "RaiseEvent" The first hit in a search using the above provides the following link: http://devcity.net/Articles/25/1/20020316.aspx It's not ideal, but it does illustrate how to call a class/form using WithEvents, how to define events using "Public Event" and how to send information back to the calling class/form by using RaiseEvent.
Show quote
Hide quote
"Robbie" <ro***@yahoo.com> wrote in message Put a public property on your FormKeyboard called eg MyTextValuenews:goydnZMe_sAL8JnRnZ2dnUVZ_qidnZ2d@giganews.com... > Hi, > > I have a "keyboard" form that I would like to reuse through out my > application... > > Let's say in Form1 I have a text box or property I want to populate... I > want to be able to call the "FormKeyboard" which has a textbox that gets > populated with the value typed by the user. I then want to transfer this > value back to the Calling Form... > > How may I make "FormKeyboard" generic enough to be useable form any form ? > > Thanks > Put a constructor on FormKeyboard Public Sub New (sMyTextValue as String) Me.MyTextValue = sMyTextValue 'here you pass whatever value to the form End Sub When calling FormKeyboard do it modally eg Using frm as New FormKeyBoard(Text1.text) With frm .ShowDialog(Me) 'here you can get back the value Text1.Text = .MyTextValue End With End Using Thank you - I will try this out...
Show quoteHide quote "Harry Strybos" <nospam@ffapaysmart.com.au> wrote in message news:OIP86gcALHA.3176@TK2MSFTNGP05.phx.gbl... > "Robbie" <ro***@yahoo.com> wrote in message > news:goydnZMe_sAL8JnRnZ2dnUVZ_qidnZ2d@giganews.com... >> Hi, >> >> I have a "keyboard" form that I would like to reuse through out my >> application... >> >> Let's say in Form1 I have a text box or property I want to populate... I >> want to be able to call the "FormKeyboard" which has a textbox that gets >> populated with the value typed by the user. I then want to transfer >> this value back to the Calling Form... >> >> How may I make "FormKeyboard" generic enough to be useable form any form >> ? >> >> Thanks >> > Put a public property on your FormKeyboard called eg MyTextValue > > Put a constructor on FormKeyboard > > Public Sub New (sMyTextValue as String) > Me.MyTextValue = sMyTextValue 'here you pass whatever value to the form > End Sub > > When calling FormKeyboard do it modally eg > > Using frm as New FormKeyBoard(Text1.text) > With frm > .ShowDialog(Me) > 'here you can get back the value > Text1.Text = .MyTextValue > End With > End Using > > > > >
Add new event manually to a control of mine.
Encryption and Decryption with office 2007 document Convert from network name to ip address How do I copy file from resources to C:\Notes? make a dll Disable a Textbox default context menu Print from console application DataGridView values. How to use Serial Port Component bindingSource.Position = ... doesn't change the current property. |
|||||||||||||||||||||||