0

I am using two forms in a windows form application in C#.I want to pass the tabControl's properties like its "Tabpage count" from first form to second form. Can anyone help me here?I can't create object of first form in second form and call a function beacuse for a new forn object, the tabcontrol gets refreshed.

leppie
  • 115,091
  • 17
  • 196
  • 297
Arun Kannath
  • 73
  • 1
  • 1
  • 10
  • can you provide some code - what you have, and what you have tried already? – totallyNotLizards Dec 09 '14 at 10:29
  • If you want to send from Form1 to Form2, then either create an object of Form2 in Form1 and assign like objForm2.propertyinForm2 or create parameterized constructor in Form2 and call like Form2 objForm2=new Form2(param1,param2...) @Arun Kannath – Sarath Subramanian Dec 09 '14 at 12:01

4 Answers4

0

Inside your first form create an instance of your second Form class as this

Form frm= the instance of your secand form

after that show the instance of your secand form, now you exactly have an instance of your secand form inside your first form and can use all the public properties of it

void
  • 7,760
  • 3
  • 25
  • 43
0

You can create static public functions exposing desired control properties like in below code.

 public static Color TabColor()
{
return Form1.Fom1TabControl1.SelectedTab.ForeColor;
}

and you can access Form1 properties like below;

private void Form2_Load(object sender, EventArgs e)
{
    this.Fom2TabControl1.SelectedTab.ForeColor = Form1.ForeColor;
}
Anil
  • 3,722
  • 2
  • 24
  • 49
0

First Check your class accessibility and set to public if not work set public static, maybe your namespaces is different hope it helps

Jamaxack
  • 2,400
  • 2
  • 24
  • 42
0

This can be achieved in two ways

Aprroach 1:

Create a public variable in Form2

public int intTabCount=0;

and in Form1, you should call Form2 like

Form2 objForm2 = new Form2();
objForm2.intTabCount = tabPageCountVariable;
objForm2.Show()

Aprroach 2:

Create a parameterized constructor and public variable in Form2

public int intTabCount=0;

public Form2(int TabCounts)
{
   intTabCount = TabCounts; // and use intTabCount for your class
}

and call from Form1 like

Form2 objForm2 = new Form2(tabPageCountVariable);
objForm2.Show();

Now if you want to pass value through any events like clicking an button in Form1 which updates anything in Form2, use the below link Passing Values Between Windows Forms c#

Community
  • 1
  • 1
Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86