• <legend id='DmY21'><style id='DmY21'><dir id='DmY21'><q id='DmY21'></q></dir></style></legend>

      • <bdo id='DmY21'></bdo><ul id='DmY21'></ul>
    1. <small id='DmY21'></small><noframes id='DmY21'>

    2. <i id='DmY21'><tr id='DmY21'><dt id='DmY21'><q id='DmY21'><span id='DmY21'><b id='DmY21'><form id='DmY21'><ins id='DmY21'></ins><ul id='DmY21'></ul><sub id='DmY21'></sub></form><legend id='DmY21'></legend><bdo id='DmY21'><pre id='DmY21'><center id='DmY21'></center></pre></bdo></b><th id='DmY21'></th></span></q></dt></tr></i><div id='DmY21'><tfoot id='DmY21'></tfoot><dl id='DmY21'><fieldset id='DmY21'></fieldset></dl></div>
      <tfoot id='DmY21'></tfoot>

        将文本框值从表单访问到另一个类

        Accessing Text Box Values from Form to another class(将文本框值从表单访问到另一个类)

          <small id='0SXxx'></small><noframes id='0SXxx'>

            <tfoot id='0SXxx'></tfoot>

                <tbody id='0SXxx'></tbody>
              <i id='0SXxx'><tr id='0SXxx'><dt id='0SXxx'><q id='0SXxx'><span id='0SXxx'><b id='0SXxx'><form id='0SXxx'><ins id='0SXxx'></ins><ul id='0SXxx'></ul><sub id='0SXxx'></sub></form><legend id='0SXxx'></legend><bdo id='0SXxx'><pre id='0SXxx'><center id='0SXxx'></center></pre></bdo></b><th id='0SXxx'></th></span></q></dt></tr></i><div id='0SXxx'><tfoot id='0SXxx'></tfoot><dl id='0SXxx'><fieldset id='0SXxx'></fieldset></dl></div>
                <bdo id='0SXxx'></bdo><ul id='0SXxx'></ul>

                <legend id='0SXxx'><style id='0SXxx'><dir id='0SXxx'><q id='0SXxx'></q></dir></style></legend>
                • 本文介绍了将文本框值从表单访问到另一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 WPF 应用程序,其中包含一个名为 RateView.xaml.cs 和 MainWindow.xaml.cs 的类

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

                  MainWindow.xaml.cs 包含三个文本框,我想将它们的值传递到 RateView.xaml.cs.这些文本框的内容可以由最终用户更改,但无论如何我总是希望文本框的值进入 rateview.xaml.cs.

                  The MainWindow.xaml.cs contains three textboxes of which values I want to pass into the RateView.xaml.cs. The content of these textboxes can be changed by the end user but regardless of that I always want whatever the value is of the textbox to be going into rateview.xaml.cs.

                  如何做到这一点?

                  我是编码新手,因此不确定,有人提到 Get 和 Set 语句,如果是,我该怎么做?

                  I am a newbie to coding hence not sure, someone mentioned Get and Set statements, if so how can I do these?

                  目前我在 MainWindow 中像这样访问我的文本框:

                  Currently I access my textboxes like this in the MainWindow:

                  private float GetSomeNumber()
                  {
                      bool Number1 = false;
                      float parsedNumber1Value = 0.00F;
                      Number1 = float.TryParse(Number1_TextBox.Text, out parsedNumber1Value);
                      return parsedNumber1Value;
                  }
                  

                  然后将 GetSomeNumber() 方法传递给另一个单独的类以进行一些计算.

                  The GetSomeNumber() method is then passed to another seperate class to do some calculation with.

                  在初始加载时,它适用于我方法中的值,但一旦有人更改值 rateview.xaml.cs 就无法识别此更改,并且始终使用第一次加载的值.

                  On intital load it works of the value from my method, but once someone changes the value rateview.xaml.cs doesn't recognise this change and always uses the values that were first loaded.

                  谢谢

                  推荐答案

                  只是一个小例子(这是winforms)

                  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";
                  }
                  }
                  

                  这篇关于将文本框值从表单访问到另一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                • <legend id='yXSzh'><style id='yXSzh'><dir id='yXSzh'><q id='yXSzh'></q></dir></style></legend>

                        <small id='yXSzh'></small><noframes id='yXSzh'>

                        <tfoot id='yXSzh'></tfoot>
                          <bdo id='yXSzh'></bdo><ul id='yXSzh'></ul>

                            <i id='yXSzh'><tr id='yXSzh'><dt id='yXSzh'><q id='yXSzh'><span id='yXSzh'><b id='yXSzh'><form id='yXSzh'><ins id='yXSzh'></ins><ul id='yXSzh'></ul><sub id='yXSzh'></sub></form><legend id='yXSzh'></legend><bdo id='yXSzh'><pre id='yXSzh'><center id='yXSzh'></center></pre></bdo></b><th id='yXSzh'></th></span></q></dt></tr></i><div id='yXSzh'><tfoot id='yXSzh'></tfoot><dl id='yXSzh'><fieldset id='yXSzh'></fieldset></dl></div>
                              <tbody id='yXSzh'></tbody>