1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Draw to form caption

Discussion in 'Delphi Programming' started by AdminDF, Jan 3, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    {
    This writes form caption to center. However, old caption stays. The solution
    could be to use another variable as caption and keep Form.Caption empty.


    Add to private:
    }


    Code:
    procedure RedrawCaption;
      procedure WMMove(var Message: TMessage); message WM_MOVE;
      procedure WMResize(var Message: TMessage); message WM_SIZE;
    
    
    procedure TForm1.RedrawCaption;
    var
      LabelHeight, LabelWidth, LabelTop: Integer;
      Caption_Height, Border3D_Y, Button_Width, Border_Thickness: Integer;
      TitleCanvas: TCanvas;
      CaptionBarRect: TRect;
    begin
      TitleCanvas := TCanvas.Create;
      TitleCanvas.Handle := GetWindowDC(Handle);
      Border3D_Y := GetSystemMetrics(SM_CYEDGE);
      Button_Width := GetSystemMetrics(SM_CXSIZE);
      Border_Thickness  := GetSystemMetrics(SM_CYSIZEFRAME);
      Caption_Height := GetSystemMetrics(SM_CYCAPTION);
      LabelWidth := Canvas.TextWidth(Caption);
      LabelHeight := Canvas.TextHeight(Caption);
      LabelTop := LabelHeight - Caption_Height div 2;
      CaptionBarRect := Rect(Border_Thickness + Border3D_Y + Button_Width,
                             Border_Thickness + Border3D_Y,
                             Width - (Border_Thickness + Border3D_Y) - Button_Width * 4,
                             Caption_Height);
      TitleCanvas.Brush.Style := bsClear;
      TitleCanvas.Font.Color := clCaptionText;
      TitleCanvas.Font.Name := 'MS Sans Serif';
      TitleCanvas.Font.Style := [fsBold];
      DrawText(TitleCanvas.Handle, PChar(Caption), Length(Caption), CaptionBarRect,
               DT_CENTER or DT_SINGLELINE or DT_VCENTER);
    end;
    
    
    procedure TForm1.WMMove(var Message: TMessage);
    begin
      RedrawCaption;
    end;
    
    
    procedure TForm1.WMResize(var Message: TMessage);
    begin
      RedrawCaption;
    end;
     

Share This Page