Hello.
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);
}
}
}