所以,直核缺谨接响应对话框的扮巧WM_VSCROLL和WM_HSCROLL消息就可以了
若对话框中有多个滚动条,则可以用WM_VSCROLL和WM_HSCROLL消息响应函数中的参数CScrollBar*
pScrollBar来进行判断
试试下面这代码,细节方面自己改改private Point pt = Point.Empty// 记录鼠标按下时的坐标
private Point def = Point.Empty// 记录鼠标按下panel横纵滚动条的值
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (MouseButtons.Left != e.Button) return
Cursor = Cursors.SizeAll
pt = panel1.PointToClient(pictureBox1.PointToScreen(e.Location))// 鼠标是按在picturebox上,需要转化成相对于panel的坐标
def.X = panel1.HorizontalScroll.Value//歼清拦 HScroll值
def.Y = panel1.VerticalScroll.Value// VScroll值
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (MouseButtons.Left != e.Button) return
Point cur = panel1.PointToClient(pictureBox1.PointToScreen(e.Location))// 当前氏胡鼠标坐标,同样需要转化成相对于panel的坐标
cur = new Point(pt.X - cur.X, pt.Y - cur.Y)/正嫌/ 计算差
cur.X = def.X + cur.X// 计算和
cur.Y = def.Y + cur.Y
if (0 >cur.X) cur.X = 0 // 如果超出范围,需要修正
if (panel1.Width <cur.X) cur.X = panel1.Width
if (0 >cur.Y) cur.Y = 0
if (panel1.Height <cur.Y) cur.Y = panel1.Height
if (panel1.HorizontalScroll.Visible) panel1.HorizontalScroll.Value = cur.X // 如果存在对应的滚动条,则赋值
if (panel1.VerticalScroll.Visible) panel1.VerticalScroll.Value = cur.Y
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
Cursor = Cursors.Default
}
你的意思就是滚动条滚动的时候不执行你的代码,滚动完了,鼠标键up了才执行代衫袜橘码,可以或团这样:在滚好喊动条事件中,例如form的滚动条:
private void Form1_Scroll(object sender, ScrollEventArgs e)
{
if(e.Type != ScrollEventType.ThumbTrack)
MessageBox.Show("aa")
}
就可以了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)