473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

MDI and Interface question

I am doing the following with my MDI app..

Please advise if I am going about this wrong or there is a better way.

I thought, well, the main form needs to be able to ask the child form if it
can save

So I made the following interfaces.

'all child forms implement ICanSave and return true or false;main can thus
always call CanSave to see if it can save
Public Interface ICanSave
ReadOnly Property CanSave() As Boolean
End Interface

'if they can save they should then implement ISave which has the
following... So when user clicks Save icon, this Save method 'is called
Public Interface ISave
Function IsDirty() As Boolean
Function Save() As Boolean
Function SaveAs(ByVal FileName As String) As Boolean
End Interface

on main form
Private Sub frmMain_MdiChildActivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MdiChildActivate
Dim Savable As ICanSave
Dim ISaver As ISave
Try
'see if can save
Savable = Me.ActiveMdiChild
If Savable.CanSave Then
ISaver = Me.ActiveMdiChild
mnuFileSave.Enabled = ISaver.IsDirty
End If

mnuFileSaveAs.Enabled = Savable.CanSave
Catch ex As Exception
'don't know so disable them
mnuFileSave.Enabled = False
mnuFileSaveAs.Enabled = False
End Try
End Sub

Is there a better way?

Am I doing something dumb?

Is there another event to check when child form becomes dirty because I
think ChildActivate requires a click.

So how can I know when to enable the Save icon otherwise?

Hope this all makes sense..

Any help appreciated.

Shane
Nov 20 '05 #1
1 1105
"SStory" <Th*******@TAKETHISSPAMBUSTEROUT.Softhome.net> schrieb
I am doing the following with my MDI app..

Please advise if I am going about this wrong or there is a better
way.

I thought, well, the main form needs to be able to ask the child form
if it can save

So I made the following interfaces.

'all child forms implement ICanSave and return true or false;main can
thus always call CanSave to see if it can save
Public Interface ICanSave
ReadOnly Property CanSave() As Boolean
End Interface

'if they can save they should then implement ISave which has the
following... So when user clicks Save icon, this Save method 'is
called Public Interface ISave
Function IsDirty() As Boolean
Function Save() As Boolean
Function SaveAs(ByVal FileName As String) As Boolean
End Interface

IMO it is sufficient to implement the second interface. If the child
implements the interface, the child is "savable".
on main form
Private Sub frmMain_MdiChildActivate(ByVal sender As Object, ByVal e
As System.EventArgs) Handles MyBase.MdiChildActivate
Dim Savable As ICanSave
Dim ISaver As ISave
Try
'see if can save
Savable = Me.ActiveMdiChild
If Savable.CanSave Then
ISaver = Me.ActiveMdiChild
mnuFileSave.Enabled = ISaver.IsDirty
End If

mnuFileSaveAs.Enabled = Savable.CanSave
Catch ex As Exception
'don't know so disable them
mnuFileSave.Enabled = False
mnuFileSaveAs.Enabled = False
End Try
End Sub

Is there a better way?

Am I doing something dumb?

Is there another event to check when child form becomes dirty because
I think ChildActivate requires a click.

So how can I know when to enable the Save icon otherwise?


I'd probably declare an event in the ISavable interface (Event
IsDirtyChanged). On creation of a child form, the Mdi container can attach a
handler to the event. Either you know what type of child is created, so
you'll be able to type cast to ISavable and attach the handler, or, if each
child is sent through a common procedure, the procedure can do the same but
only after checking if it implements the interface.
The event handler above I'd probably write this way:

Private Sub frmMain_MdiChildActivate(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MdiChildActivate

Dim EnableMenu As Boolean

EnableMenu = TypeOf Me.ActiveMdiChild Is ISavable _
AndAlso DirectCast(Me.ActiveMdiChild, ISavable).IsDirty

mnuFileSave.Enabled = EnableMenu
mnuFileSaveAs.Enabled = EnableMenu

End Sub
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
26
by: Marius Horak | last post by:
As in subject. Thanks MH
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
13
by: John Salerno | last post by:
Hi all. I have a question about interfaces now. According to the book I'm reading, when you implement an interface, the class or structure has to declare all the methods that the interface...
6
by: John Salerno | last post by:
I understand how they work (basically), but I think maybe the examples I'm reading are too elementary to really show their value. Here's one from Programming C#: #region Using directives ...
10
by: Joe | last post by:
My question is more an OOD question. I know *how* to implement both abstract classes and interfaces. Here's my question - under what circumstacnes does one use an abstract class and under what...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
5
by: Colin McGuire | last post by:
Hi all, when I write the class below Private Class employee End Class and then add the line "Implements IVF" which is an interface I have written, the IDE modifies my code to display
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.