MDI application design

  • Thread starter Thread starter Tod Johnson
  • Start date Start date
T

Tod Johnson

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
 
Tod said:
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

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 said:
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?

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

\\\
DirectCast(Me.ActiveMdiChild, FooForm).Zoom = 70
///
 
Herfried said:
Add a 'Zoom' property to your MDI child and use this code:

\\\
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
 
* schneider said:
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...

\\\
If Not Me.ActiveMdiChild Is Nothing Then
If TypeOf Me.ActiveMdiChild Is FooForm Then
DirectCast(..., FooForm)...
ElseIf...
...
...
End If
End If
///
 
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?
 
Tod said:
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?

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
 
Back
Top