Jump to content

How can I transfer variables between forms?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
katspn

katspn

    Newbie

  • Members
  • Pip
  • 3 posts
I am a student and therefore not to bright ;-)

I am currently working on an assignment in C# which requires me to create a program in a windows application using more then one form which I have never done before, infact I have 5 forms and I just cannot seem to figure out how to move information from a variable between them.

I have created a class in which which I have declared all the variables I will need but I cant get to the information from my forms.

Any help would be greatly appriciated.

#2
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
I'm not too clear on what you're after. Do you want the 'information' (as in, the values) of components on your form (like the text from a text box)? Or are you literally trying to provide access of declared variables in one form class, to another form class?

Or something entirely different again?

#3
veda87

veda87

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Have a look at this video tutorial. This might help you a bit...
How to Transfer Information Between Forms

#4
katspn

katspn

    Newbie

  • Members
  • Pip
  • 3 posts
Thanks you for your help,
I have found what the problem was, I did not make the variables "public static".
:cursing:

#5
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
inside a function? Doesn't sound like legal syntax.

#6
yoda174

yoda174

    Newbie

  • Members
  • PipPip
  • 25 posts
I was in these situation,and that worked me well.

To transfer data(s) beetwen forms :
Create example a string

:

public static string test = "";

then

test=textbox1.text; //or whatever you want.

Form2 form_that_we_want_to_send_data = new Form2();

//In the main part of form_that_we_want_to_send_data

label1.text=Form1.test;

#7
Pr0grammer

Pr0grammer

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

//In Form2 (that_we_want_to_Received_data):
Public int MyVariable;


//In Form1 (that we_want_to_send_data):
Form2 frm = new Form2()
frm.MyVariable = Convert.ToInt32(TextBox1.Text);
frm.Show();

Good Luck