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
Tabs in Source Editor
by
skalogryz
[
Today
at 07:31:20 am]
Windows LazSerial - Disk ...
by
CraigNZ
[
Today
at 06:54:50 am]
x64 vs x86 storing functi...
by
daobh
[
Today
at 04:56:08 am]
Creating a video editor
by
CarolynClark
[
Today
at 04:49:40 am]
BGRA Controls
by
lainz
[
Today
at 02:54:03 am]
Indy9-10 docs still alive
by
mercurhyo
[
Today
at 02:43:05 am]
Compiling Linux project t...
by
dbannon
[
Today
at 01:49:26 am]
How to use html colors in...
by
voltag
[
Today
at 12:32:27 am]
crash with chartEditor de...
by
Muso
[
Today
at 12:32:21 am]
Iteration over string arr...
by
jamie
[April 18, 2021, 11:37:39 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SOLVED] Fitting control to StringGrid cell (Read 202 times)
pcurtis
Sr. Member
Posts: 498
[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
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: 4362
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: 498
Re: Fitting control to StringGrid cell
«
Reply #4 on:
February 28, 2021, 06:43:28 pm »
Thanks
Logged
Windows 10
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