从单独的类更新了文本框 [英] Updated a Textbox from a separate class
问题描述
我知道这可能很简单,但我有一个C#表单,而
表单的类叫做sbaSynch。我有一个文本框名称txtServerName。
我正在创建一个操作XML函数的类,所以我在
项目中添加了一个类,它是'名为XmlApi()。
在XmlAPI()类中我有如下简单代码
XmlAPI()
{
string str =" Some Text";
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
}
我没有错误,但表格上的文字框没有显示
的文字分配给它。
-
kr**@n-sv.com
Network&软件集成
www.n-sv.com
I know this is probably simple but I have a C# form and the class for the
form is called sbaSynch. I have a textbox name txtServerName.
I''m creating a class to manipulate XML functions so I added a class to
project and it''s named XmlApi().
In the XmlAPI() class I have simple code as following
XmlAPI()
{
string str = "Some Text";
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
}
I get no errors but the text box on the form doesn''t display the text that
was assigned to it.
--
kr**@n-sv.com
Network & Software Integration
www.n-sv.com
推荐答案
kfrost,
你可以声明控件是公开的,然后,实例将是
从您的表格中暴露出来。然而,这是非常糟糕的设计。你应该公开一个允许你将文本传递给它的方法,然后
方法将设置文本(允许你不暴露控件)。
希望这会有所帮助。
-
- Nicholas Paldino [.NET / C#MVP]
- ca*******@caspershouse.com
kfrost < KR ** @ n-sv.com(donotspam)GT。在消息中写道
新闻:AC ********************************** @ microsof t.com ...
kfrost,
You can declare the control to be public, then, the instance will be
exposed from your form. However, this is pretty bad design. You should
expose a method which will allow you to pass the text into it, and then the
method will set the text (allowing you to not expose the control).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com
"kfrost" <kr**@n-sv.com.(donotspam)> wrote in message
news:AC**********************************@microsof t.com...
我知道这可能很简单,但我有一个C#表单,而
表单的类叫做sbaSynch。我有一个文本框名称txtServerName。
我正在创建一个操作XML函数的类,所以我在
项目中添加了一个类,它被命名为XmlApi()。
在XmlAPI()类中,我有简单的代码如下:
XmlAPI()
{
string str =" Some Text"
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
我没有错误但是表单上的文本框没有显示
分配给它的文字。
-
kr ** @ n-sv .com
网络&软件集成
www.n-sv.com
I know this is probably simple but I have a C# form and the class for the
form is called sbaSynch. I have a textbox name txtServerName.
I''m creating a class to manipulate XML functions so I added a class to
project and it''s named XmlApi().
In the XmlAPI() class I have simple code as following
XmlAPI()
{
string str = "Some Text";
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
}
I get no errors but the text box on the form doesn''t display the text that
was assigned to it.
--
kr**@n-sv.com
Network & Software Integration
www.n-sv.com
Hello Nicholas,
我过去曾写过的所有问题都是控制台
应用程序和东西我刚刚把我所有的功能写在一个班级。
当我在试验时,我发现当我在
中调用一个函数时
xmlapi,我可以通过文本框而且有效。我不确定那就像我要传递参考资料一样。
你说的是什么,如果是表格的话class是sbaSynch()和来自sbaSynch()我
调用XmlAPI()类中的函数,我应该有一个方法在
sbaSynch()可以从XmlAPI()类中调用的类,它会更新文本框吗?
这是最有效的方法吗?在课间拨打电话和
?
此外,将文本框传递给班级的潜在问题是什么?
下面我列出了XmlAPI()类错误。
它是XmlAPI()
{
GetXMLString(TextBox txtResults)
{
txtResults.Text =" some text"
}
}
在表单类中有一个名为txtResults的文本框
我执行以下操作
GetXMLString (txtResults);
这似乎工作正常。只是不确定是否存在继承问题我不知道这是什么?
-
kr ** @ n-sv.com
Network&软件集成
www.n-sv.com
Nicholas Paldino [.NET / C#MVP]"写道:
Hello Nicholas,
My problem everything I''ve ever written in the past has been console
applications and stuff and I''ve just written all my functions in one class.
While I was experimenting, I found that when I call a function in the
xmlapi, I could pass the textbox and that worked. I''m not sure that''s like C
to where I''m passing a reference.
What you are saying, if the form class is sbaSynch() and from sbaSynch() I
make a call to a function in the XmlAPI() class, I should have a method in
the sbaSynch() class that can be called from the XmlAPI() class that would
update the textbox?
Would that be the most efficient way of doing this? Making calls back and
forth between classes?
Also, what are the potential problems of passing the textbox''s to the class?
Below I listed the XmlAPI() class wrong.
It''s XmlAPI()
{
GetXMLString(TextBox txtResults)
{
txtResults.Text = "some text"
}
}
In the form class there is a textbox named txtResults
I do the following
GetXMLString(txtResults);
This appears to work fine. Just not sure if there are inherit problems I''m
not aware of?
--
kr**@n-sv.com
Network & Software Integration
www.n-sv.com
"Nicholas Paldino [.NET/C# MVP]" wrote:
kfrost,
你可以声明控件是公开的,然后,实例将从你的表单中公开。然而,这是非常糟糕的设计。你应该公开一个允许你将文本传递给它的方法,然后
方法将设置文本(允许你不暴露控件)。
希望这会有所帮助。
-
- Nicholas Paldino [.NET / C#MVP]
- ca ******* @ caspershouse.com
kfrost < KR ** @ n-sv.com(donotspam)GT。在消息中写道
新闻:AC ********************************** @ microsof t.com。 ..
kfrost,
You can declare the control to be public, then, the instance will be
exposed from your form. However, this is pretty bad design. You should
expose a method which will allow you to pass the text into it, and then the
method will set the text (allowing you to not expose the control).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com
"kfrost" <kr**@n-sv.com.(donotspam)> wrote in message
news:AC**********************************@microsof t.com...
我知道这可能很简单,但我有一个C#表单,而
表单的类叫做sbaSynch。我有一个文本框名称txtServerName。
我正在创建一个操作XML函数的类,所以我在
项目中添加了一个类,它被命名为XmlApi()。
在XmlAPI()类中,我有简单的代码如下:
XmlAPI()
{
string str =" Some Text"
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
我没有错误但是表单上的文本框没有显示
分配给它的文字。
-
kr ** @ n-sv .com
网络&软件集成
www.n-sv.com
I know this is probably simple but I have a C# form and the class for the
form is called sbaSynch. I have a textbox name txtServerName.
I''m creating a class to manipulate XML functions so I added a class to
project and it''s named XmlApi().
In the XmlAPI() class I have simple code as following
XmlAPI()
{
string str = "Some Text";
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
}
I get no errors but the text box on the form doesn''t display the text that
was assigned to it.
--
kr**@n-sv.com
Network & Software Integration
www.n-sv.com
PS Nicolas,我一直在做很多事情,而且我在sbaSynch()类中有一个
方法试图更新文本框但是它没有
也在工作。我已经考虑过创建一个代表,但仍然没有工作。
我唯一能做的就是路过函数的文本框
我在单独的课程中打电话让它一直工作。
如上所述,我不知道这样做有什么问题吗?
-
kr ** @ n-sv .com
Network&软件集成
www.n-sv.com
kfrost写道:
P.S. Nicolas, I''ve been ramping up on a lot of things, and I do have a
method in the sbaSynch() class trying to update the textbox''s but it wasn''t
working either. I''ve looked into creating a delegate but still wasn''t
working either.
The only thing I''ve gotten to work is passing the textbox to the function
I''m calling in the separate class to get it to work consistently.
As mentioned, I don''t know of any problems with doing this?
--
kr**@n-sv.com
Network & Software Integration
www.n-sv.com
"kfrost" wrote:
我知道这可能很简单,但我有一个C#表单,而
表单的类叫做sbaSynch。我有一个文本框名称txtServerName。
我正在创建一个操作XML函数的类,所以我在
项目中添加了一个类,它被命名为XmlApi()。
在XmlAPI()类中,我有简单的代码如下:
XmlAPI()
{
string str =" Some Text"
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
我没有错误但是表单上的文本框没有显示
分配给它的文字。
-
kr ** @ n-sv .com
网络&软件集成
www.n-sv.com
I know this is probably simple but I have a C# form and the class for the
form is called sbaSynch. I have a textbox name txtServerName.
I''m creating a class to manipulate XML functions so I added a class to
project and it''s named XmlApi().
In the XmlAPI() class I have simple code as following
XmlAPI()
{
string str = "Some Text";
sbaSynch sbas = new sbaSynch();
sbas.txtServerName.Text = str;
}
I get no errors but the text box on the form doesn''t display the text that
was assigned to it.
--
kr**@n-sv.com
Network & Software Integration
www.n-sv.com
这篇关于从单独的类更新了文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!