滚动面板时固定十个分量的控制地位 [英] Mantain a control position fixed when scrolling a panel
本文介绍了滚动面板时固定十个分量的控制地位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大的自定义面板的是Panel2 的是滚动在父面板的 PANEL1 的左边中间一个标签的卷标1 的。
我的保持的卷标1 的始终是是Panel2的可见光左中间,滚动时也是如此。
在真实的例子,我的面板是用户控件的生成的在其左侧的一些标签。该小组卷轴,但我需要保持标签总是可见的。
怎么可能实现?
这是我的code:
公共部分类Form1中:形态
{
公共Form1中()
{
this.InitializeComponent();
}
保护点clickPosition;
保护点的scrollPosition;
私人无效panel2_MouseDown(对象发件人,发送MouseEventArgs E)
{
this.clickPosition = e.Location;
}
私人无效panel2_MouseMove(对象发件人,发送MouseEventArgs E)
{
如果(e.Button == MouseButtons.Left)
{
this.SuspendLayout();
this.scrollPosition + =(尺寸)clickPosition - (尺寸)e.Location;
this.panel1.AutoScrollPosition =则scrollPosition;
this.ResumeLayout(假);
}
}
}
解决方案
公共Form1中()
{
this.InitializeComponent();
panel2.Paint + =新PaintEventHandler(panel2_Paint);
}
无效panel2_Paint(对象发件人,PaintEventArgs的E)
{
label1.Location =
新点(-panel1.AutoScrollPosition.X,label1.Location.Y);
}
I have a label label1 in the middle left of a large custom panel panel2 that is scrolled in a parent panel panel1.
I would keep the label1 always in the visible left middle of the panel2, even when scrolling.
In the real example, my panel is a user control that generates the some labels in its left side. The panel scrolls, but I need to keep the labels always visible.
How could it be achieved?
this is my code:
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);
}
}
}
解决方案
public Form1()
{
this.InitializeComponent();
panel2.Paint += new PaintEventHandler(panel2_Paint);
}
void panel2_Paint(object sender, PaintEventArgs e)
{
label1.Location =
new Point(-panel1.AutoScrollPosition.X, label1.Location.Y);
}
这篇关于滚动面板时固定十个分量的控制地位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文