Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
LCL
»
[SOLVED] TPanel bar MouseWheel step
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Front-end framework
by
PierceNg
[
Today
at 05:46:34 am]
Amigo programming languag...
by
paxscript
[
Today
at 05:21:56 am]
[SOLVED] The "dockedforme...
by
Gustavo 'Gus' Carreno
[
Today
at 05:08:22 am]
How many lines is too man...
by
440bx
[
Today
at 04:12:46 am]
X11Libre, finally and for...
by
Fred vS
[
Today
at 03:37:59 am]
https://live.freepascal.o...
by
PierceNg
[
Today
at 03:04:22 am]
Debian removes FPC/Lazaru...
by
Fred vS
[
Today
at 01:17:08 am]
PasLLM - LLM Inference En...
by
valdir.marcos
[
Today
at 01:11:25 am]
Fast Canvas Library V1.05...
by
Gigatron
[
Today
at 01:09:53 am]
TDirectoryEdit with OnAft...
by
Bart
[
Today
at 01:04:32 am]
Problem wih reference to ...
by
PascalDragon
[
Today
at 12:09:44 am]
Win 11, strange position ...
by
Bart
[March 07, 2026, 11:23:38 pm]
Benchmark test in nanosec...
by
PascalDragon
[March 07, 2026, 11:14:15 pm]
How to execute a procedur...
by
n7800
[March 07, 2026, 10:17:32 pm]
Set horizontal scroll pos...
by
jamie
[March 07, 2026, 09:50:54 pm]
[SOLVED] Add Help to an A...
by
valdir.marcos
[March 07, 2026, 07:18:00 pm]
Variable initialization
by
valdir.marcos
[March 07, 2026, 05:58:47 pm]
Lazarus IDE built for LCL...
by
valdir.marcos
[March 07, 2026, 05:57:09 pm]
Status of LCL-fpGUI widge...
by
valdir.marcos
[March 07, 2026, 04:04:53 pm]
Status of LCL's CustomDra...
by
zeljko
[March 07, 2026, 03:59:56 pm]
uses unit decalration ord...
by
Martin_fr
[March 07, 2026, 02:10:32 pm]
Update a table with an Au...
by
CraigC
[March 07, 2026, 01:56:50 pm]
could Ardour's YTK be use...
by
robert rozee
[March 07, 2026, 01:51:39 pm]
[SOLVED] File Format LAMW...
by
RaketeMike
[March 07, 2026, 01:41:46 pm]
[ANN] PasBuild 1.5.0 rele...
by
cdbc
[March 07, 2026, 05:10:09 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] TPanel bar MouseWheel step (Read 787 times)
Pe3s
Hero Member
Posts: 641
[SOLVED] TPanel bar MouseWheel step
«
on:
November 23, 2023, 05:40:06 pm »
Hello, how can I program the OnMouseWheel event with increments of 5?
Regards
Code: Pascal
[Select]
[+]
[-]
uses
Classes
,
SysUtils
,
Forms
,
Controls
,
Graphics
,
Dialogs
,
ExtCtrls
,
LCLIntf
,
Types
,
Math
;
type
{ TForm1 }
TForm1
=
class
(
TForm
)
Panel1
:
TPanel
;
Panel2
:
TPanel
;
procedure
Panel1MouseMove
(
Sender
:
TObject
;
Shift
:
TShiftState
;
X
,
Y
:
Integer
)
;
procedure
Panel1Paint
(
Sender
:
TObject
)
;
private
public
end
;
var
Form1
:
TForm1
;
BarPos
:
Integer
=
100
;
implementation
{$R *.lfm}
{ TForm1 }
procedure
TForm1
.
Panel1Paint
(
Sender
:
TObject
)
;
var
R
:
TRect
;
begin
with
Panel1
,
Canvas
do
begin
R
:
=
Rect
(
0
,
0
,
Panel1
.
Width
*
BarPos
div
100
,
Panel1
.
Height
)
;
Brush
.
Color
:
=
RGB
(
250
,
208
,
44
)
;
FillRect
(
R
)
;
end
;
end
;
procedure
TForm1
.
Panel1MouseMove
(
Sender
:
TObject
;
Shift
:
TShiftState
;
X
,
Y
:
Integer
)
;
begin
if
(
ssLeft
in
Shift
)
then
begin
BarPos
:
=
EnsureRange
(
X
*
100
div
Panel1
.
Width
,
0
,
100
)
;
if
(
BarPos
mod
5
)
=
0
then
begin
Panel1
.
Invalidate
;
Panel2
.
Caption
:
=
IntToStr
(
BarPos
)
;
end
;
end
;
end
;
end
.
«
Last Edit: November 23, 2023, 07:00:06 pm by Pe3s
»
Logged
Handoko
Hero Member
Posts: 5524
My goal: build my own game engine using Lazarus
Re: TPanel bar MouseWheel step
«
Reply #1 on:
November 23, 2023, 06:23:49 pm »
Done.
Code: Pascal
[Select]
[+]
[-]
unit
Unit1
;
{$mode objfpc}{$H+}
interface
uses
Classes
,
SysUtils
,
Forms
,
Controls
,
ExtCtrls
,
LCLIntf
;
type
{ TForm1 }
TForm1
=
class
(
TForm
)
Panel1
:
TPanel
;
Panel2
:
TPanel
;
procedure
Panel1MouseWheel
(
Sender
:
TObject
;
Shift
:
TShiftState
;
WheelDelta
:
Integer
;
MousePos
:
TPoint
;
var
Handled
:
Boolean
)
;
procedure
Panel1Paint
(
Sender
:
TObject
)
;
end
;
var
Form1
:
TForm1
;
BarPos
:
Integer
=
100
;
implementation
{$R *.lfm}
{ TForm1 }
procedure
TForm1
.
Panel1Paint
(
Sender
:
TObject
)
;
var
R
:
TRect
;
begin
with
Panel1
,
Canvas
do
begin
R
:
=
Rect
(
0
,
0
,
Panel1
.
Width
*
BarPos
div
100
,
Panel1
.
Height
)
;
Brush
.
Color
:
=
RGB
(
250
,
208
,
44
)
;
FillRect
(
R
)
;
end
;
end
;
procedure
TForm1
.
Panel1MouseWheel
(
Sender
:
TObject
;
Shift
:
TShiftState
;
WheelDelta
:
Integer
;
MousePos
:
TPoint
;
var
Handled
:
Boolean
)
;
const
Step
=
5
;
begin
case
WheelDelta <
0
of
True
:
BarPos
:
=
BarPos
-
Step
;
False
:
BarPos
:
=
BarPos
+
Step
;
end
;
if
BarPos <
0
then
BarPos
:
=
0
;
if
BarPos >
100
then
BarPos
:
=
100
;
Panel1
.
Invalidate
;
Panel2
.
Caption
:
=
IntToStr
(
BarPos
)
;
end
;
end
.
Tested on Ubuntu Mate only, but I think it should work too on Windows.
Logged
Pe3s
Hero Member
Posts: 641
Re: TPanel bar MouseWheel step
«
Reply #2 on:
November 23, 2023, 06:34:08 pm »
@Handoko, I noticed that if we move the mouse bar and then use the mouse wheel, the values do not match. It is possible to make the values the same every 5. Why does this happen?
Regards
Logged
Handoko
Hero Member
Posts: 5524
My goal: build my own game engine using Lazarus
Re: TPanel bar MouseWheel step
«
Reply #3 on:
November 23, 2023, 06:42:08 pm »
Add this MouseMove event:
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
Panel1MouseMove
(
Sender
:
TObject
;
Shift
:
TShiftState
;
X
,
Y
:
Integer
)
;
begin
if
not
(
ssLeft
in
Shift
)
then
Exit
;
BarPos
:
=
EnsureRange
(
X
*
100
div
Panel1
.
Width
,
0
,
100
)
;
BarPos
:
=
BarPos
-
(
BarPos
mod
5
)
;
Panel1
.
Invalidate
;
Panel2
.
Caption
:
=
IntToStr
(
BarPos
)
;
end
;
Logged
Pe3s
Hero Member
Posts: 641
Re: TPanel bar MouseWheel step
«
Reply #4 on:
November 23, 2023, 06:59:50 pm »
@Handoko, Thank you for your help
Regards
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
LCL
»
[SOLVED] TPanel bar MouseWheel step
TinyPortal
© 2005-2018