お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"StringGridでCellの文字配置設定"



 

 procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Integer;
   Rect: TRect; State: TGridDrawState);
 const
   SpaceW = 5; // 左及び右寄せの場合にCell端と文字列の間隔幅
   SpaceH = 2; // 上及び下寄せの場合にCell端と文字列の間隔幅
 var
   H, W, TexAliW, TexAliH: Integer;
 begin
   StringGrid1.Canvas.FillRect(Rect);
   // 列の表示設定の
   case Col of // これを Row にすると行毎に設定可能
     1, 2: // 1列目と2列目の設定
     begin
       TexAliW := 1; // 中心寄せ
       TexAliH := 0; // 上寄せ
     end;
     3, 4:
     begin // 3列目と4列目の設定
       TexAliW := 2; // 右寄せ
       TexAliH := 2; // 下寄せ
     end;
   else // そのほかの列の設定
     TexAliW := 0;   // 左寄せ
     TexAliH := 1;   // 中心寄せ
   end;
   // 縦方向の表示位置設定
   W := StringGrid1.Canvas.TextWidth(StringGrid1.Cells[Col, Row]);
   case TexAliW of
     0: // 左寄せ
       W := Rect.Left + SpaceW;
     1: // 中心寄せ
       W := ((Rect.Right - W) - Rect.Left) div 2 + Rect.Left;
     2: // 右寄せ
       W := Rect.Right - W - SpaceW;
   end;
   // 縦方向の表示位置設定
   H := StringGrid1.Canvas.TextHeight(StringGrid1.Cells[Col, Row]);
   case TexAliH of
     0: // 上寄せ
       H := Rect.Top + SpaceH;
     1: // 中心寄せ
       H := ((Rect.Bottom - H) - Rect.Top) div 2 + Rect.Top;
     2: // 下寄せ
       H := Rect.Bottom - H - SpaceH;
   end;
   // 文字列の表示
   StringGrid1.Canvas.TextOut(W, H, StringGrid1.Cells[Col,Row]);
 end;

 ### しんしん Team SpringStar☆彡 ### 〜 Aptiva730 with AirCraft97 〜

Original document by しんしん        氏 ID:(CXW02731)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum