Graphics.DrawRectangle Method (Pen, Rectangle)
msdn中 的例子
public void DrawRectangleRectangle(PaintEventArgs e)
{
// Create pen.
Pen blackPen = new Pen(Color.Black, 3);
// Create rectangle.
Rectangle rect = new Rectangle(0, 0, 200, 200);
// Draw rectangle to screen.
e.Graphics.DrawRectangle(blackPen, rect);
}
只要获取X,Y,宽度,和高度就能在 所需要的控件中绘制这个是在picturebox中绘制的
private void currentImgBox_Paint(object sender, PaintEventArgs e)
{
if (0 <= rectS.X && rectS.X < rectE.X &&
0 <= rectS.Y && rectS.Y < rectE.Y)
{
int xZoomed = (int)(rectS.X * zoomRatio + 0.5);
int yZoomed = (int)(rectS.Y * zoomRatio + 0.5);
int wZoomed = (int)((rectE.X - rectS.X) * zoomRatio);
int hZoomed = (int)((rectE.Y - rectS.Y) * zoomRatio);
e.Graphics.DrawRectangle(Pens.Black, xZoomed, yZoomed, wZoomed, hZoomed);
}
}
本文介绍如何在Windows Forms应用程序中利用Graphics类的DrawRectangle方法,结合Pen对象来绘制矩形。详细讲解了参数Pen和Rectangle的使用,帮助开发者实现自定义的矩形绘制功能。
3078

被折叠的 条评论
为什么被折叠?



