Simulating the File Properties dialog

M

Mark Rae

Hi,

Suppose you are writing an MDI application, and each of the child windows
has document properties associated with it e.g. Author, Company etc exactly
the same as in the case of Microsoft Word, Excel etc.

You want to simulate the File, Properties functionality of the MS-Office
apps by providing a Dialog form which pops up and shows the current values
of the active MDI child window. What would be the best way to do this? Would
you use get and let in the child form's class? If so, how would you
reference the properties from the Dialog form?

Any assistance gratefully received.

Best regards,

Mark Rae
 
N

Nicholas Paldino [.NET/C# MVP]

Mark,

I would make sure that the child class implements an interface of some
sort. This interface would have a method or a property that you can call
that would get the data that is currently represented by the child form.
What is returned would then be represented by another interface, this
interface having the methods and properties which would expose the
information to be shown on the dialog. This way, you have a generic way of
exposing the data to be shown, and a generic way of representing the data.

Hope this helps.
 
M

Mark Rae

message
Nicholas,
I would make sure that the child class implements an interface of some
sort. This interface would have a method or a property that you can call
that would get the data that is currently represented by the child form.
What is returned would then be represented by another interface, this
interface having the methods and properties which would expose the
information to be shown on the dialog. This way, you have a generic way of
exposing the data to be shown, and a generic way of representing the data.
Thanks.

Hope this helps.

Not really, but thanks anyway.

Mark
 
G

Guest

I use a structure to pass info back and fourth

Have some functions in the parent/child that fill the structure and update the form
Have some functions in the dialog to initialise it and to send back updated data

If you send the form with ShowDialog() you can implement an Apply style button as well

How you actually pass the data is down to personal taste. The thing is to be consistent.
 
M

Mark Rae

Vas said:
I use a structure to pass info back and fourth.

Have some functions in the parent/child that fill the structure and update the form.
Have some functions in the dialog to initialise it and to send back updated data.

If you send the form with ShowDialog() you can implement an Apply style button as well.

How you actually pass the data is down to personal taste. The thing is to
be consistent.

That sounds good - do you have an examples of this, or can you point me to a
site?
 
G

Guest

Heres a rough kind of outline, sorry I just made it up

// Create a structur
public struct DetailsStruc

public string details
// ..


// Add a get functio
public DetailsStruct GetData(

DetailsStruct ds

ds.details = textBox1.Text
// ..

return ds


// Add a set functio
public void SetData(DetailsStruct ds

textBox1.Text = ds.details
// ..


Add the same type of functions to the dialog form

Then you can set and get the details

MyDialog dlg = new MyDialog()
dlg.SetData(this.GetData())
DialogResult dr = dlg.ShowDialog()
if(dr == DialogResult.OK
this.SetData(dlg.GetData())

If you want to use an Apply button, you have to set the dialogs Owner property. There's a few ways to do this, to use the parent form

dlg.ShowDialog(this)

Implement a Click handler for the dialogs Apply button to update the details

// get the active for
if(Owner.ActiveMdiChild.GetType().Equals(typeof(ChildFormA))

ChildFormA child = (ChildTypeA)Owner.ActiveMdiChild
child.SetData(this.GetData())

else if(Owner.ActiveMdiChild.GetType().Equals(typeof(ChildFormB))

// ..

else if(// ...

Let's say that all the child forms will have the get and set functions, then create an interface like Nicholas said, it'll simplify all that checking code for the Apply button

// All child forms will inherit from thi
interface IGetAndSe

void SetData(DetailsStruct ds)
DetailsStruct GetData()


Next, remove the checks for the Apply button and add a line like this to update the child, any child

((IGetAndSet)Owner.ActiveMdiChild).SetData(this.GetData())
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top