hi,
i made a form1(FrmMain) and when i press on BtnAdvocaat form2(FrmAdvocaat) is vissable and BtnAdvocaat is disabled. now i want to make it like this:
when the form2(FrmAdvocaat) is closed by BtnClose i want BtnOpen to be enabled.
the code to open so far is:

private void button1_Click(object sender, EventArgs e)
        {
            FrmAdvocaat form2 = new FrmAdvocaat();
            form2.Show();
            BtnAdvocaat.Enabled = false;
        }

and on form2 i have a button with this code:

private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

now how could i get BtnAdvocaatr.enabled = true; on form1?
in delphi it's just FrmMain.BtnAdvocaat.enabled = true;
but i don't know how to call other button on another form...
plz some help with this ;)

Recommended Answers

All 8 Replies

Just make your button control access modifier public, then handle second form closing event to enable the button by your code.

i just started with C# and i have no idee how to make button control access modifier public could you give me litle more info?

When you drag and drop a control into the Windows Form in the Designer It automatic crate a private field that represent the control you just added.

What you need to do is go to de Designer File it and change the access modifier to public.

You can find the dedigner file int the Solution Explorer under 'Form.cs'(Form its the name of your form) just expande the tree view(+) and you will see the 'Form.Designer.cs' and you will find the field declaration at the end of the file.

Thanks
Camilo

P.S: Access Modifier in C#(public, private, internal...)

tanx for help, i managed to make it public but still don't get how to use that button... i just can't get it...
what kind of code should i use...
because i can't just do

BtnAdvocaat.enabled = true;

(btnAdvocaat is the button that needs to be enabled on first form from 2nd form.)
should i anounce the form the button is on or so? and how can i do that?
could you give me litle piece of code? then i can edit it myself :)

sorry for all the questions... just finished learning litle delphi but because i wasn't good enough in school i had to make a litle program in C# but i won't get any support by my teacher... so that's why i have to ask almost everything...
maby you also know a good tutorial where i can learn this a bit?

You can access the button thru form2 object instance after changing the modifier as public
like

private void button1_Click(object sender, EventArgs e)
        {
            FrmAdvocaat form2 = new FrmAdvocaat();
            form2.Show();
            [B]form2.BtnAdvocaat.Enabled = false;[/B]
        }

ok and how could i do it when i don't wanna open a new form? but enable the button that's still active on other form.
i have this code so far:

private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            FrmMain form1 = new FrmMain();
            form1.BtnAdvocaat.Enabled = true;

        }

but still the button on FrmAdcovaat isn't enabled... but i think that's because with form1.show makes totaly new form... and i just wanna edit the button on form that's already visable..

This is what you need to do

In Form1.cs:

private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            this.AddOwnedForm(f2);
            f2.Show();
        }
In Form2.cs:
           private void button2_Click(object sender, EventArgs e)
        {
            this.Owner.Controls["BtnAdvocaat"].Enabled = true;
            
                       this.Close();

        }

note: with this solution there is no need for changing the access modifier of the BtnAdvocaat to public.

Camilo

tanx alot :)
this was just what i needed ;)
now i can continue my program again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.