Synchronized forms, or Companion Forms 
Author Message
 Synchronized forms, or Companion Forms

I'll admit upfront that I'm a newbee to VB.NET.  So.

I want to create a user interface that allows for a "Menu Form" (frmMenu) to
always exist.  This form launches other forms.

For example:

frmMenu has 3 buttons, btnDoit, btnLaunchForm1, and btnLaunchForm2.  So
frmMenu launches frmForm1, then frmForm2.  frmForm1, and frmForm2 each have
1 textbox on them.

I want to be able to click btnDoIt on frmMenu and have that display letters
in frmForm2 when it was the last active form and numbers in frmForm1 when it
was the last active form.

I tried creating a public variable for frmMenu so that I could have an
addhandler in each forms activate events, but I only seem to be able to
addhandlers to local classes.

Can I create a collection of disparate forms?  It looks like collections
need to be typed exactly too.

Any help appreciated, Thanks in advance

Ben Hunsberger



Tue, 26 Apr 2005 21:46:22 GMT  
 Synchronized forms, or Companion Forms
Create a seperate form and place the buttons on it.Once the button is placed
on this form, double click each and run code under them to load the
appropriate form.


Quote:
> I'll admit upfront that I'm a newbee to VB.NET.  So.

> I want to create a user interface that allows for a "Menu Form" (frmMenu)
to
> always exist.  This form launches other forms.

> For example:

> frmMenu has 3 buttons, btnDoit, btnLaunchForm1, and btnLaunchForm2.  So
> frmMenu launches frmForm1, then frmForm2.  frmForm1, and frmForm2 each
have
> 1 textbox on them.

> I want to be able to click btnDoIt on frmMenu and have that display
letters
> in frmForm2 when it was the last active form and numbers in frmForm1 when
it
> was the last active form.

> I tried creating a public variable for frmMenu so that I could have an
> addhandler in each forms activate events, but I only seem to be able to
> addhandlers to local classes.

> Can I create a collection of disparate forms?  It looks like collections
> need to be typed exactly too.

> Any help appreciated, Thanks in advance

> Ben Hunsberger



Tue, 26 Apr 2005 22:55:22 GMT  
 Synchronized forms, or Companion Forms
Thanks, but I know that.  I guess I wasn't clear.  Loading the forms isn't
the issue.
The issues is having frmMenu smart enough to know that frmForm1 was just
active so that when btnDoIt is clicked it behaves differently than when
frmForm2 was last active, and it modifies data on the correct form.  In
otherwords I want btnDoIt on frmMenu to perform a different sub on frmForm1
than onf frmForm2, and know the difference.



Quote:
> Create a seperate form and place the buttons on it.Once the button is
placed
> on this form, double click each and run code under them to load the
> appropriate form.



> > I'll admit upfront that I'm a newbee to VB.NET.  So.

> > I want to create a user interface that allows for a "Menu Form"
(frmMenu)
> to
> > always exist.  This form launches other forms.

> > For example:

> > frmMenu has 3 buttons, btnDoit, btnLaunchForm1, and btnLaunchForm2.  So
> > frmMenu launches frmForm1, then frmForm2.  frmForm1, and frmForm2 each
> have
> > 1 textbox on them.

> > I want to be able to click btnDoIt on frmMenu and have that display
> letters
> > in frmForm2 when it was the last active form and numbers in frmForm1
when
> it
> > was the last active form.

> > I tried creating a public variable for frmMenu so that I could have an
> > addhandler in each forms activate events, but I only seem to be able to
> > addhandlers to local classes.

> > Can I create a collection of disparate forms?  It looks like collections
> > need to be typed exactly too.

> > Any help appreciated, Thanks in advance

> > Ben Hunsberger



Wed, 27 Apr 2005 00:56:00 GMT  
 Synchronized forms, or Companion Forms
I've solved my own problem.  The key was to define a public event in the
main form, then have each form replace themselves as the handler of that
event.

