【发布时间】:2015-11-22 05:49:40
【问题描述】:
我有一个可以放大和缩小的应用程序,唯一的问题是我想放大和缩小但专注于面板位置的当前中间位置,而不是使用鼠标位置
有什么想法吗?
private void panel1_Paint(object sender, PaintEventArgs e)
{
SolidBrush brushs = new SolidBrush(Color.White);
e.Graphics.Clip = new Region(new Rectangle(0, 0, Viewer.Width, Viewer.Height));
e.Graphics.FillRegion(brushs, e.Graphics.Clip);
Graphics g = e.Graphics;
g.TranslateTransform(_ImgX, _ImgY);
g.ScaleTransform(_Zoom, _Zoom);
g.SmoothingMode = SmoothingMode.AntiAlias;
SolidBrush myBrush = new SolidBrush(Color.Black);
Pen p = new Pen(Color.Red);
foreach (CircuitData.ResistorRow resistorRow in ResistorData.Resistor)
{
RectangleF rec = new RectangleF((float)(resistorRow.CenterX - resistorRow.Length/ 2), (float)(resistorRow.CenterY - resistorRow.Width/ 2), (float)resistorRow.Length, (float)resistorRow.Width);
float orientation = 360 - (float)resistorRow.Orientation;
PointF center = new PointF((float)resistorRow.CenterX, (float)resistorRow.CenterY);
PointF[] points = CreatePolygon(rec, center, orientation);
if (!Double.IsNaN(resistorRow.HiX) && !Double.IsNaN(resistorRow.HiY))
{
g.FillEllipse(myBrush, (float)resistorRow.HiX - 2 , (float)resistorRow.HiY - 2, 4, 4);
g.DrawLine(p, new PointF((float)resistorRow.HiX , (float)resistorRow.HiY ), center);
}
g.FillPolygon(myBrush, points);
}
}
更新 缩放功能,我知道这是错误的,但如果有人可以帮助我修复逻辑或更好的想法。
private void trackBar1_Scroll(object sender, EventArgs e)
{
float oldZoom = _Zoom;
_Zoom = zoomTrackPad.Value / 10f;
int x = Math.Abs(Viewer.Width / 2 );
int y = Math.Abs(Viewer.Height / 2 );
int oldImageX = (int)(x / oldZoom);
int oldImageY = (int)(y / oldZoom);
int newImageX = (int)(x / _Zoom);
int newImageY = (int)(y / _Zoom);
_ImgX = newImageX - oldImageX + _ImgX;
_ImgY = newImageY - oldImageY + _ImgY;
Viewer.Invalidate();
}
谢谢
【问题讨论】:
-
您说它正在放大鼠标坐标,但在您的代码中没有对这些坐标的引用,所以我想这段代码对于您的要求来说非常不完整
-
对不起我想说的是有很多关于如何用鼠标索引实现它的例子,但我只关心面板中间的固定位置。但我会用我目前写的更新代码
-
正在写回复,请稍候... XD