GDI+繪制圓角矩形


1. 生成圓角矩形路徑對象。

   1) 創建CGraphicsRoundRectPath對象objRoundPath。

   2) objRoundPath調用添加圓角矩形路徑的函數AddRoundRect。

2. 使用Graphic::DrawPath繪制圓角矩形。

CGraphicsRoundRectPath的頭文件:

1 class CGraphicsRoundRectPath: public Gdiplus::GraphicsPath
2 {
3 public:
4     CGraphicsRoundRectPath();
5     CGraphicsRoundRectPath(INT x, INT y, INT width, INT height, INT cornerX, INT cornerY);
6 
7 public:
8     void AddRoundRect(INT x, INT y, INT width, INT height, INT cornerX, INT cornerY);
9 };

CGraphicsRoundRectPath的源代碼:

 1 CGraphicsRoundRectPath::CGraphicsRoundRectPath(INT x, INT y, INT width, INT height, INT cornerX, INT cornerY)
 2     :Gdiplus::GraphicsPath()
 3 {
 4     AddRoundRect(x,y,width,height,cornerX,cornerY);
 5 }
 6 void CGraphicsRoundRectPath::AddRoundRect(INT x, INT y, INT width, INT height, INT cornerX, INT cornerY)
 7 {
 8     INT elWid = 2*cornerX;
 9     INT elHei = 2*cornerY;
10 
11     AddArc(x,y,elWid,elHei,180,90); // 左上角圓弧
12     AddLine(x+cornerX,y,x+width-cornerX,y); // 上邊
13 
14     AddArc(x+width-elWid,y, elWid,elHei,270,90); // 右上角圓弧
15     AddLine(x+width,y+cornerY, x+width,y+height-cornerY);// 右邊
16 
17     AddArc(x+width-elWid,y+height-elHei, elWid,elHei,0,90); // 右下角圓弧
18     AddLine(x+width-cornerX,y+height, x+cornerX,y+height); // 下邊
19 
20     AddArc(x,y+height-elHei, elWid,elHei,90,90); 
21     AddLine(x,y+cornerY, x, y+height-cornerY);
22 }

 

 

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM