如何将控件值从Windows窗体传递到类 [英] How to pass controls value from windows form to class
本文介绍了如何将控件值从Windows窗体传递到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Helloo ..
我在形式上用组合框,我想在类中动态获取组合框选择的值
我要做的是
我在课堂上写了以下代码..
Helloo..
I''v combobox in form, dynamically i wanna get combobox selected value in class
What I''v done is
I wrote the following code in class..
using experiments;
experiments.Form1 formvalue=new experiments.Form1();
但是无法通过"formvalue"对象获取值
您可以帮我吗?
But unable to get the value through "formvalue" object
Can u help me?
推荐答案
将combobox修饰符更改为public,您应该可以通过以下方式访问它:formvalue.combobox1.SelectedValue
.
Change the combobox modifier to public and the you should be able to access it like this: formvalue.combobox1.SelectedValue
.
请使用:
experiments.Form1 formvalue=new experiments.Form1();
string cbValue = string.Empty;
if(formvalue.cbLoginCompany.SelectedValue != null)
{
cbValue = formvalue.cbLoginCompany.SelectedValue.ToString();
}
在构造函数中初始化.
解决方案:字段初始化程序无法引用非静态字段,方法或属性 [
Initialize in the constructor.
Solution : A field initializer cannot reference the nonstatic field, method, or property[^]
read ps2goat''s 2nd reply.
这篇关于如何将控件值从Windows窗体传递到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文