LoginSignup
0
1

More than 3 years have passed since last update.

2015-12-15 c++ builder XE4, 10.2 Tokyo > Forms > 細い横線を表示する > TShape使用 | PenとBrush

Last updated at Posted at 2015-12-15
動作確認
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

細い横線を表示したい。

参考 SOのTShapeというキーワードをもとにやってみた。

準備

  1. TColorBoxを追加
  2. TEditを追加. 線の太さを指定する. E_lineWidth
  3. Buttonを追加
  4. TShapeを追加
  5. TEditを追加. TShapeとの比較として. Edit1

コード

Unit1.cpp
static int calcHeight(int lineWidth)
{
    return lineWidth * 2 + 1;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Shape1->Brush->Color = ColorBox1->Selected;
    Edit1->Color = ColorBox1->Selected;

    int height = calcHeight( E_lineWidth->Text.ToInt() );

    if (height > 0) {
        Shape1->Height = height;
        Edit1->Height = height;
    }
}
void __fastcall TForm1::FormShow(TObject *Sender)
{
    Shape1->Pen->Style = psClear; // 枠線を消す
}

結果

線の太さ1
右上はTShapeで右下はTEdit。

qiita.png

線の太さ2
qiita.png

線の太さ3
qiita.png

まとめ

  • 枠線を消したTShapeでやるのがよさそう
  • TEditは太さを変えた時にBevelの表示・非表示が変わるので扱いにくい

よく使うTEdit(や他のよく使うコンポーネント)でやろうとするより、素直にTShapeを使うのがよさそうだった。

PenとBrush

(追記 2019-06-21)

  • PenはTShapeの外側の線
  • BrushはTShapeの内側の塗りつぶし

として覚えると記憶に残るかもしれない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1