Accessing Text Box Values from Form to another class

后端 未结 2 395
情书的邮戳
情书的邮戳 2021-01-28 09:44

I have a WPF Application which contains a class called RateView.xaml.cs and MainWindow.xaml.cs

The MainWindow.xaml.cs contains three textboxes of which values I want to

2条回答
  •  -上瘾入骨i
    2021-01-28 09:46

    Just a small example (This is winforms)

    This is the mainwindow, where your textbox is:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    1
    public string TextBox1Text
    { 
      get { return textBox1.Text; }
      set { textBox1.Text = value;
    }
    }
    

    and this is a class where you want to interact with the textboxes:

    public class Test
    {
    public Test(Form1 form)
    {
    //Set the text of the textbox in the form1
    form.TextBox1Text = "Hello World";
    }
    }
    

提交回复
热议问题