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
duplicate an Object at ru...
by
jamie
[
Today
at 03:44:29 am]
Can /my/ AI help me with ...
by
schuler
[
Today
at 03:08:23 am]
Anubis activated
by
dsiders
[
Today
at 01:36:11 am]
wildcard utilities list
by
mas steindorff
[May 17, 2026, 11:01:19 pm]
TLazSerial : serial port ...
by
mas steindorff
[May 17, 2026, 10:50:34 pm]
StringGrid: which is "cur...
by
Bart
[May 17, 2026, 10:41:30 pm]
PopupMenu on dock menu
by
systemgvp
[May 17, 2026, 08:32:50 pm]
How to wait until a WebDA...
by
paweld
[May 17, 2026, 08:16:51 pm]
[SOLVED] Dark Theme
by
Hansvb
[May 17, 2026, 07:29:22 pm]
Bug with constref?
by
LemonParty
[May 17, 2026, 07:15:45 pm]
When will lazarus actuall...
by
marcov
[May 17, 2026, 05:52:04 pm]
FPC Unleashed (inline var...
by
Okoba
[May 17, 2026, 03:49:31 pm]
Can I enter MySQL prompt ...
by
nikel
[May 17, 2026, 03:41:56 pm]
is this code correct?
by
Thaddy
[May 17, 2026, 03:23:29 pm]
Anubis's website security...
by
ALLIGATOR
[May 17, 2026, 02:45:52 pm]
Pure Pascal LZ4, LZ5 and ...
by
LemonParty
[May 17, 2026, 01:38:07 pm]
Linking a PortAudio stati...
by
Thaddy
[May 17, 2026, 10:52:31 am]
TShellTreeView TopItem
by
Paolo
[May 17, 2026, 10:07:58 am]
Temp file CGI00000.TMP
by
Thaddy
[May 17, 2026, 09:32:16 am]
Nothing but chaotic attem...
by
LeP
[May 17, 2026, 09:02:05 am]
Feature suggestion - repe...
by
paweld
[May 17, 2026, 07:38:10 am]
search via TSQLQuery
by
paweld
[May 17, 2026, 07:28:41 am]
Amigo programming languag...
by
paxscript
[May 17, 2026, 05:49:02 am]
Klondike solitaire Part 2
by
valdir.marcos
[May 17, 2026, 03:50:07 am]
Creation of LAMW [NoGUI] ...
by
neuro
[May 17, 2026, 01:06:41 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] TPanel bar MouseWheel step (Read 815 times)
Pe3s
Hero Member
Posts: 647
[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: 5537
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: 647
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: 5537
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: 647
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