Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

TSplitter enhanced with grab bar

Discussion in 'Delphi Programming' started by N0body, Mar 13, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Recently someone asked me what splitter component I had used in my (very secret) resource editor. The splitter is a very simple descendant of the standard VCL TSplitter. The only difference from the standard one is that my custom splitter sports a grab bar, bumps, knobs or whatever they are called.
    The source for the custom splitter is only about 40 lines of code so I thought I might as well just post it here and let everyone benefit from it. The source also demonstrates a very useful technique that I often use to customize the standard VCL components without the hassle of having to create design time packages.
    It’s really very simple so without further ado here comes:

    [​IMG]

    Code:
    unit amSplitter;
    
    interface
     
    uses
      ExtCtrls;
     
    //------------------------------------------------------------------------------
    //
    //      TSplitter enhanced with grab bar
    //
    //------------------------------------------------------------------------------
    type
      TSplitter = class(ExtCtrls.TSplitter)
      protected
        procedure Paint; override;
      end;
     
    implementation
     
    uses
      Windows, Graphics, Controls, Classes;
     
    //------------------------------------------------------------------------------
    //
    //      TSplitter enhanced with grab bar
    //
    //------------------------------------------------------------------------------
    procedure TSplitter.Paint;
    var
      R: TRect;
      X, Y: integer;
      DX, DY: integer;
      i: integer;
      Brush: TBitmap;
    begin
      R := ClientRect;
      Canvas.Brush.Color := Color;
      Canvas.FillRect(ClientRect);
     
      X := (R.Left+R.Right) div 2;
      Y := (R.Top+R.Bottom) div 2;
      if (Align in [alLeft, alRight]) then
      begin
        DX := 0;
        DY := 3;
      end else
      begin
        DX := 3;
        DY := 0;
      end;
      dec(X, DX*2);
      dec(Y, DY*2);
     
      Brush := TBitmap.Create;
      try
        Brush.SetSize(2, 2);
        Brush.Canvas.Brush.Color := clBtnHighlight;
        Brush.Canvas.FillRect(Rect(0,0,1,1));
        Brush.Canvas.Pixels[0, 0] := clBtnShadow;
        for i := 0 to 4 do
        begin
          Canvas.Draw(X, Y, Brush);
          inc(X, DX);
          inc(Y, DY);
        end;
      finally
        Brush.Free;
      end;
     
    end;
     
    end.

    Usage
    Place a standard TSplitter on a form.
    Add amSplitter to the interface section uses clause.

    Code:
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls,
      amSplitter;
    Compile and Run .
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block