c# - 在 c# 的不同类中检索最新的控件值(复选框、日期时间选择器)
问题描述
我想使用名为 GetProfileFilter 的函数访问最新的检查状态和最新的设置日期值。现在我的问题是,当 checkbox.Checkstate 更改或 datetimepicker 更改时,我无法获取最新值。我根据是否设置了复选框来设置值,并且我打算在其他地方使用 IBitWise 值.注意,在表单加载时,所有复选框都被选中。在表单类中,我只有几个变量以及按钮和复选框的事件处理程序以及日期时间选择器。向所有建议开放!
class Profile{
public bool GetProfileFilter()
{
if (frmInactive.btnApplyWasClicked == true || frmInactive.btnCancelWasClicked == false)
{
frmInactive.ShowDialog();
MessageBox.Show("Here");
if (frmInactive.chkCancel.Checked == true)
{
MessageBox.Show("Cancel");
IBitWise += Canceled;
}
if (frmInactive.chkDiscon.Checked == true)
{
MessageBox.Show("Discon");
IBitWise += Discontinued;
}
if (frmInactive.chkVoidwoRes.Checked == true)
{
MessageBox.Show("Voidedwo");
IBitWise += VoidedWoutRes;
}
if (frmInactive.chkVoidwRes.Checked == true)
{
MessageBox.Show("Voidedw");
IBitWise += VoidedWRes;
}
MessageBox.Show("Ibit value:" + IBitWise);
return true;
}
else
{
return false;
}
}
}
public partial class FilterView : Form
{
Utilities Utilities = new Utilities();
//FilterView filterView = new FilterView();
public FilterView()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
}
private void rsetbtn_Click(object sender, EventArgs e)
{
}
private void aplybtn_Click(object sender, EventArgs e)
{
callonload();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
}
解决方案
这是带有公开复选框的示例代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Profile profile = new Profile(this);
profile.GetProfileFilter();
}
}
class Profile
{
Form1 form1;
public Profile(Form1 form1)
{
this.form1 = form1;
}
public bool GetProfileFilter()
{
form1.checkBox1.Checked = true;
return true;
}
}
}
推荐阅读
- javascript - React Native:何时应该在构造函数与 componentDidMount 中调用函数
- python - Split the data frame based on consecutive row values differences
- javascript - 如何访问被锚和循环语句按住的网页
- javascript - 使用 Javascript AddIn 在 OneNote 中插入打印输出
- python - 多个 DF 列的 Sumproduct
- python - 命令被标记为无效
- javascript - 更改 highchart 网络图中每个链接的长度
- python - 如何显示()地理图?
- algorithm - 解决问题的动态规划技术
- javascript - 中的默认选项