[英]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.