c# - 从表单将值传递给用户控件
问题描述
我在我的 WFA(Windows 窗体应用程序)中创建了用户控件,我想从我的 to 传递值MainForm.cs
,UserControl.cs
但我不知道如何做到这一点。这是我想传递给UserControl.cs
public partial class MainForm : Form
{
private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (ProcOpen)
{
//THESE
int vlInt = m.ReadByte("base+007C1DAC,0x14,0x4");
int roomID = m.ReadByte("base+003CA150,0x0");
double diffValue = m.ReadDouble("base+007B4A3C,0x0,0x2c,0x10,0x7ec,0x300");
}
}
}
到
public partial class FirstCustomControl : UserControl
{
public FirstCustomControl()
{
InitializeComponent();
}
private void FirstCustomControl_Load(object sender, EventArgs e)
{
//GET THE VALUES HERE
}
}
解决方案
您可以为您的 UC 定义一个属性,然后从父级设置该属性;
public partial class FirstCustomControl : UserControl
{
public static dynamic vlInt;
public static dynamic roomID;
public static dynamic diff;
public FirstCustomControl()
{
InitializeComponent();
}
public void NotifyValueChanged(){
label1.text = vlInt.ToString();
label2.text = roomID.ToString();
label3.text = diff.ToString();
}
private void FirstCustomControl_Load(object sender, EventArgs e)
{
}
}
然后在你的 MainForm
public partial class MainForm : Form
{
private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (ProcOpen)
{
//THESE
FirstCustomControl.vlCount = m.ReadByte("base+007C1DAC,0x14,0x4");
FirstCustomControl.roomID = m.ReadByte("base+003CA150,0x0");
FirstCustomControl.diff = m.ReadDouble("base+007B4A3C,0x0,0x2c,0x10,0x7ec,0x300");
firstCustomControl1.NotifyValueChanged();
}
}
}
推荐阅读
- python - Python 简单测验程序 - 如何解决问题循环
- r - 如何从 R 中 PubMed 的数据框列表 MESH 列表中提取单词
- javascript - Javascript隐藏图片
- php - 如何解决“现有连接被远程主机强行关闭”的问题。从 Laravel 发送邮件时?
- google-apps-script - 通过 Google 脚本启用 Google 表格保护
- spring - @Async 和 @Transaction 方面顺序
- jquery - 如何在另一个元素之前找到第一个元素
- android - 如何将手机图库中的所有图像自动加载到 Android 中的图像滑块?
- c - 调用lua_resume时有没有办法避免阻塞?
- mysql - 如何获取订单计数子查询