2010-04-07 112 views

回答

9

創建一個圓角矩形作爲路徑,選擇路徑作爲剪切路徑,然後對同一個矩形進行漸變填充。與MFC代碼應該是這樣的:

int top = 10; 
int left = 10; 
int right = 200; 
int bottom = 200; 
int radius = 20; 


pDC->BeginPath(); 
pDC->RoundRect(left, top, right, bottom, radius, radius); 
pDC->EndPath(); 
pDC->SelectClipPath(RGN_COPY); 

TRIVERTEX vertices[2]; 

vertices[0].x = left; 
vertices[0].y = top; 
vertices[0].Red = 0xffff; 
vertices[0].Green = 0; 
vertices[0].Blue = 0; 
vertices[0].Alpha = 0xffff; 

vertices[1].x = right; 
vertices[1].y = bottom; 
vertices[1].Red = 0; 
vertices[1].Green = 0; 
vertices[1].Blue = 0xffff; 
vertices[1].Alpha = 0xffff; 

GRADIENT_RECT r; 
r.UpperLeft = 0; 
r.LowerRight = 1; 

pDC->GradientFill(vertices, 2, &r, 1, GRADIENT_FILL_RECT_V); 

如果你不使用MFC,該pDC->x(...)將與x(your_DC, ...)所取代。

+0

謝謝,它的工作原理! – lovespring 2010-04-08 01:47:04