Delphi: problems with GDI + and gradient frame / rectangle

Delphi XE2. There is a shape and a frame.

Shape and frame doublebuffered. GlassFrameswitched on.

I draw a background frame and try to draw a right aligned rectangle, but there are errors. Especially I have errors when resizing.

The rectangle does not want to get from transparency to opaque black. 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;

Please help me draw a rectangle on a gradient frame, usually from transparency to opaque black.

+5
source share
1 answer

Changing the code as shown below will result in a right-aligned thin line from opacity to black opaque.

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 enabledGlassFrame disabled

TFrame GlassFrame (). ( ) GlassFrame .

2:

SheetOfGlass, .

enter image description here

3:

GlassFrame 40 . 0, ​​ .

+3
source

All Articles