Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2004

Tip: Looking for answers? Try searching our database.

MDI application design

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tod Johnson - 30 Aug 2004 20:31 GMT
Hello,

I have created Application that has MDI interface. Indeed application
works as it should, but I have question related to its design.

Assume my application can change Zoom state of the opened document from
the toolbar (toolbar for all opened document is the same). Which
component of application should change this zoom: the main form where
toolbar situated or this Document through the main form should change Zoom?

I hope it's not complicated to understand :)

Thanks
schneider - 30 Aug 2004 20:56 GMT
> Hello,
>
[quoted text clipped - 9 lines]
>
> Thanks

The MDI form has a reference to the ActiveForm, but I usually have a
property on the MDI form for the active document form, this way it's
type specific.

The Tool bar/Menu can then reference the active document property on the
MDI form to perform functions, like call
MyMDIform.MyActiveTextDocument.Zoom = 50.

Your document (MyActiveTextDocument) will also need to set itself as
active document on the MDI form. This is easy to do in the form activate
event.

Others may have better ideas....

Schneider
Tod Johnson - 31 Aug 2004 06:32 GMT
Schneider,

as I understood you, you suggest to write all logic on the mainform but
what if the types of documents too big than the mainform should contain
many IF/ELSE operators:

OnActivateMdiWindow
{
    if (ActiveMdiWindow is ImageDocument)
    {
    toolbarZoom.Enabled = true;
        toolbarZoom.SelectedIndex = (ImageDocument)ActiveMdiWindow;
    }
    else if (ActiveMdiWindow is OtherDocument)
    {
        toolbarSomeItem.SelectedIndex = ....
    }
}

OnDeactiveMdiWindow
{
    if (ActiveMdiWindow is ImageDocument)
    {
       toolbarZoom.Enabled = false;
    }
}

It will be hard to understand and the main form will contain unnecessary
code. Are there any patterns for such problems?

> The MDI form has a reference to the ActiveForm, but I usually have a
> property on the MDI form for the active document form, this way it's
[quoted text clipped - 11 lines]
>
> Schneider
schneider - 31 Aug 2004 15:57 GMT
> Schneider,
>
[quoted text clipped - 41 lines]
>>
>> Schneider

No, I suggest keep as much of the Document logic out of the MDI form.

I was thinking more like this:

Public Class MyMdiForm
    Inherits System.Windows.Forms.Form

    Private m_ActiveDocumentForm As MyDocumentForm
    Private m_Toolbar As ToolbarForm

    Public Property ActiveDocumentForm() As MyDocumentForm
        Get
            Return m_ActiveDocumentForm
        End Get
        Set(ByVal value As MyDocumentForm)
            m_ActiveDocumentForm = value
        End Set
    End Property

    Public Property ToolBar() As ToolbarForm
        Get
            Return m_Toolbar
        End Get
        Set(ByVal value As ToolbarForm)
            m_Toolbar = Value
        End Set
    End Property

    Private Sub MyMdiForm_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

        'create toolbar
        Dim newToolbar As New ToolbarForm
        newToolbar.MdiParent = Me
        newToolbar.Visible = True
        Me.ToolBar = newToolbar

        'create a new document 1
        Dim newDoc1 As New MyDocumentForm
        newDoc1.Text = "Doc1"
        newDoc1.MdiParent = Me
        newDoc1.Visible = True

        'create a new document 1
        Dim newDoc2 As New MyDocumentForm
        newDoc2.Text = "Doc2"
        newDoc2.MdiParent = Me
        newDoc2.Visible = True

    End Sub
End Class

Public Class MyDocumentForm
    Inherits System.Windows.Forms.Form

    Private m_Zoom As Integer

    Public Property Zoom() As Integer
        Get
            Return m_Zoom
        End Get
        Set(ByVal value As Integer)
            m_Zoom = value

            Me.Label1.Text = m_Zoom.ToString
        End Set
    End Property

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

        Dim mdiform As MyMdiForm = DirectCast(Me.MdiParent, MyMdiForm)

        'set this document as active
        mdiform.ActiveDocumentForm = Me
    End Sub
End Class

Public Class ToolbarForm
    Inherits System.Windows.Forms.Form

    Private Sub btnZoomIn_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnZoomIn.Click

        Dim mdiform As MyMdiForm = DirectCast(Me.MdiParent, MyMdiForm)

        'increase zoom
        mdiform.ActiveDocumentForm.Zoom =
diform.ActiveDocumentForm.Zoom + 10

    End Sub

End Class

Anyone have a better approach?
I'm always looking for better ways...

Thanks,

Schneider
Herfried K. Wagner [MVP] - 30 Aug 2004 21:34 GMT
* Tod Johnson <todjohnson@bcd.com> scripsit:
> I have created Application that has MDI interface. Indeed application
> works as it should, but I have question related to its design.
[quoted text clipped - 4 lines]
> toolbar situated or this Document through the main form should change
> Zoom?

Add a 'Zoom' property to your MDI child and use this code:

\\\
DirectCast(Me.ActiveMdiChild, FooForm).Zoom = 70
///

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/

schneider - 30 Aug 2004 23:09 GMT
> * Tod Johnson <todjohnson@bcd.com> scripsit:
>
[quoted text clipped - 12 lines]
> DirectCast(Me.ActiveMdiChild, FooForm).Zoom = 70
> ///

Except if you have different types of MDI child forms that would be an
issue. Your tool bar could be a form and could be the ActiveMdiChild.

You could check the ActiveMdiChild type prior though...

Schneider
Herfried K. Wagner [MVP] - 30 Aug 2004 23:45 GMT
* schneider <abd@123.com> scripsit:
>>> I have created Application that has MDI interface. Indeed application
>>> works as it should, but I have question related to its design.
[quoted text clipped - 15 lines]
>
> You could check the ActiveMdiChild type prior though...

\\\
If Not Me.ActiveMdiChild Is Nothing Then
   If TypeOf Me.ActiveMdiChild Is FooForm Then
       DirectCast(..., FooForm)...
   ElseIf...
       ...
   ...
   End If
End If
///

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.