Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Free Pascal
»
Beginners
(Moderators:
FPK
,
Tomas Hajny
) »
Cursor position.
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
Recent
Some observations on the ...
by
Thaddy
[
Today
at 11:09:15 am]
scrolling Tmemos simultan...
by
dbannon
[
Today
at 10:52:45 am]
simple thread handling fo...
by
Thaddy
[
Today
at 10:15:47 am]
Simple confirmatory quest...
by
egsuh
[
Today
at 10:13:37 am]
New Big Integer library i...
by
ad1mt
[
Today
at 10:12:45 am]
Free Pascal releases
by
Thaddy
[
Today
at 09:59:38 am]
Benefits of docked IDE in...
by
Thaddy
[
Today
at 09:56:38 am]
question on how to retrie...
by
rvk
[
Today
at 09:42:04 am]
TMemo scroll down (stupid...
by
TRon
[
Today
at 09:00:38 am]
fpPDF -transparent fill s...
by
tdb
[
Today
at 08:53:19 am]
OPM(Online Package Manage...
by
FrankBKK
[
Today
at 08:26:28 am]
Project not load TrfDataS...
by
pawelborek2
[
Today
at 08:13:09 am]
Not able to install "fpc-...
by
AlexTP
[
Today
at 07:55:06 am]
Xtensa-freertos wiki
by
ccrause
[
Today
at 06:53:52 am]
Retaining the scrollbars ...
by
Ed78z
[
Today
at 04:25:27 am]
Logarithmic transformatio...
by
kapibara
[
Today
at 02:01:56 am]
Close buttons on TPageCon...
by
dseligo
[
Today
at 01:32:06 am]
UtilWMI issue - not retur...
by
jamie
[
Today
at 12:07:55 am]
fpcupdeluxe and the Pico
by
TRon
[October 07, 2024, 10:46:44 pm]
Why MaxDouble does not eq...
by
MarkMLl
[October 07, 2024, 10:16:50 pm]
New language features?
by
PascalDragon
[October 07, 2024, 10:06:28 pm]
how to translate this fro...
by
MarkMLl
[October 07, 2024, 10:03:27 pm]
TSplitter or TPairSplitte...
by
vfclists
[October 07, 2024, 09:38:52 pm]
Advice needed on creating...
by
carl_caulkett
[October 07, 2024, 08:50:02 pm]
Tmemo don't control when ...
by
eldonfsr
[October 07, 2024, 08:39:34 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Cursor position. (Read 263 times)
seghele0
Full Member
Posts: 222
Cursor position.
«
on:
October 01, 2024, 01:06:38 pm »
I try to place the mouse cursor on Button1, but it doesn't work.
Please help.
Code: Pascal
[Select]
[+]
[-]
unit
Unit1
;
{$mode objfpc}{$H+}
interface
uses
Classes
,
SysUtils
,
Forms
,
Controls
,
Graphics
,
Dialogs
,
StdCtrls
,
ExtCtrls
;
type
{ TForm1 }
TForm1
=
class
(
TForm
)
Button1
:
TButton
;
Panel1
:
TPanel
;
procedure
FormCreate
(
Sender
:
TObject
)
;
private
public
end
;
var
Form1
:
TForm1
;
implementation
{$R *.lfm}
{ TForm1 }
procedure
TForm1
.
FormCreate
(
Sender
:
TObject
)
;
var
ButtonPosition
:
TPoint
;
begin
ButtonPosition
:
=
Button1
.
ClientToScreen
(
Point
(
0
,
0
)
)
;
Mouse
.
CursorPos
:
=
ButtonPosition
;
end
;
end
.
Logged
Hansvb
Hero Member
Posts: 701
Re: Cursor position.
«
Reply #1 on:
October 01, 2024, 04:56:18 pm »
hi,
a first attempt (not good enough but works a little)
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
FormCreate
(
Sender
:
TObject
)
;
var
pt1
:
TPoint
;
begin
pt1
.
x
:
=
0
;
pt1
.
y
:
=
0
;
pt1
:
=
Button1
.
Parent
.
ControlToScreen
(
pt1
)
;
pt1
.
X
:
=
pt1
.
X
+
Button1
.
Left
+
50
;
pt1
.
Y
:
=
pt1
.
Y
+
Button1
.
Top
+
50
;
mouse
.
CursorPos
:
=
pt1
;
end
;
Logged
seghele0
Full Member
Posts: 222
Re: Cursor position.
«
Reply #2 on:
October 01, 2024, 05:44:56 pm »
Hansvb,
It works perfectly.
A sincere thank you for your code.
Logged
wp
Hero Member
Posts: 12357
Re: Cursor position.
«
Reply #3 on:
October 01, 2024, 06:03:09 pm »
Quote from: seghele0 on October 01, 2024, 01:06:38 pm
I try to place the mouse cursor on Button1,
Sincerely? Software which takes over control of the mouse cursor, moves it to some place, or locks it in some window, will not be loved a lot...
Logged
Hansvb
Hero Member
Posts: 701
Re: Cursor position.
«
Reply #4 on:
October 01, 2024, 06:21:45 pm »
If you work with Windows, you can set the options so that a mouse should snap on the default button. That is indeed not very useful, but I did enjoy figuring out whether it could be made. So far I haven't been able to do it well.
Logged
Hansvb
Hero Member
Posts: 701
Re: Cursor position.
«
Reply #5 on:
October 01, 2024, 06:39:25 pm »
Found it.
I was looking at the wrong place.
@seghele0 this is better then my first attempt:
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
FormShow
(
Sender
:
TObject
)
;
var
pt1
:
TPoint
;
begin
pt1
.
x
:
=
0
;
pt1
.
y
:
=
0
;
pt1
:
=
Button1
.
ControlToScreen
(
pt1
)
;
pt1
.
X
:
=
pt1
.
X
+
(
Button1
.
Width
div
2
)
;
pt1
.
Y
:
=
pt1
.
Y
+
(
Button1
.
Height
div
2
)
;
mouse
.
CursorPos
:
=
pt1
;
end
;
Logged
Sieben
Sr. Member
Posts: 327
Re: Cursor position.
«
Reply #6 on:
October 01, 2024, 11:51:23 pm »
Or as a one-liner:
Code: Pascal
[Select]
[+]
[-]
Mouse
.
CursorPos
:
=
Button1
.
ControlToScreen
(
Point
(
Button1
.
Width
div
2
,
Button1
.
Height
div
2
)
)
;
«
Last Edit: October 01, 2024, 11:56:16 pm by Sieben
»
Logged
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7
seghele0
Full Member
Posts: 222
Re: Cursor position.
«
Reply #7 on:
October 02, 2024, 08:17:25 am »
Many thanks to all for the support.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Free Pascal
»
Beginners
(Moderators:
FPK
,
Tomas Hajny
) »
Cursor position.
TinyPortal
© 2005-2018