简体   繁体   English

如何通过调用方法将 multiple.text 值更改为“”?

[英]How can I change multiple .text values to “”, through calling a method?

I m trying to make a method and call it everytime I want my textboxes to go blank in my form.我正在尝试创建一个方法并在每次我希望我的文本框在我的表单中为 go 空白时调用它。

The code I ve tried is listed below我尝试过的代码如下所示

In the main(form) code:在主(表单)代码中:

 _BlankSpaces.NineBlankTextboxes( ref txtSup.Text, ref txtSupName.Text, ref txtSupCode.Text, ref txtZenonName.Text, ref txtZenonCode.Text, ref txtInAmount.Text, ref Combo_Mech_El.Text, ref txtDescr.Text, ref txtID.Text);

                    /*   Instead of:
                    txtSup.Text = "";
                    txtSupName.Text = "";
                    txtSupCode.Text = "";
                    txtZenonName.Text = "";
                    txtZenonCode.Text = "";
                    txtInAmount.Text = "";
                    Combo_Mech_El.Text = "";
                    txtDescr.Text = "";
                    txtID.Text = ""; */

                    //And In the Class I call:

namespace WarehouseManagementToolv1.Secondary
{
    public class BlankSpaces
    {

        //public string Blank1, Blank2, Blank3, Blank4, Blank5, Blank6, Blank7, Blank8, Blank9;

        public void NineBlankTextboxes(ref string blank1, ref string blank2, ref string blank3, ref string blank4,
            ref string blank5, ref string blank6, ref string blank7, ref string blank8, ref string blank9)
        {
            blank1 = "";
            blank2 = "";
            blank3 = "";
            blank4 = "";
            blank5 = "";
            blank6 = "";
            blank7 = "";
            blank8 = "";
            blank9 = "";

        }

    }
}

When I run it the massage I get is:当我运行它时,我得到的按摩是:

A property or indexer may not be passed as an out or ref parameter属性或索引器不能作为 out 或 ref 参数传递

Property "Text" access returns temporary value.属性“文本”访问返回临时值。 "ref" argument must be an assignable variable, field or an array element. “ref”参数必须是可赋值的变量、字段或数组元素。

this is only possible with jquery or css selectors (web app), for C# (desktop app) this is not possible, you should clear your text using yourtext.Text = string.Empty, or by binding a property and set it to empty each time you want to.这仅适用于 jquery 或 css 选择器(网络应用程序),对于 C# (桌面应用程序)这是不可能的,您应该清除您的文本,或通过使用属性为空的文本来设置它。你想要的时间。

You could try something like你可以尝试类似的东西

private void ClearTextBoxes(params TextBox[] list)
{
    foreach(TextBox tb in list)
    {
        tb.Text = "";
    }
}

This would be used as这将用作

ClearTextBoxes(txtSup, txtSupName, txtSupCode); // TODO : Add any other textboxes

This sidesteps the issue of trying to send a reference copy of a property and sends the object itself to allow it to be cleared.这回避了尝试发送属性的参考副本并发送 object 本身以使其被清除的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取调用方法的参数值? - How can I get the values of the parameters of a calling method? 如何通过将myLable1.Text调用为变量来更改它 - How can I change myLable1.Text by calling it as a variable 调用具有多个默认值的方法 - calling a method with multiple default values 如何通过调用 Blazor 中的另一个组件方法来更改按钮文本 - How to change Button Text by calling another component method in Blazor 如何通过ajax调用的c#函数更改asp标签的文本 - How can I change the text of asp label through c# function which is called by ajax 如何循环遍历多个数组? - How can I loop through multiple arrays? 是否可以创建一个字典,其中的值可以具有多种数据类型? (另外我如何遍历一个数组作为我的值之一) - Is it possible to create a dictionary in which values can have multiple data types? (Also how do I iterate through an array as one of my values) 如何更改事件分配的方法? - How can I change a method assigned on an event? 如何使用一种方法将字符串的多种不同类型的日期值转换为datetime? - How can I convert date values from the multiple different types that are string to datetime with one method? 我如何使用Moles为C#中的一个方法的多次调用返回不同的值? - How can I use Moles to return different values for multiple calls to a method in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM