在WinForms(最好的C#)中,我怎么能做一个简单的"缩放"工具在光标位置下方显示矩形视图?理想情况下,只放大控件(按钮,标签......)
虽然,首先,这可能与标准库(.dll)有关吗?我是处理图形的新手...
提前致谢!
编辑:此问题/答案(Zoom a Rectangle in .NET)对待缩放图像,而不是输入控件。我只是想放大控件。
Edit2:通过每个控件的MouseEnter事件,我定位一个面板,该面板应该包含放大的控件图像。我只在正确的网站上获得了这个小组......
private void anyControl_MouseEnter(object sender, EventArgs e)
{
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
//Create the Graphic Variable with screen Dimensions
Graphics graphics = Graphics.FromImage(printscreen as Image);
//Copy Image from the screen
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
Control auxControl = (Control) sender;
panel.Width = auxControl + 20;
panel.Height = auxControl + 20;
panel.Location = new Point (auxControl.Location.X - 10, auxControl.Location.Y - 10);
control.DrawToBitmap(printscreen, panel.Bounds)
}
答案 0 :(得分:1)
您可以使用此代码从屏幕上获取图片(感谢http://www.codeproject.com/Articles/485883/Create-your-own-Snipping-Tool):
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
//Create the Graphic Variable with screen Dimensions
Graphics graphics = Graphics.FromImage(printscreen as Image);
//Copy Image from the screen
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
所以使用此链接和您分享的链接应该排序
如果您不热衷于捕获屏幕部分,请使用表单的DrawToBitmap方法(感谢Capture screenshot of only a section of a form?)
答案 1 :(得分:0)
使用以下代码我解决了我的问题,但最终的图像有些模糊......(我"缩放"图像为20%)
private void anyControl_MouseEnter(object sender, EventArgs e)
{
Control auxControl = (Control) sender;
int enlargedWidth = (int) Math.Round(auxControl.Width * 1.20);
int enlargedHeight = (int) Math.Round(auxControl.Height * 1.20);
panel.Width = enlargedWidth;
panel.Height = enlargedHeight;
panel.Location = new Point (auxControl.Location.X - (int) Math.Round(auxControl.Width * 0.10), auxControl.Location.Y - (int) Math.Round(auxControl.Height * 0.10));
Bitmap aBitmap = new System.Drawing.Bitmap(auxControl.Width, auxControl.Height);
auxControl.DrawToBitmap(aBitmap, auxControl.ClientRectangle);
Bitmap aZoomBitmap = ZoomImage(aBitmap, panel.Bounds);
panel.ContentImage = aZoomBitmap;
panel.Visible = true;
}
private Bitmap ZoomImage(Bitmap pBmp, Rectangle pDestineRectangle)
{
Bitmap aBmpZoom = new Bitmap(pDestineRectangle.Width, pDestineRectangle.Height);
Graphics g = Graphics.FromImage(aBmpZoom);
Rectangle srcRect = new Rectangle(0, 0, pBmp.Width, pBmp.Height);
Rectangle dstRect = new Rectangle(0, 0, aBmpZoom.Width, aBmpZoom.Height);
g.DrawImage(pBmp, dstRect, srcRect, GraphicsUnit.Pixel);
return aBmpZoom;
}