如题所示标题,想同时表达两个意思:1:缩放平移绘制区域,2:创建模板匹配区域并保存。被一个技术问题卡住折腾了近大半天时间+熬夜2个小时,经过不懈努力,反复验证各参数意义,找到了问题的原因,终于攻克难题。分享给需要的朋友。效果如下:
思路如下:
首先鼠标滚轮缩放,按压鼠标左键平移的鼠标事件组合:MouseDown,MouseUp,MouseMove,MouseWheelEvent,
具体为:void AddEvent()
{
hWindowControl2.HMouseWheel += HWindowControl1_HMouseWheel;
hWindowControl2.HMouseMove += HWindowControl1_HMouseMove;
hWindowControl2.HMouseDown += HWindowControl1_HMouseDown;
hWindowControl2.HMouseUp += HWindowControl1_HMouseUp;
hWindowControl2.MouseLeave += HWindowControl1_MouseLeave;
}
MouseDown记录鼠标点击的起始位置:bool mousePressed = false;
Point startPoint = Point.Empty;
private void HWindowControl1_HMouseDown(object sender, HMouseEventArgs e)
{
mousePressed = true;
startPoint = new Point((int)e.X, (int)e.Y);
this.hWindowControl1.Cursor = Cursors.SizeAll;
}MouseMove 平移:注意关键之处,每次移动后的步进位置,需要重新给startPoint赋值,此处调试一下代码就知道如何写了。
另外一点是每次平移后把最新的平移旋转矩阵 out 参数出来,供下次作为新参数传递进去重新计算;private void HWindowControl1_HMouseMove(object sender, HMouseEventArgs e)
{
if (hMatrix == null || !mousePressed) return;
HTuple hv_Matrix = null;
double x = e.X - startPoint.X;
double y =