Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
[SOLVED] Fitting control to StringGrid cell
Free Pascal
Website
Downloads
Wiki
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Bugtracker
IRC channel
Latest SVN
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
Contemporary Pascal Discu...
by
Warfley
[
Today
at 03:50:07 am]
Lazarus 2.0.12 hangs on o...
by
Muso
[
Today
at 03:22:31 am]
memo and smileys
by
mercurhyo
[
Today
at 02:17:10 am]
Tabs in Source Editor
by
trev
[
Today
at 01:44:22 am]
A poll about FPC +/ Lazar...
by
dbannon
[
Today
at 01:37:57 am]
How to get the value of a...
by
wp
[
Today
at 01:15:19 am]
Actioning an IPRo hot lin...
by
wp
[
Today
at 01:07:30 am]
Can't recompile Lazarus 2...
by
trev
[
Today
at 01:04:11 am]
MOVED: LCL Custom Control...
by
trev
[
Today
at 01:00:31 am]
create OpenGL Context und...
by
Seenkao
[
Today
at 12:52:46 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Fitting control to StringGrid cell (Read 200 times)
pcurtis
Sr. Member
Posts: 491
[SOLVED] Fitting control to StringGrid cell
«
on:
February 28, 2021, 05:55:59 pm »
Hi All,
why doesn't the control (TButton) fit the cell in a StringGrid when I do this
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
StringGrid1DrawCell
(
Sender
:
TObject
;
aCol
,
aRow
:
Integer
;
aRect
:
TRect
;
aState
:
TGridDrawState
)
;
begin
if
(
aCol
=
1
)
and
(
aRow
=
2
)
then
Button2
.
SetBounds
(
aRect
.
Left
,
aRect
.
Top
,
aRect
.
Width
,
aRect
.
Height
)
;
(
Sender as TStringGrid
)
.
DefaultDrawCell
(
aCol
,
aRow
,
aRect
,
aState
)
;
end
;
Its close but about 10 pixels off
«
Last Edit: February 28, 2021, 06:49:12 pm by pcurtis
»
Logged
Windows 10 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0
Handoko
Hero Member
Posts: 4158
My goal: build my own game engine using Lazarus
Re: Fitting control to StringGrid cell
«
Reply #1 on:
February 28, 2021, 06:26:09 pm »
It should be something like this:
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
StringGrid1DrawCell
(
Sender
:
TObject
;
aCol
,
aRow
:
Integer
;
aRect
:
TRect
;
aState
:
TGridDrawState
)
;
var
TheGrid
:
TStringGrid
;
begin
if
not
(
Sender is TStringGrid
)
then
Exit
;
TheGrid
:
=
(
Sender as TStringGrid
)
;
if
(
aCol
=
1
)
and
(
aRow
=
2
)
then
Button1
.
SetBounds
(
aRect
.
Left
+
TheGrid
.
Left
,
aRect
.
Top
+
TheGrid
.
Top
,
aRect
.
Width
,
aRect
.
Height
)
;
end
;
Logged
jamie
Hero Member
Posts: 4346
Re: Fitting control to StringGrid cell
«
Reply #2 on:
February 28, 2021, 06:26:34 pm »
hard to say...
could be borderspacing values set in the control?
the control may have the wrong parent..?
The control could be scrolled alittle ?
Logged
The only true wisdom is knowing you know nothing
Handoko
Hero Member
Posts: 4158
My goal: build my own game engine using Lazarus
Re: Fitting control to StringGrid cell
«
Reply #3 on:
February 28, 2021, 06:30:57 pm »
Not hard.
It's about the coordinate origin. The button's coordinate origin is the form's top left corner but the aRect in the event is using the grid's top left corner as its origin.
Logged
pcurtis
Sr. Member
Posts: 491
Re: Fitting control to StringGrid cell
«
Reply #4 on:
February 28, 2021, 06:43:28 pm »
Thanks
Logged
Windows 10 / Linux Mint 20
Laz 2.0.12
FPC 3.2.0
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
[SOLVED] Fitting control to StringGrid cell
TinyPortal
© 2005-2018