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
TPairSplitter control lea...
by
wp
[
Today
at 11:31:27 am]
Use mORMot2 to export PDF...
by
rvk
[
Today
at 10:13:38 am]
Xtensa-freertos wiki
by
ccrause
[
Today
at 09:48:49 am]
Why MaxDouble does not eq...
by
jollytall
[
Today
at 09:40:23 am]
Building FPC 3.2.2 on Deb...
by
MarkMLl
[
Today
at 09:27:48 am]
Win SHBrowseForFolder API...
by
d2010
[
Today
at 09:02:38 am]
Class helpers cannot have...
by
Thaddy
[
Today
at 08:51:02 am]
Not able to install "fpc-...
by
dbannon
[
Today
at 07:19:07 am]
[Solved] Package Laz_Syna...
by
Fibonacci
[
Today
at 03:40:50 am]
Making a plea :)
by
dbannon
[
Today
at 02:25:25 am]
Q Win SHBrowseForFolder A...
by
ASerge
[
Today
at 02:18:29 am]
Reintroduce events and pr...
by
Joanna
[
Today
at 01:58:28 am]
Besides TForm is there a ...
by
mas steindorff
[
Today
at 12:40:09 am]
About $ and Cents - Dbf L...
by
Fibonacci
[
Today
at 12:01:43 am]
Is there a TPanel substit...
by
Sieben
[October 04, 2024, 11:47:42 pm]
FPC 3.2.2 / Lazarus 2.2.6...
by
Fred vS
[October 04, 2024, 09:58:43 pm]
Why I can not set affinit...
by
440bx
[October 04, 2024, 09:28:07 pm]
Feature announcement: Imp...
by
corpsman
[October 04, 2024, 08:48:30 pm]
Trying to tweak the bsTri...
by
carl_caulkett
[October 04, 2024, 08:19:54 pm]
AY_FLY Library
by
Gigatron
[October 04, 2024, 07:58:37 pm]
Error code documentation
by
Ștefan-Iulian Alecu
[October 04, 2024, 07:09:10 pm]
code seems bulky
by
Ștefan-Iulian Alecu
[October 04, 2024, 07:07:19 pm]
Еличка - a simple calcula...
by
CM630
[October 04, 2024, 06:12:07 pm]
standard or third party f...
by
Packs
[October 04, 2024, 03:41:49 pm]
Working MIDI app for the ...
by
carl_caulkett
[October 04, 2024, 03:29:15 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Cursor position. (Read 243 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: 12353
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: 326
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