5 Replies - 2094 Views - Last Post: 26 February 2012 - 02:50 PM Rate Topic: -----

#1 roguex20  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 11-August 11

Pass Value from One Form to Another Form

Posted 25 February 2012 - 11:59 AM

I can't seem to pass the value "destFile2" to the 2nd form "form2".

string destFile2 = System.IO.Path.GetFileName(ofd.FileName);

Not sure how to unbox this correctly or if that is even the route I have to take.
Do I need to create a struct? If there is a BEST PRACTICE way to do this please advise. I'd like to pass it without creating the struct or to at least know if that can be done.
Is This A Good Question/Topic? 0
  • +

Replies To: Pass Value from One Form to Another Form

#2 JizzaDaMan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 137
  • Joined: 23-May 11

Re: Pass Value from One Form to Another Form

Posted 25 February 2012 - 12:05 PM

if you want to pass a variable into a class, you can pass it into the class constructor method :

Form2 form2 = new Form2(ValueForDestFile2);

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4928
  • View blog
  • Posts: 10,465
  • Joined: 02-June 10

Re: Pass Value from One Form to Another Form

Posted 25 February 2012 - 12:18 PM

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



Was This Post Helpful? 0
  • +
  • -

#4 roguex20  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 11-August 11

Re: Pass Value from One Form to Another Form

Posted 25 February 2012 - 01:44 PM

View PostJizzaDaMan, on 25 February 2012 - 12:05 PM, said:

if you want to pass a variable into a class, you can pass it into the class constructor method :

Form2 form2 = new Form2(ValueForDestFile2);

Thanks! Will try it when I get home shortly.
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

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


Reputation: 3803
  • View blog
  • Posts: 6,410
  • Joined: 08-June 10

Re: Pass Value from One Form to Another Form

Posted 26 February 2012 - 11:21 AM

View Postroguex20, on 25 February 2012 - 02:44 PM, said:

View PostJizzaDaMan, on 25 February 2012 - 12:05 PM, said:

if you want to pass a variable into a class, you can pass it into the class constructor method :

Form2 form2 = new Form2(ValueForDestFile2);

Thanks! Will try it when I get home shortly.


That only works if you set the constructor up to use a parameter.

I've actually written a tutorial on this sort of thing:

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

#6 roguex20  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 11-August 11

Re: Pass Value from One Form to Another Form

Posted 26 February 2012 - 02:50 PM

View PostCurtis Rutland, on 26 February 2012 - 11:21 AM, said:

View Postroguex20, on 25 February 2012 - 02:44 PM, said:

View PostJizzaDaMan, on 25 February 2012 - 12:05 PM, said:

if you want to pass a variable into a class, you can pass it into the class constructor method :

Form2 form2 = new Form2(ValueForDestFile2);

Thanks! Will try it when I get home shortly.


That only works if you set the constructor up to use a parameter.

I've actually written a tutorial on this sort of thing:

http://www.dreaminco...ny-other-forms/


I actually read that tutorial and got the value passed. Thanks!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1