Home All Groups Group Topic Archive Search About

Passing Values between forms

Author
1 Jun 2010 2:09 AM
Robbie
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

Author
1 Jun 2010 2:36 AM
Tom Shelton
Robbie has brought this to us :
> 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

There are a number of ways to accomplish this...  A form is just a
class.  You can expose custom properites, methods, and events to
clients of this form just as you would any other class.

--
Tom Shelton
Author
1 Jun 2010 3:57 AM
Mr. Arnold
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.
Author
1 Jun 2010 5:04 AM
Robbie
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.
>
Author
1 Jun 2010 2:41 PM
Jason Keats
Robbie wrote:
>
> Now How do I get this back to the calling Form (generically) without making
> a reference to the specific form name ?
>

You need to find an example that includes the statements/terms:

"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.
Author
1 Jun 2010 8:22 PM
Harry Strybos
Show quote Hide quote
"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
Author
3 Jun 2010 2:27 AM
Robbie
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
>
>
>
>
>