Stringgrid usage tips

Source: Internet
Author: User
Tags drawtext

1. How to add color to the dotted border of (Focus) when adding selected text to the center

Procedure tform1.stringgrid1drawcell (Sender: tobject; ACOl, Arow: integer;
Rect: trect; State: tgriddrawstate );
VaR
Vtext: pchar;
Begin
With tstringgrid (sender) Do begin
Vtext: = pchar (cells [ACOl, Arow]);
Canvas. fillrect (rect );
Drawtext (canvas. Handle, vtext, strlen (vtext), rect,
Dt_center or dt_vcenter or dt_singleline); // redraw a cell

If gdfocused in State then begin // agree to camel_luo // I will add
Rect. Left: = rect. Left + 1;
Rect. Top: = rect. Top + 1;
Rect. Right: = rect. Right-1;
Rect. Bottom: = rect. Bottom-1;
Canvas. drawfocusrect (rect );
End;
End;
End;

2. When a row changes color, it indicates the difference between the current row and other rows in the editing status.

If goperatestate <> 'browse' then

With tstringgrid (sender) Do

Begin

If (inttostr (old) <> '0') and (old <> cur) then

Begin

For I: = 1 to stringgrid1.colcount-1 do

Begin

STR: = stringgrid1.cells [I, old];

Frect: = stringgrid1.cellrect (I, old); // obtain the region

Canvas. Brush. Color: = clcream; // fill color white

Canvas. fillrect (frect); // fill the area

Settextcolor (canvas. Handle, clblack); // text color

Drawtext (canvas. Handle, pchar (STR), length (STR), frect, 0); // windows. Pas that is, WIN32API calls the external function stdcall

End;

End;

If (inttostr (cur) <> '0') and (stringgrid1.row = cur) and (stringgrid1.row <> 0) and (old <> stringgrid1.row) then

Begin

Old: = cur; // The old row of the new row

For I: = 1 to stringgrid1.colcount-1 do

Begin

STR: = stringgrid1.cells [I, stringgrid1.row];

Frect: = stringgrid1.cellrect (I, stringgrid1.row );

Canvas. Brush. Color: = clskyblue;

Canvas. fillrect (frect );

Settextcolor (canvas. Handle, clblack );

Drawtext (canvas. Handle, pchar (STR), length (STR), frect, 0 );

End;

End;

End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.