-3

I want to use the data form Form1 in Form2.

I did it in Public, but it didn't happen again.

I Can't get data from Form1 into Form2. How can I fix this problem?

.

Form1 f1 = new Form1();
Random rnd = new Random();
Font fnt = new Font(f1.comboBox1.SelectedIndex.ToString(),12);
TextureBrush tbr = new TextureBrush(Image.FromFile("kaplan.jpg"),
System.Drawing.Drawing2D.WrapMode.Tile);
g.DrawString(f1.textBox1.Text, fnt, tbr, rnd.Next(0, 1024), rnd.Next(0, 768));

amitklein
  • 1,302
  • 6
  • 23
Mustafa Koca
  • 5
  • 1
  • 6
  • What it is the exact error? – ckuri May 24 '20 at 18:05
  • Your question has some wierdness. The Properties accesds modifer can be public, but Modifiers do not have properties. | While you create a Form1 instance, you do not show it. Did you expect a totally different Form1 Instance to realate to the new created one? – Christopher May 24 '20 at 18:09
  • The exact error is that I can't get the data in form1 from form2, even though it's public. – Mustafa Koca May 24 '20 at 18:21
  • How did you show form2? Show us that code. You are supposed to pass a reference of the existing Form1 to form2 when calling `Show()` or `ShowDialog()`. – preciousbetine May 24 '20 at 18:22
  • thank you. but we can pull the properties in form1 to form2 normally. but I couldn't. – Mustafa Koca May 24 '20 at 18:26
  • Form2 frm = new Form2(); frm.Show(); this.Hide(); – Mustafa Koca May 24 '20 at 18:27
  • There is a lot of info on how to pass variables between forms. In addition, there are several ways to do this. I recommend you take a look at the selected answer to this question… [Communicate between two windows forms in C#](https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp) … Pay attention to “how” the second form is called from the first form, and pay attention to the second forms constructor. If you can’t get it working, then you should show “how” the first form is calling the second form in addition you should show the second forms constructor. – JohnG May 24 '20 at 19:58
  • Does this answer your question? [Communicate between two windows forms in C#](https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp) – JohnG May 24 '20 at 19:59

1 Answers1

-1

Go to the Form1.cs hold ctrl and press on the InitializeComponent();

Hold ctrl and press on the name comboBox1 in the line this.comboBox1 = new System.Windows.Forms.ComboBox();

Now change the lines

private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox1;

to

public System.Windows.Forms.ComboBox comboBox1;
public System.Windows.Forms.TextBox textBox1;

Here are some images for you to follow:

enter image description here

enter image description here

enter image description here

amitklein
  • 1,302
  • 6
  • 23