1
我有一个图片框。 在图片框我使用画线:如何在GDI中移动缩放线+
gfx.DrawLine(nPen, line.xBegin, line.yBegin, line.xEnd, line.yEnd);
line
是包含开头的行值和结束值的对象。
我在那个图片框上绘制10行。 我MOUSE_WHEEL监听器包含代码:
gfx.TranslateTransform((panelpreview.Width)/2, (panelpreview.Height)/2);
gfx.ScaleTransform(imageScale, imageScale);
gfx.TranslateTransform(-(panelpreview.Width)/2, -(panelpreview.Height)/2);
目前我试图通过移动线:
private void panelPreview_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
checkLinesIntersection(e.Location); //checks if e.Location intersects with the line
panelPreview.MouseUp += new MouseEventHandler(panelPreview_MouseUpLine);
panelPreview.MouseMove += new MouseEventHandler(panelPreview_MouseMoveLine);
}
}
void panelPreview_MouseMoveLine(object sender, MouseEventArgs e)
{
if (_Leading.movable)
newFont.Leading = e.Y - (_base.yBegin + newFont._descenderHeight);
if (_xHeight.movable)
if (_base.yBegin - e.Y >= 0)
newFont.xHeight = _base.yBegin - e.Y;
if (_capHeight.movable)
if (_base.yBegin - e.Y >= 0)
newFont.capHeight = _base.yBegin - e.Y;
if (_ascenderHeight.movable)
if (_base.yBegin - e.Y >= 0)
newFont.ascenderHeight = _base.yBegin - e.Y;
if (_descenderHeight.movable)
if (e.Y - _base.yBegin >= 0)
newFont.descenderHeight = e.Y - _base.yBegin;
UpdatePreviewWindow();
}
void panelPreview_MouseUpLine(object sender, MouseEventArgs e)
{
panelPreview.MouseMove -= new MouseEventHandler(panelPreview_MouseMoveLine);
panelPreview.MouseUp -= new MouseEventHandler(panelPreview_MouseUpLine);
}
的问题是,上线的,即使在视觉上我按缩放后的未反应的它应该的方式。
public void checkLinesIntersection(Point mouseLocation)
{
lineIntersects(_Leading, mouseLocation);
lineIntersects(_xHeight, mouseLocation);
}
private void lineIntersects(nLine line, Point mouseLocation)
{
if (mouseLocation.X >= line.xBegin && mouseLocation.X <= line.xEnd)
if (mouseLocation.Y >= line.yBegin || mouseLocation.Y + 2 >= line.yBegin)
if (mouseLocation.Y <= line.yEnd || mouseLocation.Y - 2 <= line.yEnd)
switch (line.sName)
{
case "xHeight":
newFont.selectedLine = nFont.Lines._xHeight;
break;
default:
break;
}
}
我的水晶球看不到checkLinesIntersection() – 2011-12-14 12:47:19