-3

I'm a newbie in programming and can you help me about C#?

The thing is I want to get the value from another FORM and pass it to another FORM. IT'S LIKE A LOGIN-SIGNUP PROJECT WITHOUT using database/MYSQL

I have Form1.Form2,Form3.

When I click the button from FORM1 "Create Account" it will hide and Form2 will appear after you create an account there's a button "Create" and it will Hide and Form1 will appear and there's a button "View Account Details" and Click it and Form1 will Hide and Form3 will appear witch contain all the Details of your Account witch you create in Form2 AND it will all change if you CREATE A NEW ACCOUNT in FORM2.

Damiel
  • 71
  • 5
  • Add a public property to your form class. There are lots of examples of this. – Jonathon Reinhart Nov 27 '15 at 23:27
  • 1
    Welcome to StackOverflow. We would love to help but it might be wise to read the articles on [this](http://stackoverflow.com/help/asking) page before asking a (new) question. – Berendschot Nov 27 '15 at 23:28
  • @Damiel this is probably one of the easiest things to do if you understand C# Basics in regards to `Access Modifier` [C# Encapsulation](http://www.csharp-station.com/Tutorial/CSharp/Lesson19) – MethodMan Nov 27 '15 at 23:41
  • @Damiel also this is not a `Code Factory Site` and what is your question.. if you have `Form1, Form2, and Form3` then why not show what you have tried thus far .. as well as any actual code.. – MethodMan Nov 27 '15 at 23:43

1 Answers1

-1

Create a singleton class that holds all of your data. Form2 will set its values. Form 3 will read its values. Here's a simple example for the singleton:

public class LoginData
{
    public static readonly LoginData Instance = new LoginData();
    public string UserName {get; set;}
    public string Password {get; set;}
}

In your forms you will write something like

LoginData.Instance.UserName = inputBox.Text;

This is not how you would write a singleton for production grade code. But it should work for an academic exercise.

You could simplify this even more by just making the properties static and omitting the Instance variable like this:

public class LoginData
{
    public static string UserName {get; set;}
    public static string Password {get; set;}
}

Then you would access the properties like this:

LoginData.UserName = inputBox.Text;
Lorek
  • 855
  • 5
  • 11