Forum > LCL
[SOLVED] TPanel slider position
Pe3s:
Hello forum members, what do I need to correct in the code to make the adjustment range -100 - 0 - 100 work?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Panel2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin if not(ssLeft in Shift) then Exit; Pos := X + Panel2.Left; Max := Panel1.ClientWidth - Panel2.Width; if Pos < 0 then Pos := 0; if Pos > Max then Pos := Max; Panel2.Left := Pos; BGProgress.Value := Round(100 * Pos / Max); Form1.Caption := IntToStr(BGProgress.Value);end; procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin if not (ssLeft in Shift) then Exit; Pos:= X; Max := Panel1.ClientWidth - Panel2.Width; if Pos < 0 then Pos := 0; if Pos > Max then Pos := Max; Panel2.Left:= Pos; BGProgress.Value := Round(100 * Pos / Max); Form1.Caption := IntToStr(BGProgress.Value);end;
Handoko:
Done.
This is the correct formula:
BGProgress.Value := Round(200 * Pos / Max) - 100;
Pe3s:
@Handoko, Thank you for your help :)
Thaddy:
I believe the correct formula to be BGProgress.Value := (200 * Pos div Max) - 100;, Handoko.
That processes completely in the integer domain.
Handoko:
Yes, you're right.
I forgot that div is more efficient than / for result in integer.
Navigation
[0] Message Index
[#] Next page