方法 : テキストをボックスを表示します。

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

プログラム例を次に示しますは、四角形の文字列の周囲を描画します。

使用例

                        Protected
                        Overrides
                        Sub OnPaint(ByVal e As PaintEventArgs)
    Dim s AsString = ".NET Compact Framework"Dim pen AsNew Pen(Color.Red, 5)
    Dim font AsNew Font("Arial", 10, FontStyle.Regular)
    Dim brush AsNew SolidBrush(Color.Black)
    Dim textSize As SizeF = e.Graphics.MeasureString(s, font)

    ' Create a rectangle with padding space between string and box.Dim r AsNew Rectangle(45, 70, CInt(Fix(textSize.Width) + 10), _
        CInt(Fix(textSize.Height) + 10))
    e.Graphics.DrawRectangle(pen, r)
    e.Graphics.DrawString(s, font, brush, 50F, 75F)
    MyBase.OnPaint(e)
EndSub
                        protected
                        override
                        void OnPaint(PaintEventArgs e)
{
    string s = ".NET Compact Framework";
    Pen pen = new Pen(Color.Red, 5);
    Font font = new Font("Arial", 10, FontStyle.Regular);
    SolidBrush brush = new SolidBrush(Color.Black);
    SizeF textSize = e.Graphics.MeasureString(s, font);
    int newW = (int) textSize.Width + 10;
    int newH = (int) textSize.Height + 10;

    Rectangle r = new Rectangle(45, 70, newW, newH);
    e.Graphics.DrawRectangle(pen, r);
    e.Graphics.DrawString(s, font, brush, 50F, 75F);
base.OnPaint(e);
}

コードのコンパイル方法

この例では、次の名前空間への参照が必要です。

参照

概念

.NET コンパクトなフレームワーク方法を説明したトピックの検索

その他の技術情報

グラフィックスと、.NET での描画の最適化フレームワーク