How to call a form from another class in C#
I have a form and a class. I have a string variable in the class, I want
it's value to be a textbox value from the form. and then I want to reuse
this value in the same class.
The code I am using for the class is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Windows.Forms;
using System.Data;
namespace Teaching_Time
{
class ConnectToSpecificDB
{
//Set the variables
private string name;
private Login LoginForm;
//Constructor
public ConnectToSpecificDB()
{
Initialize();
LoginForm = new Login();
}
//Initialize values
private void Initialize()
{
name = LoginForm.TextBox1.Text
}
public void Fill (TextBox tb)
{
tb.text = name;
}
When I run the application using this code the application never opens,
The memory keeps increasing but it never opens. If it doesn't make sense
please let me know and i'll explain it more.
The above code isn't what I am really doing. It's just an example of what
I want to do, but I am sure the problem is when I add those 2 lines
private Login LoginForm;
And
LoginForm = new Login();
No comments:
Post a Comment