各位大侠:
小弟最近学习使用picturebox控件,画完图后,想实现缩放功能;
具体缩放要求为:鼠标框选目标区域,自动实现放大;右键点击返回原始大小。
有人说该用两个picturebox控件来实现;若是,我不懂第二个picturebox控件的位置,大小该怎么调整呢?
若不是,我该怎么来实现呢?
小弟尝试了几种方法,效果都不行。
还请懂行的大哥给个提示,或者代码更好了!
提示的话,最好烦请您把每一步都点明,不胜感激!
小弟最近学习使用picturebox控件,画完图后,想实现缩放功能;
具体缩放要求为:鼠标框选目标区域,自动实现放大;右键点击返回原始大小。
有人说该用两个picturebox控件来实现;若是,我不懂第二个picturebox控件的位置,大小该怎么调整呢?
若不是,我该怎么来实现呢?
小弟尝试了几种方法,效果都不行。
还请懂行的大哥给个提示,或者代码更好了!
提示的话,最好烦请您把每一步都点明,不胜感激!
解决方案 »
- ICSharpCode.SharpZipLib 判断压缩后的文件是否可用?
- InvokeMember("click"); 无效?
- c# DateGridView 中RowEnter事件使用错误?详情请进~
- ComboBox和Treeview绑定后设置成DropDownList后无法获取值
- treeview控件问题 !
- 请教关于DataGrid的一个问题,在线等...
- 请问怎样实现自己所调用的dll程序集文件(动态装载),调用完毕后可以将程序集文件清楚掉。不被程序锁定。
- 简单问题,高手请看看
- 如何将GRID的一列锁定使水平滚动时不移动?
- 如何在运行时候得到dll的路径
- asp.net 应用extjs的grid的问题
- 如何获取注册表中的键值
大小属性设置为 AutoScale
你是说设置为AutoSize模式吧?
能否麻烦说的详细点呢?比如两个picturebox分别怎么操作?什么作用?
其中,
DrawReversibleFrame:画选择框
l=... t=... : 计算当前选择影射到图像的坐标
this.Invalidate:刷新当前窗口
public partial class Form1 : Form
{
Bitmap bitmap = new Bitmap(@"c:\temp\penguins.jpg");
RectangleF sourceRectange;
Point lastMouseDown;
Point lastMouseMove;
public Form1()
{
InitializeComponent();
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.lastMouseDown = this.lastMouseMove = e.Location;
}
protected override void OnMouseMove(MouseEventArgs e)
{
if( !this.Capture) return;
DrawReversibleFrame();
lastMouseMove = e.Location;
DrawReversibleFrame();
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
float l = sourceRectange.Left + sourceRectange.Width * lastMouseDown.X / this.ClientRectangle.Width;
float t = sourceRectange.Top + sourceRectange.Height * lastMouseDown.Y / this.ClientRectangle.Height;
float r = sourceRectange.Left + sourceRectange.Width * e.X / this.ClientRectangle.Width;
float b = sourceRectange.Top + sourceRectange.Height * e.Y / this.ClientRectangle.Height;
sourceRectange = RectangleF.FromLTRB(l, t, r, b);
}
else
{
this.sourceRectange = new RectangleF(PointF.Empty, bitmap.Size);
}
DrawReversibleFrame();
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
if ( Math.Abs(sourceRectange.Width * sourceRectange.Height) < 1) sourceRectange = new RectangleF(PointF.Empty, bitmap.Size);
e.Graphics.DrawImage(bitmap, (RectangleF)ClientRectangle, sourceRectange, GraphicsUnit.Pixel);
}
private void DrawReversibleFrame()
{
Rectangle rect = this.RectangleToScreen(Rectangle.FromLTRB(lastMouseMove.X, lastMouseMove.Y, lastMouseDown.X, lastMouseDown.Y));
ControlPaint.DrawReversibleFrame(rect, Color.Cyan, FrameStyle.Dashed);
}
}