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!

Dynamic control creation under MDI Form 2

Status
Not open for further replies.

CmPaiva

Programmer
Nov 13, 2002
124
PT
Using .Controls.Add("VB.CommandButton", "Up"),is possible to create a control at runtime.
The question is:
Does anybody know , how to do the same but for MDI forms?
The problem is that ie. CommandButton doesn't have an .Alignment property, thus the system is unable to add it to the controls collection.

Any work around?

Thanks in advance for your cooperation,
Carlos Paiva
 

You need to create a container object for the command button that has an alignment property, like a picture box.

Good Luck

 
Thakns for the reply

Sorry, but i forgot to say something:
The problem is assigning the CommandButton to a picturebox (ie. LeftPanel) already existing in the form. I don't know how to pass, to the Controls colection, the parent reference,(?! for the Add method). VB don't let you create control And then setup the parent object, so i think that it must be made i some other way...
Changing control parent, will be easier, throught SetParent API, but I need to add control to collection first...

Carlos Paiva
 

I gave it a try and I see now exactly where your problem is and no I don't have any further suggestions at this time.


Good Luck

 
Er...you can't do this directly. There are a large number of controls that cannot be added to the MDI parent form. The command button is one of them.

So you need to fake it. You'll need at least one MDI child form. Add the command button to that, then chamge the parent using the SetParent API. Eg:

Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long


Private Sub Command1_Click()
Dim fred As CommandButton
Set fred = Form1.Controls.Add("VB.CommandButton", "Up")
SetParent fred.hWnd, MDIForm1.Picture1.hWnd
fred.Visible = True
End Sub
 

That's what I tried to do ... damn, damn, damn ... but forgot the API. Has anyone seen my mind?

Good Luck

 
Thanks for the sugestion.I' solved the problem yesterday night, by using an MDI child form without border, loaded at startup, and placed where my PictureBox panel was previously.It only requires some care with resize events.
This could be acomplished, cos i only use MDI for easy of use of some features, and not for use of a true multi-document application.
Anyway, thanks to both of you for listen to my problem and try some work around.

Carlos Paiva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top