Hi,
how do I take ownership ower a button or a textbox that is on another form?
I take ownership ower a form like this:
frm1.Owner=frm2;
I want the same thing for a button! But how?
Thanks
Printable View
Hi,
how do I take ownership ower a button or a textbox that is on another form?
I take ownership ower a form like this:
frm1.Owner=frm2;
I want the same thing for a button! But how?
Thanks
Buttons are windows too. It should work the same way. Alternatively, try to assign to the Parent property, if it exists.
Chuck Norris owns every button
Thanks KONI for that infinitely productive and enlightening response.
Brane, you want a button from one form moved to another?
like an example, my ok button from my main form moved to the settings form? or like you have a button inside a panel and you want to move it to the main form instead of being inside that panel?
so if i have a button named button1 and a panel named panel1
i could assign to button1's click method this function and it will alter the parent.Code:private void button1_Click(object sender, EventArgs e)
{
if (button1.Parent == this)
button1.Parent = panel1;
else
button1.Parent = this;
}
Since the parent changes, the "Location" that is assigned to the button is applied towards its parent so if you have your button at 12,12 and your panel at 30,30 you will see a difference when you click the button.
is this what your looking for? or you want to move the button to a totally different form all together?
if you want to move it to a new form, you have to have that form created and shown first
so if i have a button that creates my form and shows it
then i have another button that when clicked you can alter the parent like this.Code:private void button3_Click(object sender, EventArgs e)
{
f = new Form2();
f.Show();
}
this is all code in my form1 and my class has a member variable called f that is declared likeCode:private void button2_Click(object sender, EventArgs e)
{
button2.Parent = f;
}
Code:Form2 f;
Thnks for the response AtomRiot
It looks like this:
I have 2 forms. One has an button and an textbox. The other has just one button.
It doesnt matter how where and wenn the forms are created.
A click on the button on form2 should make form2 the owner of the button and textBox that are on form1.
Thank you