Home > Back-end >  C builder StringGrid controls how the data in the vertical center
C builder StringGrid controls how the data in the vertical center

Time:10-08

In c + + builder StringGrid controls how the data in the vertical center

CodePudding user response:

In stringgrid controls do up and down in the text in the cell center


After repeated practice, I finally found the solution to make the text centered way up and down in each cell unit:
Is using the draw method of drawing board, through the "painting" the text solves this problem, ha, not a given ~
Implementation is very simple:

Set up a whole other variables: var Iscentre: Boolean;

When need to up and down the center display text content, language sentence:
Cells (x, y) :=, collocation Iscentre is true;
(note: be sure to assign null!!!!! Why below) ~ ~ ~ ~ ~ x, y is a local variable

To add Form1 stringgrid control OnDrawCell events, procedure code:
Procedure TForm1. StringGrid1DrawCell (Sender: TObject; ACol, ARow: Integer;
The Rect: TRect; State: TGridDrawState);
The begin
If iscentre then
Stringgrid1. Canvas. TextOut (the rect. Left + 14, the rect. Top + 8, title center);
end; ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Please according to the specific Settings!

Because this event is triggered, the condition of cell is happen by assignment, so must the blank value to trigger Stringgrid
OnDrawCell event!

CodePudding user response:

In the Draw method implementation;

CodePudding user response:

 void __fastcall TForm1: : StringGrid1DrawCell (TObject * Sender, int ACol, 
Int ARow, TRect & amp; The Rect, TGridDrawState State)
{

DrawText (StringGrid1 - & gt; Canvas - & gt; Handle, StringGrid1 - & gt; Cells [ACol] [ARow] c_str (),
1, (the RECT *) & amp; The Rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER);

}
  • Related