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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
WIKI Timeout issues
Please read here if you have trouble connecting to the wiki
Recent
OpenDialog and mouse even...
by
hedgehog
[
Today
at 08:06:03 am]
Lazarus 4, What's wrong w...
by
incendio
[
Today
at 07:59:48 am]
How to toggle back to the...
by
ASerge
[
Today
at 07:42:13 am]
Strict Aliasing Rule
by
Thaddy
[
Today
at 07:02:16 am]
IBX 2.7.2.1650 Bug?
by
incendio
[
Today
at 06:33:52 am]
Where to download IBX pre...
by
incendio
[
Today
at 06:17:46 am]
IBX, unable to install pr...
by
incendio
[
Today
at 04:34:20 am]
Component to manage short...
by
EganSolo
[
Today
at 12:36:36 am]
Replace controls dynamica...
by
Aruna
[June 18, 2025, 11:58:42 pm]
[SOLVED] Which RTL Unit d...
by
tfurnivall
[June 18, 2025, 10:25:01 pm]
CEF component - the first...
by
wp
[June 18, 2025, 08:21:11 pm]
slim installation by remo...
by
wp
[June 18, 2025, 08:19:09 pm]
Crash on changing a strin...
by
Martin_fr
[June 18, 2025, 08:11:34 pm]
How to stop macro executi...
by
Martin_fr
[June 18, 2025, 08:06:44 pm]
Layout problem by nested ...
by
etrusco
[June 18, 2025, 07:55:44 pm]
Build failure
by
user5
[June 18, 2025, 07:42:34 pm]
Loading an image from an ...
by
Fred vS
[June 18, 2025, 06:29:01 pm]
IDE Lazarus 4.0 on Window...
by
Martin_fr
[June 18, 2025, 03:47:30 pm]
Lazarus 4.0 RC3
by
paxnet_be
[June 18, 2025, 02:34:23 pm]
Firebird 5 remote login v...
by
LacaK
[June 18, 2025, 02:07:34 pm]
Compile errors in MacBook...
by
Thaddy
[June 18, 2025, 11:46:06 am]
LAMW - UTF-8 character in...
by
Alcatiz
[June 18, 2025, 11:36:29 am]
How to run an external pr...
by
vsajip
[June 18, 2025, 08:50:34 am]
lazbuild command line swi...
by
n7800
[June 18, 2025, 04:21:35 am]
dBGRidController and Erro...
by
essence-ciel
[June 18, 2025, 01:15:11 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] TPanel bar MouseWheel step (Read 677 times)
Pe3s
Hero Member
Posts: 596
[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: 5436
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: 596
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: 5436
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: 596
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