|
-
May 8th, 2002, 08:48 PM
#1
Thread Starter
PowerPoster
Set the parent of a control at runtime
The Parent property on every control is only read-only at runtime. What other way would I set the parent of any control at runtime? I Have tried "SetParent" but it won't work for label control (doesn't have hWnd property) and don't know why it doesn't respond to any event when it's showed up on it's new parent form.
-
May 8th, 2002, 08:49 PM
#2
try
VB Code:
Set Label1.Container = Frame1
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 8th, 2002, 08:52 PM
#3
Re: Set the parent of a control at runtime
Originally posted by abdul
The Parent property on every control is only read-only at runtime. What other way would I set the parent of any control at runtime? I Have tried "SetParent" but it won't work for label control (doesn't have hWnd property) and don't know why it doesn't respond to any event when it's showed up on it's new parent form.
Sorry for this question, but *** is Parent?, and what blade's code does?
-
May 8th, 2002, 08:57 PM
#4
Thread Starter
PowerPoster
Originally posted by crptcblade
try
VB Code:
Set Label1.Container = Frame1
Hmmm, it's not working. Shows me "Invalid Object Use" error.
My code is like:
VB Code:
Set frmExtra.Command1.Container = whichform
So the code is in the module, and it takes the control from frmExtra and shows that on whichform.
-
May 8th, 2002, 08:58 PM
#5
Sorry, that method won't work between forms.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 8th, 2002, 08:58 PM
#6
Thread Starter
PowerPoster
Re: Re: Set the parent of a control at runtime
Originally posted by Stiletto
Sorry for this question, but *** is Parent?, and what blade's code does?
Parent property of a specific control contains the object that this control in placed on. Blade's code doesn't work yet.
BTW, are you drunk?
-
May 8th, 2002, 09:00 PM
#7
Thread Starter
PowerPoster
Originally posted by crptcblade
Sorry, that method won't work between forms.
Awww, any other way you can think of to switch the control among different forms?
-
May 8th, 2002, 09:03 PM
#8
Re: Re: Re: Set the parent of a control at runtime
Originally posted by abdul
Parent property of a specific control contains the object that this control in placed on. Blade's code doesn't work yet.
BTW, are you drunk?
Me, no...
So you mean like this:
VB Code:
Form1.Command1.Container = Form1
?
-
May 8th, 2002, 09:05 PM
#9
Thread Starter
PowerPoster
Re: Re: Re: Re: Set the parent of a control at runtime
Originally posted by Stiletto
Me, no...
So you mean like this:
VB Code:
Form1.Command1.Container = Form1
?
Maybe this will work but I want to go from one form to another like this:
VB Code:
Form1.Command1.Container = Form2
-
May 8th, 2002, 09:05 PM
#10
Can I ask why you need to do this? Maybe there is a better way.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 8th, 2002, 09:09 PM
#11
Thread Starter
PowerPoster
I want the user to be able to add different controls on the form at runtime. Obviously, I'll have more than 1 form and each form should be loaded with no control (empty like in vb) then you can choose a control from the toolbar and draw it on the form you have chosen. Right now, I have places all the common controls on one form, frmExtra, and when the user wants to draw a control on a specific form, I just increase the dimension of the array of that specific control and then move it to the form where the user wants to draw it.
Maybe there is another way but I can't think of that right now...
-
May 8th, 2002, 09:12 PM
#12
Lemme get this. If the control is on Form1, so the Container property of that control will be Form1, is that correct?
If so, as i understand it, you cant do this Abdul:
VB Code:
Form1.Command1.Container = Form2
Since the control is on Form1.
Or this is possible, and it will remove the control from form1 to form2?
-
May 8th, 2002, 09:14 PM
#13
Thread Starter
PowerPoster
This method will give you an error message that's why I am looking for another way to do this.
-
May 8th, 2002, 09:29 PM
#14
New Member
just make a control array on the form u want 2 add 2 then use:
load command(x)
command(x).top=command(x-1).top+120
command(x).visible=true
-
May 8th, 2002, 09:51 PM
#15
Thread Starter
PowerPoster
Yes, but I'll have to do that on every single form. I am trying another way right now but I think this method will also work with more ease.
-
May 8th, 2002, 10:06 PM
#16
The picture isn't missing
try using the SetParent API
VB Code:
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
SetParent Form1.Command1.hWnd, Form2.hWnd
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
May 8th, 2002, 10:08 PM
#17
Thread Starter
PowerPoster
Originally posted by BuggyProgrammer
try using the SetParent API
VB Code:
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
SetParent Form1.Command1.hWnd, Form2.hWnd
1) Somehow, it just doesn't respond to any event on the command button quite right.
2) It won't work for a label control because it doesn't have a 'Hwnd" property.
-
May 8th, 2002, 10:15 PM
#18
The picture isn't missing
well then you're out of solutions now.........
Remember, if someone's post was not helpful, you can always rate their post negatively  .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|