Accessing Text Box Values from Form to another class

后端 未结 2 391
情书的邮戳
情书的邮戳 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条回答
  • 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";
    }
    }
    
    0 讨论(0)
  • 2021-01-28 10:13

    To get and set the value of a textbox within another class/form you can do it with something like:

    public string TextBox1Text
    { get { return textBox1.Text; } 
      set { textBox1.Text = value; } }
    
    0 讨论(0)
提交回复
热议问题