Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Application - controls on child forms 1

Status
Not open for further replies.

newora

Programmer
Aug 19, 2003
133
GB
Hi There could someone please point me in the right direction please, as I am stick again !!

I have an MDI application and each child form has a print button on it - always called cmdprint.

What I wish to do is have a menu option on the parent form called print and clicking on this calls the cmdprint button click event of the currently active child form, to print out a picture that is on the form.

I know how to get the active child form name and I know that I can loop down the controls collection to get a reference to the cmdprint button control, but what I can not figure out os how to actually call the click event of the control.

I have this so far :-

If Me.MdiChildren.Length > 0 Then
MsgBox(Me.ActiveMdiChild.Name)
For Each clscontrol In Me.ActiveMdiChild.Controls
If UCase(clscontrol.Name) = "CMDPRINT" Then
clsconret = clscontrol
End If
Next
End If

This obviously gives me a reference to the cmdprint control on the active MDI child form, but I now want to actually call the event click handler for the control, which is where the logic to print the pciture is located.

Any help,as always, would be greatly appreciated.
 
You could try:

ctype(clscontrol, button).performclick


(not tested)


Hope this helps

[vampire][bat]
 
Thanks earthandfire,

Thats absolutely great - worked first time. I would have never have found that in a million years - looked at MSDN / help files for hours (it seemed it anyway) and found nothing.


Can you recommend any good books / websites to try to bring me up to speed and try to get to your level LOL.

Thanks a lot again - much appreciated.
 
I don't know why you want to be as bad as E&F ;-) but Normally you would make a method public and call that just like the onclick event of that button.

So you probably have a class/form with the click eventhandler that has all the code to print the picture. cut and paste all that code in a "public sub blabla()" and then replace the cutted code with "blabla()". Now you can simplify the above code like this.

ctype(me.activechild, mdiformname).blabla

mdiformname being the name of the class/form you use as mdi. I suppose they are all the same form/class.

Christiaan Baes
Belgium

"My new site" - Me
 
You have do use delegates...
( ) for info

Here is an example to get/set a child's textbox property:

Form1 is the mdiparent. Use the following to load a new child (form2)

Dim f As New Form2
f.MdiParent = Me
f.Show()

Form2 has a textbox. Name of it is textbox1. You can set it's text property simply by:

CType(Me.ActiveMdiChild.Controls("textbox1"), TextBox).Text = "Hello"

Try it to see if it works.

What you could do is to place the code for printing in the mdi form, and use the above line of code to get some properties of the controls, information that you propably need for printing.
Last, you can use the child's form tag property to store a value. Getting this value you can know what child is currently active so to launch to correct printing process. I mention that in case you have more than one different types of child forms (like form3).
 
Thanks for your insight TipGiver and Chrissie1,

I understand and follow what you are saying - I will do some tests with your ideas, just to help be gain a better understanding really.

TipGiver I am stil using VS 2003 and so I do not think that I can reference the controls collection by name, only index. Can not afford to move to VS 2005 yet I am afraid.

Thanks again for your help with this - is has encouraged me to not to go to the pub tonight and to do some further research on the web! LOL

 
chrissie, I agree (in principle) - I use both methods.

Sometimes .PerformClick is sufficient and shouldn't be ignored just because there is a more OOPish alternative.

newora I've found books by Balena and Petroutsos (2003 and 2005 versions available) to be invaluable - as well as MSDN and this forum withy people like chrissie, ThatRickGuy and ChipH to name just a few.


Hope this helps

[vampire][bat]
 
Thanks earthandfire - will get browsing Amazon!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top