在我的父表单上
int count;
private void timer1_Tick(object sender, EventArgs e)
{
counter.Text = "TOTAL: "+Convert.ToString(count);
time.Text = DateTime.Now.ToString("h:mm:ss tt");
date.Text = DateTime.Now.ToString("MMMM d, yyyy");
}
在我的孩子表格上,我有
int counter;
public void view()
{
//codes//codes//codes//
counter = pview.Rows.Count;
}
我想设置count = counter .. 我试过了
count = childform.counter;
但它没有用......
帮帮我。帮你。 -Lina Inverse
答案 0 :(得分:0)
如果您希望父表单访问子表单的某个变量,则必须在父表单中存储对子表单的引用。您的子表单也应该提供公共变量或方法以允许从外部访问它。
我们假设您正在运行MainForm
,这将显示ChildForm
:
public partial class MainForm
{
private ChildForm _childForm;
public void ShowChildForm()
{
_childForm = new ChildForm();
_childForm.Show();
}
public void ReadRowCount()
{
if (_childForm != null)
{
// Reading variable from child form
int rowCount = _childForm.RowCount;
}
}
}
public partial class ChildForm
{
public int RowCount { get; private set; }
}