Ownership over a button

This is a discussion on Ownership over a button within the C# Programming forums, part of the General Programming Boards category; Hi, how do I take ownership ower a button or a textbox that is on another form? I take ownership ...

  1. #1
    Registered User BraneMxm's Avatar
    Join Date
    Apr 2007
    Location
    Croatia
    Posts
    20

    Ownership over a button

    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

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Buttons are windows too. It should work the same way. Alternatively, try to assign to the Parent property, if it exists.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Chuck Norris owns every button

  4. #4
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    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

    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                if (button1.Parent == this)
                    button1.Parent = panel1;
                else
                button1.Parent = this;
            }
    i could assign to button1's click method this function and it will alter the parent.
    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
    Code:
    private void button3_Click(object sender, EventArgs e)
            {
                f = new Form2();
                f.Show();
            }
    then i have another button that when clicked you can alter the parent like this.

    Code:
    private void button2_Click(object sender, EventArgs e)
            {
                button2.Parent = f;
            }
    this is all code in my form1 and my class has a member variable called f that is declared like

    Code:
    Form2 f;
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  5. #5
    Registered User BraneMxm's Avatar
    Join Date
    Apr 2007
    Location
    Croatia
    Posts
    20
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 09:30 PM
  2. button question
    By Rare177 in forum C# Programming
    Replies: 2
    Last Post: 01-05-2007, 10:59 AM
  3. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  4. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 12:32 PM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21