I have a small problem passing values between classes while a textbox is used.
I can reach the public variable (field) for the textbox that belongs to the Form class from my other class, but no values in textbox1.text can be passed from the Form class to my other class. Thought is was some datatype issue first, but no values at all, completely empty.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace myNameSpace
{
public partial class myForm : Form
{
public string myFirstValue;
public myForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
myOtherClass getOther = new myOtherClass();
getOther.SecondText();
FirstText();
label1.Text = Convert.ToString(myFirstValue) + " " + getOther.mySecondValue.ToString();
}
public void FirstText()
{
myFirstValue = textBox1.Text;
}
}
class myOtherClass
{
public string mySecondValue;
string FirstValue;
public void SecondText()
{
myForm getForm = new myForm(); // 1. Instance
getForm.FirstText(); // 2. Method
FirstValue = getForm.myFirstValue.ToString(); // 3. Field
mySecondValue = FirstValue; // The value from textbox1
}
}
}