【发布时间】:2020-04-03 21:57:04
【问题描述】:
一段时间以来,我一直在尝试让两种表单相互共享数据。在这种情况下,将数据从表单 2 继承到 1。我尝试了几种方法,这种方法是我设法实现的最好的方法。
问题是它没有完成工作,第二种形式得到的值总是0,肯定是一个小细节,但我真的不知道如何结束。
非常感谢任何帮助的尝试:)
Form1:
using System;
using ...;
namespace Name
{
public partial class Form1 : Form
{
cntr val = new cntr();
}
/// omited code that modifies val.count
public class cntr
{
public int count_ = 0;
public int count
{
get
{
return count_;
}
set
{
count_ = value;
}
}
}
}
Form2:
using System;
using ...;
namespace Name
{
public partial class Form2 : Form
{
cntr aye = new cntr();
public Form2()
{
InitializeComponent();
}
private async void Read()
{
while (true) /// updating the .Text every 5 seconds
{
Box2.Text = aye.count;
await Task.Delay(500);
}
}
}
}
【问题讨论】:
标签: c# winforms class inheritance