2 Replies - 1036 Views - Last Post: 26 February 2012 - 11:14 AM Rate Topic: -----

#1 Dan1el  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-February 12

Passing values from one form to another [Help]

Posted 25 February 2012 - 10:00 AM

Hi, I'm kinda new to C# programming. But it hasn't been so hard since I've studied VB.NET a bit.

What I'm trying to do is pass strings from one form to another.
I've a form, that has like "settings" and then in a button "extra settings", the button will take you to another little form where it has some more options to choose.
So what I'm trying to do is when you click "Set" in the second form, it will close and set the extra options in the first form.
I know that in VB.NET is something like:

Form1.Label1.Text = Me.TextBox1.Text


But it can't be that simple in C#, and I've tried:

frmMain frm = new frmMain();
frm.personName = this.txtName.Text; //personName is a public string


But for this to work I'd need to first close the first form and reopen it, but I don't/can't want to/do that since I I want the first form to be always there, well, it is the main one.
Can anyone help me?

Is This A Good Question/Topic? 0
  • +

Replies To: Passing values from one form to another [Help]

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5476
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Passing values from one form to another [Help]

Posted 25 February 2012 - 10:09 AM

The way you are going about this; tightly binding the two forms; giving them direct knowledge and control over GUI controls on the other form etc. is just plain wrong.


This comes up so often it is number 3 on my FAQ list

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Form1 talk to Form2


FAQ (Frequently Asked Questions - Updated Feb 2012
Spoiler



This post has been edited by tlhIn`toq: 25 February 2012 - 10:10 AM

Was This Post Helpful? 0
  • +
  • -

#3 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4463
  • View blog
  • Posts: 7,777
  • Joined: 08-June 10

Re: Passing values from one form to another [Help]

Posted 26 February 2012 - 11:14 AM

I wrote a tutorial on this subject:

http://www.dreaminco...ny-other-forms/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1