怎样更改FORM.CAPTION的字体和大小?(30分)

  • 主题发起人 主题发起人 ycrsjxy
  • 开始时间 开始时间
Y

ycrsjxy

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样更改FORM.CAPTION的字体和大小?
 
一个笨办法是自己做一个标题栏,用Panel就行了。
 
应该没有直接的简单方法,改 windows 设置的话,所有窗口都改了。
 
procedure WMNCPAint(var Mes : TWMNCPaint); message WM_NCPAINT;

procedure TForm1.WMNCPAint(var Mes : TWMNCPaint);
var
ACanvas : TCanvas;
begin
ACanvas := TCanvas.Create;
try
ACanvas.Handle := GetWindowDC(Form1.Handle);
with ACanvas do begin
Brush.Color := clActiveCaption;
Font.Name := 'Times New Roman';
Font.Size := 10;
Font.Color := clCaptionText;
Font.Style := [fsItalic, fsBold];
TextOut(GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CXBORDER),
Round((GetSystemMetrics(SM_CYCAPTION) - Abs(Font.Height))/2) +1,
' Your title here!');
end;
finally
ReleaseDC(Form1.Handle, ACanvas.Handle);
ACanvas.Free;
end;
end;
 
好代码!!!
但点击“最大化”按钮或 移动时,即不断改变窗口时会有不正常现象。

头尾应分别加上一行代码:
procedure TForm1.WMNCPAint(var Mes: TWMNCPaint);
var
ACanvas : TCanvas;
begin
inherited;//////////////////////////////
ACanvas := TCanvas.Create;
try
ACanvas.Handle := GetWindowDC(Form1.Handle);
with ACanvas do begin
Brush.Color := clActiveCaption;
Font.Name := 'Times New Roman';
Font.Size := 10;

Font.Color := clCaptionText;
Font.Style := [fsItalic, fsBold];
TextOut(GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CXBORDER),
Round((GetSystemMetrics(SM_CYCAPTION) - Abs(Font.Height))/2) +1,
caption);/////////////////
end;
finally
ReleaseDC(Form1.Handle, ACanvas.Handle);
ACanvas.Free;
end;
mes.Result:=0; ////////////////////////////////
end;




WM_NCPAINT
An application sends the WM_NCPAINT message to a window when its frame must be painted.

WM_NCPAINT
hrgn = (HRGN) wParam; // handle of update region

Parameters
hrgn
Value of wParam. Handle to the update region of the window. The update region is clipped to the window frame. When wParam is 1, the entire window frame needs to be updated.
This value can be passed to GetDCEx as in the following example.

case WM_NCPAINT:
{
HDC hdc;
hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
// Paint into this DC
ReleaseDC(hwnd, hdc);
}

Return Values
An application returns zero if it processes this message.

Remarks
The DefWindowProc function paints the window frame.

An application can intercept the WM_NCPAINT message and paint its own custom window frame. The clipping region for a window is always rectangular, even if the shape of the frame is altered.

 
1、Object TreeView 里选 Form1
2、Object Inspector 里选 Font 下拉
3、Font 下选 Size
 
后退
顶部