2012-01-11 46 views
5

Delphi XE2。有一個表格&。德爾福:問題與GDI +&梯度框架/矩形

窗體和框架是doublebufferedGlassFrame已啓用。

我畫框的背景,並嘗試繪製一個右對齊的矩形,但有錯誤。尤其是我在調整大小時出現了錯誤。

矩形不希望從透明度正常繪製到不透明的黑色。 enter image description here

uses ...GDIPAPI, GDIPOBJ... 
type 
    TFrame2 = class(TFrame) 
    procedure PaintWindow(DC: HDC); override; 

    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

implementation 
{$R *.dfm} 

procedure TFrame2.PaintWindow(DC: HDC); 
var 
    R: TGPRect; 
    pen: TGPPen; 
    Graphics: TGPGraphics; 
    linGrBrush: TGPLinearGradientBrush; 
begin 
    R.X := 0; 
    R.Y := 0; 
    R.Width := self.Width; 
    R.Height := self.Height; 

    Graphics := TGPGraphics.Create(DC); 

    linGrBrush := TGPLinearGradientBrush.Create(R, MakeColor(255, 120, 248, 253), 
    MakeColor(255, 200, 216, 250), LinearGradientModeVertical); 

    Graphics.FillRectangle(linGrBrush, 0, 0, R.Width, R.Height); 
    linGrBrush.Free; 

    linGrBrush := TGPLinearGradientBrush.Create(MakePoint(0, 0), 
MakePoint(189, 2), MakeColor(0, 0, 0, 0), MakeColor(255, 0, 0, 0)); 

    Graphics.FillRectangle(linGrBrush, R.Width - 189, 79, 189, 2); 

    linGrBrush.Free; 
    Graphics.Free; 
end; 

請幫我從透明度通常繪製漸變框架上的一個矩形不透明黑色。

回答

3

更改如下所示的代碼將繪製從透明到黑色不透明的右對齊細線。

linGrBrush := TGPLinearGradientBrush.Create( 
    MakePoint(R.Width-189,0), MakePoint(R.Width,2), 
    MakeColor(0, 0, 0, 0), 
    MakeColor(255, 0, 0, 0)); 
Pen := TGPPen.Create(linGrBrush,3); 
Graphics.DrawLine(Pen,R.Width-189,79,R.Width,79); 
InvalidateRect(Handle,Rect(0,0,R.Width,R.Height),False); 

更新,使用InvalidateRect整個區域迫使幀的總重繪。 否則重畫可能會以奇怪的方式剪裁。 這將解決你的顏色變化效果。

但是GlassFrame缺陷是用下面的最後兩張圖片來說明的。 TFrame的外部框架在頂部和頂部不正確可見。

enter image description here

GlassFrame enabled GlassFrame disabled

GlassFrame被啓用(左)顯示TFRAME的功能障礙。 正確的圖片顯示一個完整的黑色框架(儘管在這張圖片中右側被壓縮裁剪),GlassFrame被禁用。

更新2:

啓用SheetOfGlass,一切似乎確定。

enter image description here

更新3:

GlassFrame頂部屬性設置爲40,並造成周圍的框架奇怪的邊界效應。將其設置爲0可解決此問題。

+0

謝謝!但這不是我想要的。請下載上面的項目並調整窗體大小,您將看到矩形的顏色發生變化。 – maxfax 2012-01-12 17:21:14

+0

查看我的更新。打開/關閉玻璃框架仍然是一個奇怪的效果。框架邊緣從玻璃框架兩側的高度35左右開始。似乎是某個系統中的一個錯誤。 – 2012-01-12 18:13:14

+0

如果您註銷PaintWindow過程並打開/關閉玻璃框,玻璃框架功能障礙更加明顯。 – 2012-01-12 18:27:30