Title: Drawing a form border
Question: How to change the appearance of a forms border?
Answer:
Actually, it is very easy top change the standard frame border, just by capturing the two events of Non-Client-Paint and Non-Client-Activate and calling your own drawing at your own will onto the form.
First, you will have to find the width of your frame border, which can be done by using the GetSystemMetrics method. Now you can do whatever you want within the canvas, however, you should not leave the frame area.
type
TForm1 = class(TForm)
private
procedure FormFrame;
procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT;
procedure WMNCActivate(var Msg: TWMNCActivate); message WM_NCACTIVATE;
public
end;
procedure TForm1.FormFrame;
var
YFrame: Integer;
Rect: TRect;
begin
YFrame := GetSystemMetrics(SM_CYFRAME);
Canvas.Handle := GetWindowDC(Handle);
with Canvas, Rect do
begin
Left := 0;
Top := 0;
Right := Width;
Bottom := Height;
Pen.Style := psClear;
// draw background of frame
Brush.Color := clNavy;
Brush.Style := bsSolid;
Rectangle(Left, Top, Right, YFrame);
Rectangle(Left, Top, YFrame, Bottom);
Rectangle(Right - YFrame, Top, Right, Bottom);
Rectangle(Left, Bottom - YFrame, Right, Bottom);
// draw frame pattern
Brush.Color := clYellow;
Brush.Style := bsDiagCross;
Rectangle(Left, Top, Right, YFrame);
Rectangle(Left, Top, YFrame, Bottom);
Rectangle(Right - YFrame, Top, Right, Bottom);
Rectangle(Left, Bottom - YFrame, Right, Bottom);
end;
end;
procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);
begin
inherited;
FormFrame;
end;
procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
begin
inherited;
FormFrame;
end;