请问在c#中如何画出圆角矩形?谢谢

wovow 2004-07-23 02:35:55
如题
...全文
820 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wovow 2004-08-04
  • 打赏
  • 举报
回复
Thank u ,BearRui
i get it,that's just what i fond
BearRui 2004-07-30
  • 打赏
  • 举报
回复

Setting the control region
Everybody who used Windows XP has very probably noticed that buttons have rounded corners. The graphic shape of the button looks like this:

So, we'll create such a region (the interior of a graphics shape) for our button.

int X = this.Width;
int Y = this.Height;
Point[] points = { new Point(1, 0),
new Point(X-1, 0),
new Point(X-1, 1),
new Point(X, 1),
new Point(X, Y-1),
new Point(X-1, Y-1),
new Point(X-1, Y),
new Point(1, Y),
new Point(1, Y-1),
new Point(0, Y-1),
new Point(0, 1),
new Point(1, 1)}
GraphicsPath path = new GraphicsPath();
path.AddLines(points);
this.Region = new Region(path);
yuxiaodong790909 2004-07-30
  • 打赏
  • 举报
回复
可以使用API
wovow 2004-07-30
  • 打赏
  • 举报
回复
谢谢
可在CSDN中写着:
GDI 提供几种用于创建区域的函数:CreateRectRgn、CreateEllpticRgn、CreateRoundRectRgn、CreatePolygonRgn 和 CreatePolyPolygonRgn。您或许希望 GDI+ 中的 Region 类也有类似的构造函数,将矩形、椭圆、圆角矩形和多边形作为参数接收,但事实并非如此。GDI+ 中的 Region 类提供一个接收 Rectangle 对象的构造函数和另一个接收 GraphicsPath 对象的构造函数。如果您想基于椭圆、圆角矩形或多边形构造区域,可以通过创建一个 GraphicsPath 对象(例如包含椭圆的对象),然后将其传递至 Region 构造函数来轻松实现。
我想知道这里说的使用GraphicsPath就是用
GraphicsPath.gp.AddLine
GraphicsPath.gp.AddArc
吗?
如果这样那还是用API好了。
mastercy 2004-07-23
  • 打赏
  • 举报
回复
[DllImport("gdi32.Dll")]
public static extern int CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
athossmth 2004-07-23
  • 打赏
  • 举报
回复
public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)

{

GraphicsPath gp=new GraphicsPath();

gp.AddLine(X + radius, Y, X + width - (radius*2), Y);

gp.AddArc(X + width - (radius*2), Y, radius*2, radius*2, 270, 90);

gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius*2));

gp.AddArc(X + width - (radius*2), Y + height - (radius*2), radius*2, radius*2,0,90);

gp.AddLine(X + width - (radius*2), Y + height, X + radius, Y + height);

gp.AddArc(X, Y + height - (radius*2), radius*2, radius*2, 90, 90);

gp.AddLine(X, Y + height - (radius*2), X, Y + radius);

gp.AddArc(X, Y, radius*2, radius*2, 180, 90);

gp.CloseFigure();

g.DrawPath(p, gp);
gp.Dispose();
}

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