[SOLVED] Custom TPanel bar lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2023-05-19 16:06 Hello forum users, it is possible to add properties similar to trackbar or progressbar Min, Max and Position ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Panel2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);var  NewX, Max: Integer;begin  if not(ssLeft in Shift) then Exit;  NewX := X + Panel2.Left;  Max := Panel1.ClientWidth - Panel2.Width;  if NewX < 0 then NewX := 0;  if NewX > Max then NewX := Max;  Panel2.Left := NewX;end; ---------------------------------------------------------------------- KodeZwerg · 2023-05-19 17:06 You can add anything as a property, your class need to take care of that of course. ---------------------------------------------------------------------- Pe3s · 2023-05-19 18:14 One more question how do I have to modify the code to move the slider to the end to 100% ---------------------------------------------------------------------- KodeZwerg · 2023-05-19 21:23 I do not know your class code of that custom panel thingy. When you adding properties for min/max/position, than the position setter should calculate the sliders left drawing position, root of calculation would be "client width (where the slider is drawn into) - slider width = 100%" Based on that you know where "Position" is inside the min/max range. ---------------------------------------------------------------------- Pe3s · 2023-05-20 07:34 These are two TPanel objects, the code is in the first post, how do I correct the code to add Min, Max and Position ---------------------------------------------------------------------- KodeZwerg · 2023-05-20 09:15 Quote from: Pe3s on May 20, 2023, 09:34:37 amThese are two TPanel objects, the code is in the first post, how do I correct the code to add Min, Max and Position That is not class code, thats just an event handler. As told, you need to have your own class that implements all what you need, in your case derived from TPanel or similar, add in your class all what you need. Then you need to publish OnMouseMove, Min, Max, Position etc.... and put code in there. (But why not just simply make a TFrame with a TPanel and a TTrackBar ?) ---------------------------------------------------------------------- alpine · 2023-05-20 09:15 Quote from: Pe3s on May 20, 2023, 09:34:37 amThese are two TPanel objects, the code is in the first post, how do I correct the code to add Min, Max and Position It isn't clear to whom you'd like to add those properties. Do you want to make a new component sub-classing TPanel? Or you want to add properties to TForm1? Do you want them to be shown into the Object inspector? ---------------------------------------------------------------------- Pe3s · 2023-05-20 10:42 Thanks for the tips, I'll mix it up ---------------------------------------------------------------------- Handoko · 2023-05-20 10:48 Done! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,  StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Label1: TLabel;    Panel1: TPanel;    Panel2: TPanel;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure Panel2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer      );  strict private    FMin: Integer;  FMax: Integer;    function GetPosition: Integer;    procedure SetMax(Value: Integer);    procedure SetMin(Value: Integer);    procedure SetPosition(Value: Integer);  public    property BarMin: Integer read FMin write SetMin;    property BarMax: Integer read FMax write SetMax;    property BarPosition: Integer read GetPosition write SetPosition;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  Panel1.Anchors    := [akLeft, akRight, akTop];  Panel1.BevelOuter := bvNone;  Panel1.Caption    := '';  Panel1.Color      := clWhite;  Panel1.BevelOuter := bvNone;  Panel2.Caption    := '';  Panel2.Color    := clBlack;  BarMax := 80;  BarMin := 5;end; procedure TForm1.Button1Click(Sender: TObject);begin  BarPosition := 50;end; procedure TForm1.Panel2MouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);var  NewX, Max: Integer;begin   // From forum.lazarus.freepascal.org/index.php/topic,63407.msg480258  if not(ssLeft in Shift) then Exit;  NewX := X + Panel2.Left;  Max := Panel1.ClientWidth - Panel2.Width;  if NewX < 0 then NewX := 0;  if NewX > Max then NewX := Max;  Panel2.Left := NewX;  //----------   Label1.Caption := GetPosition.ToString;end; function TForm1.GetPosition: Integer;var  Range: Integer;  Pos:   Real;begin  Range  := FMax - FMin;  Pos    := (Panel2.Left / (Panel1.ClientWidth- Panel2.Width));  Result := Round(Pos * Range) + FMin;end; procedure TForm1.SetMax(Value: Integer);begin  if Value = FMax then Exit;  if Value < FMin then Exit;  FMax := Value;end; procedure TForm1.SetMin(Value: Integer);begin  if Value = FMin then Exit;  if Value > FMax then Exit;  FMin := Value;end; procedure TForm1.SetPosition(Value: Integer);var  Range: Integer;  Pos:   Real;begin  Range := Panel1.ClientWidth-Panel2.Width;  Pos   := (Value-FMin) / (FMax-FMin);  Panel2.Left := Round(Pos * Range);  Label1.Caption := GetPosition.ToString;end; end. Have not done: The code above does not support resizing the panel bar. It can be done easily by storing the BarPosition using OnBeforeResize event and then reposition it in OnResize event. Unfortunately there is no OnBeforeRresize event. ---------------------------------------------------------------------- Pe3s · 2023-05-20 11:34 Big beer @Handoko Thank you