Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i Want when i Click My first Form Button then Open my Second Form as a DialogBox and in DilogBox Form Button1 is Hide

i Try in First Form
C#
public Status(Form1 _f1)
        {
            InitializeComponent();
            this.f1 = _f1;
        } 

Form1 f1;

private void Open_Click(object sender, EventArgs e)
        {
            Form1 dlg1 = new Form1(this);
            dlg1.ShowDialog();
            f1.button1.Visible = false;
        }
but when i Click Open Button My Second Form Open but Button1 is still Visible but i want in my second form don't show when i open My Second Form By Clicking "open" Button

What I have tried:

in Second Form
C#
public Form1(Status _f3)
        {
            InitializeComponent();
            this.f3 = _f3;
        }

        public static string setvaluefortext1 = "";

        Status f3;


private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty)
            {
                this.Close();
            }
            else
            {
                
            }
        }
Posted
Updated 20-May-20 7:36am
v3

You are not transferring any information between the forms. In this case the information you should be transferring is the Visible property of a control on the form. It is not as simple as just trying to set the value from outside the form that contains the control.

Have a look at @Original-Griff's series of tips on the subject, starting with Transferring information between two forms, Part 1: Parent to Child[^] (also contains links to the other two)
 
Share this answer
 
Comments
Amar chand123 20-May-20 11:38am    
i just start Programming and start Learn From Internet and from my Past Mistakes, so can you explain me in easy way how i solve this Problem just some help
CHill60 21-May-20 7:44am    
Actually the tips I provided the link to explain several easy ways to do this. I see phil.o has posted an explicit answer. That concept of passing something to the form in the constructor was the very first thing that article suggested. As you say you are trying to learn from the Internet (not necessarily a good tactic) then I still recommend that series of Tips
Amar chand123 21-May-20 10:50am    
Sir Chill60, i READ your shared link and download project source code for study and try to learn and thank you for sharing and answering my question
You could modify the constructor of Form1 to accept a boolean value setting the visibility of the button.
Status:
C#
public Status(Form1 _f1)
{
   InitializeComponent();
} 

Form1 f1;

private void Open_Click(object sender, EventArgs e)
{
   f1 = new Form1(this, false);
   f1.ShowDialog(this);
}

Form1:
C#
public Form1(Status _f3, bool buttonIsVisible)
{
   InitializeComponent();
   this.f3 = _f3;
   this.button1.Visible = buttonIsVisible;
}

// ...
 
Share this answer
 
Comments
Amar chand123 20-May-20 12:56pm    
Thank you sir Phil.o
phil.o 20-May-20 13:12pm    
You're welcome. Please mark your question as answered if your problem is solved.
Your Open_Click method is calling ShowDialog before setting the Visible property of the button. ShowDialog is modal, which means that the code to set the Visible property will not be called until the second form is closed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900