From other Form i want to set visibility for textBoxes on this form but i down't know how to call TextBoxes and set property Visible = false.
I try with Enums but i still can't solve problem. I can not cast or do anything. So how can i call textBox Fro开发者_Python百科m form1 to form2...
i am using C# and CF 3.5
public enum VnosTextBoxType
{
Ean, PredmetObravnave, Tse, Kolicina, EnotaMere,
Lokacija, Zapora, Sarza, SarzaDobavitelja, Datumod,
DatumDo
}
this are names for all my TextBoxes. I have TextBoxes with names like txtEan, txtPredmetObravnave,..
What about writing on Form2 a method like this:
public void SetTBVisible(string name, bool visible)
{
this.Controls[name].Visible = visible;
}
and call this form your Form1?
EDITED:
public void SetTBVisible(string name, bool visible)
{
string cName = name.ToLower();
foreach(Control c in this.Controls)
if (c.Name.ToLower() == cName)
{
c.Visible = visible;
break;
}
}
let say you want to set Visible = false for textbox1 of form1
when you create instance of form2 then you have pass the instance of form1 into its constructor like this
Class Form1 : Form
{
public void setTextbox(bool val)
{
this.Textbox1.visible=val;
}
Public void showForm2()
{
Form2 f2= new Form2(this);
f2.show();
}
}
Class Form2 : Form
{
Form1 f1;
public Form2(Form form1)
{
f1=form1;
}
public void setTb()
{
f1.setTextbox(false);
}
}
I Hope this will help you
Make a new class called Globals.cs write:
public static Form1 MainForm;
public static Form2 ChildForm;
go to Form1 and make the event: form load put:
Globals.MainWindow = this;
and:
CheckForIllegalCrossThreadCalls = false;
and do the same in Form2 with ChildForm now you can call form2 with: Globals.ChildForm.TextBox1.Visible = false;
Edit: don't forget to make your textBox public.
精彩评论