main form: 3 buttions, btnDoit, btnForm1, and btnForm2

     btnDoit - when you click this it changes textbox1 in form1, or form2
which ever

                  was last active

    btnform1 - launches form1

    btnform2 - launches form2

Public Class frmMain

    Inherits System.Windows.Forms.Form

    Public Event DoIt()

    Private _Doit As DoItEventHandler

    Property DoItHanlder() As DoItEventHandler

        Get

            Return _Doit

        End Get

        Set(ByVal Value As DoItEventHandler)

            If Not (_Doit Is Nothing) Then

                RemoveHandler DoIt, _Doit

            End If

            _Doit = Value

            AddHandler DoIt, _Doit

        End Set

    End Property

    Public Sub btnDoIt_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDoIt.Click

        If _Doit Is Nothing Then

            MsgBox("Main Menu")

        End If

        RaiseEvent DoIt()

    End Sub

    Private Sub btnForm1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnForm1.Click

        Dim frmForm1 As New Form1()

        frmForm1.Show()

    End Sub

    Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnForm2.Click

        Dim frmForm2 As New Form2()

        frmForm2.Show()

    End Sub

End Class

Form2

Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub frmForm1_doit()

        Static i As Integer = 0

        i += 1

        TextBox1.Text = "Did it " & i.ToString & ", times"

    End Sub

    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated

        InitHandlers()

    End Sub

    Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed

        frmMainMenu.DoItHanlder = Nothing

    End Sub

    Private Sub InitHandlers()

        frmMainMenu.DoItHanlder = AddressOf frmForm1_doit

    End Sub

End Class

Form2:

Public Class Form2

    Inherits System.Windows.Forms.Form

    Private Sub frmForm2_doit()

        Static i As Integer = Asc("A") - 1

        i += 1

        If i > Asc("Z") Then

            i = Asc("A")

        End If

        TextBox1.Text = "Form2, Did it " & Chr(i) & ", times"

    End Sub

    Private Sub Form2_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated

        InitHandlers()

    End Sub

    Private Sub Form2_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed

        frmMainMenu.DoItHanlder = Nothing

    End Sub

    Private Sub InitHandlers()

        frmMainMenu.DoItHanlder = AddressOf frmForm2_doit

    End Sub

End Class


Quote:
> I'll admit upfront that I'm a newbee to VB.NET.  So.

> I want to create a user interface that allows for a "Menu Form" (frmMenu)
to
> always exist.  This form launches other forms.

> For example:

> frmMenu has 3 buttons, btnDoit, btnLaunchForm1, and btnLaunchForm2.  So
> frmMenu launches frmForm1, then frmForm2.  frmForm1, and frmForm2 each
have
> 1 textbox on them.

> I want to be able to click btnDoIt on frmMenu and have that display
letters
> in frmForm2 when it was the last active form and numbers in frmForm1 when
it
> was the last active form.

> I tried creating a public variable for frmMenu so that I could have an
> addhandler in each forms activate events, but I only seem to be able to
> addhandlers to local classes.

> Can I create a collection of disparate forms?  It looks like collections
> need to be typed exactly too.

> Any help appreciated, Thanks in advance

> Ben Hunsberger



Wed, 27 Apr 2005 04:18:59 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Synchronizing a pop-up form

2. Synchronize listbox-rowsource with form.recordset

3. Need Help Debugging for Synchronized Forms

4. 1 to 1 relationships and form synchronizing

5. synchronizing forms

6. Synchronizing Two Forms using Code with RecordSource set at runtime

7. Synchronize two forms

8. Synchronized db record on several forms

9. Help!!! Synchronizing Forms in Access

10. Help!!! Synchronizing 2 forms in Access

11. Synchronizing a MDIChild form

12. Synchronize mshflexgrid with recset on a 2nd form

 

 
Powered by phpBB® Forum Software