c#Winfrom 当滚动条滚动的时候加载数据
我想实现当窗体加载的时候,窗体上就加载20条数据,当用户滚动滚动条的时候再加载其他数据,该怎么实现,不能用分页
程序代码:using using using System.Text;
using System.Windows.Forms;
namespace WinformInfinitiScroll
{
public partial class FormMain : Form
{
#region 只读全局字段
private readonly StreamReader _sr;
#endregion
#region 构造函数
public FormMain()
{
InitializeComponent();
_sr = new StreamReader("Content.txt", Encoding.Default);
for (var i = 0; i < 20; i++)
{
var line = _sr.ReadLine();
if (string.IsNullOrWhiteSpace(line)) break;
var label = new Label {Text = line};
Tlp.RowCount++;
Tlp.Controls.Add(label);
}
Tlp.Scroll += Tlp_Scroll;
Closing += FormMain_Closing;
}
#endregion
#region 控件事件
void FormMain_Closing(object sender, CancelEventArgs e)
{
_sr.Close();
}
void Tlp_Scroll(object sender, ScrollEventArgs e)
{
if (e.NewValue + Tlp.VerticalScroll.LargeChange < Tlp.VerticalScroll.Maximum) return;
var line = _sr.ReadLine();
if (string.IsNullOrWhiteSpace(line))
{
Tlp.Scroll -= Tlp_Scroll;
MessageBox.Show("已经是最后一项数据了。");
return;
}
var label = new Label { Text = line };
Tlp.Controls.Add(label);
Tlp.ScrollControlIntoView(label);
}
#endregion
}
}