【发布时间】:2009-12-24 11:25:32
【问题描述】:
我在父面板 panel1 中滚动的大型自定义面板 panel2 的左中部有一个标签 label1。 p>
alt text http://lh4.ggpht.com/_1TPOP7DzY1E/SzNN2g9Sv4I/AAAAAAAAC1U/A_LlLOoejX8/s800/formScroll.png
我会将 label1 始终保持在 panel2 的可见左侧中间,即使在滚动时也是如此。
在实际示例中,我的面板是一个用户控件,在其左侧生成一些标签。面板滚动,但我需要保持标签始终可见。
如何实现?
这是我的代码:
public partial class Form1 : Form
{
public Form1()
{
this.InitializeComponent();
}
protected Point clickPosition;
protected Point scrollPosition;
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
this.clickPosition = e.Location;
}
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.SuspendLayout();
this.scrollPosition += (Size)clickPosition - (Size)e.Location;
this.panel1.AutoScrollPosition = scrollPosition;
this.ResumeLayout(false);
}
}
}
【问题讨论】:
标签: .net winforms .net-2.0 scroll