[英]How to assign class property to point on Windows form variable
I have class KeyWordsManager 我有KeyWordsManager类
public class KeyWordsManager
{
public Designation designation { get; set; }
public KeyWordsManager(ref Designation design)
{
this.designation=design;
}
}
And i have my windows form which have "global variable designation" 而且我的Windows表单具有“全局变量名称”
public partial class NewJob : Form
{
//some code
private Designation newJobDesignation=new Designation();
private void NewJob_Load(object sender, EventArgs e)
{
KeyWordsManager manager = new KeyWordsManager(ref newJobDesignation);
}
}
The problem is when i want to modify newJobDesignation variable in my form, and when i try to set value to some textbox from KeyWordsManager class, it isnt changed , as if it doesnt reference to object in form class. 问题是当我想修改表单中的newJobDesignation变量时,以及当我尝试将值设置为KeyWordsManager类中的某些文本框时,它没有更改,就好像它没有引用表单类中的对象一样。
I have same scheme but instead of my custom Designation class i used ComboBox and is working well. 我有相同的方案,但我使用了ComboBox而不是自定义的Designation类,并且运行良好。
Does someone know what is the problem? 有人知道这是什么问题吗? I though ref keyword would solve the problem but it didnt.
我虽然ref关键字可以解决问题,但事实并非如此。 Did i reference it good or maybe there is problem outside this part of code
我是否引用得很好,或者这部分代码之外是否存在问题
I'm not completely sure of what you are trying to do, but the following function creates a new local KeyWordsManager that goes out of scope (eventually garbage collected) when the function exits. 我不确定您要做什么,但是以下函数创建了一个新的本地KeyWordsManager,当该函数退出时,它超出了范围(最终被垃圾回收)。
private void NewJob_Load(object sender, EventArgs e)
{
KeyWordsManager manager = new KeyWordsManager(ref newJobDesignation);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.