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

<tfoot id='AUIVh'></tfoot>
  • <legend id='AUIVh'><style id='AUIVh'><dir id='AUIVh'><q id='AUIVh'></q></dir></style></legend>

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

      1. 如何在 Visual C# 中更改另一个窗体上的文本框中的文本?

        How to change text in a textbox on another form in Visual C#?(如何在 Visual C# 中更改另一个窗体上的文本框中的文本?)
        <legend id='zKYo6'><style id='zKYo6'><dir id='zKYo6'><q id='zKYo6'></q></dir></style></legend>

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

              • <tfoot id='zKYo6'></tfoot>

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

                  <bdo id='zKYo6'></bdo><ul id='zKYo6'></ul>
                  本文介绍了如何在 Visual C# 中更改另一个窗体上的文本框中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Visual C# 中,当我单击一个按钮时,我想加载另一个表单.但在该表单加载之前,我想用一些文本填充文本框.我试图在显示表单之前输入一些命令来执行此操作,但我收到一条错误消息,指出文本框由于其保护级别而无法访问.

                  In Visual C# when I click a button, I want to load another form. But before that form loads, I want to fill the textboxes with some text. I tried to put some commands to do this before showing the form, but I get an error saying the textbox is inaccessible due to its protection level.

                  如何在显示之前在表单中设置文本框?

                  How can I set the textbox in a form before I show it?

                   private void button2_Click(object sender, EventArgs e)
                      {
                  
                          fixgame changeCards = new fixgame();
                          changeCards.p1c1val.text = "3";
                          changeCards.Show();
                  
                  
                      }
                  

                  推荐答案

                  在按钮单击事件处理程序中创建新表单时,实例化一个新表单对象,然后调用它的 show 方法.

                  When you create the new form in the button click event handler, you instantiate a new form object and then call its show method.

                  一旦有了表单对象,您还可以调用该类中存在的任何其他方法或属性,包括设置文本框值的属性.

                  Once you have the form object you can also call any other methods or properties that are present on that class, including a property that sets the value of the textbox.

                  因此,下面的代码向 Form2 类添加了一个属性,用于设置您的文本框(其中 textbox1 是您的文本框的名称).我更喜欢这种方法方法,而不是通过修改其访问修饰符使 TextBox 本身可见,因为它为您提供了更好的封装,确保您可以控制文本框的使用方式.

                  So, the code below adds a property to the Form2 class that sets your textbox (where textbox1 is the name of your textbox). I prefer this method method over making the TextBox itself visible by modifying its access modifier because it gives you better encapsulation, ensuring you have control over how the textbox is used.

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

                  在第一个表单的按钮单击事件中,您可以使用如下代码:

                  And in the button click event of the first form you can just have code like:

                  private void button1_Click(object sender, EventArgs e)
                  {
                      Form2 form2 = new Form2();
                      form2.TextBoxValue = "SomeValue";
                      form2.Show();
                  }
                  

                  这篇关于如何在 Visual C# 中更改另一个窗体上的文本框中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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# 纯数字文本框控件)

                          <tfoot id='8d8CY'></tfoot>

                            <tbody id='8d8CY'></tbody>

                            <bdo id='8d8CY'></bdo><ul id='8d8CY'></ul>
                          • <small id='8d8CY'></small><noframes id='8d8CY'>

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