フォーム上に 2 つPanel
のオブジェクトが並んでいます。最初のパネルをスクロールすると、もう一方のパネルもまったく同じ量だけスクロールします。
このようなもの。
private void Panel1_Scroll(object sender, ScrollEventArgs e)
{
Panel2.ScrollPosition() = Panel1.ScrollPosition();
}
私はscottmに同意しますが、違いを生む何かを追加します:
private void ScorePanel_Scroll(object sender, ScrollEventArgs e)
{
var senderPanel = sender as Panel;
if (senderPanel == null)
{
// Might want to print to debug or mbox something, because this shouldn't happen.
return;
}
var otherPanel = senderPanel == Panel1 ? Panel2 : Panel1;
otherPanel.VerticalScroll.Value = senderPanel.VerticalScroll.Value;
}
別の方法では、常に Panel1 を Panel2 のスクロール オフセットに更新するため、Panel2 をスクロールしても、実際には何もスクロールしません。
このメソッドを取得したので、次のように両方のパネルをサブスクライブする必要があります。
Panel1.Scroll += ScorePanel_Scroll;
Panel2.Scroll += ScorePanel_Scroll;
これはおそらく、パネルを含むフォームの ctor で行うのが最適です。
かなり近いです、これはあなたのために働くはずです:
private void ScorePanel_Scroll(object sender, ScrollEventArgs e)
{
Panel1.VerticalScroll.Value = Panel2.VerticalScroll.Value;
}
MSDN を読むと、これらの状況で常に役立ちます。