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;