Control.CreateGraphics メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Control.CreateGraphics メソッドの意味・解説 

Control.CreateGraphics メソッド

コントロールGraphics作成します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説
使用例使用例

指定したコントロールサイズ変更して書式設定されたテキスト収容できるようにするコード例次に示します書式設定されたテキストは、コントロール割り当てられFontテキスト適用されている Text プロパティです。この例では AutoSizeControl メソッドにも、コントロールすべての端に適用する埋め込みを表す textPadding パラメータあります埋め込み均等に表示されるようにするには、System.Drawing.ContentAlignment の MiddleCenter 値を指定してテキスト配置します (コントロールがこれをサポートしている場合)。

Private Sub AutoSizeControl(control As
 Control, textPadding As Integer)
   ' Create a Graphics object for the Control.
   Dim g As Graphics = control.CreateGraphics()
   
   ' Get the Size needed to accommodate the formatted Text.
   Dim preferredSize As Size = g.MeasureString(
 _
     control.Text, control.Font).ToSize()
   
   ' Pad the text and resize the control.
   control.ClientSize = New Size( _
     preferredSize.Width + textPadding * 2, _
     preferredSize.Height + textPadding * 2)
   
   ' Clean up the Graphics object.
   g.Dispose()
End Sub
private void AutoSizeControl(Control control,
 int textPadding)
{
   // Create a Graphics object for the Control.
   Graphics g = control.CreateGraphics();

   // Get the Size needed to accommodate the formatted Text.
   Size preferredSize = g.MeasureString(
      control.Text, control.Font).ToSize();

   // Pad the text and resize the control.
   control.ClientSize = new Size(
      preferredSize.Width + (textPadding * 2), 
      preferredSize.Height+(textPadding * 2) );

   // Clean up the Graphics object.
   g.Dispose();
}
private:
   void AutoSizeControl( Control^ control, int
 textPadding )
   {
      
      // Create a Graphics object for the Control.
      Graphics^ g = control->CreateGraphics();
      
      // Get the Size needed to accommodate the formatted Text.
      System::Drawing::Size preferredSize = g->MeasureString( control->Text,
 control->Font ).ToSize();
      
      // Pad the text and resize the control.
      control->ClientSize = System::Drawing::Size( preferredSize.Width + (textPadding
 * 2), preferredSize.Height + (textPadding * 2) );
      
      // Clean up the Graphics object.
      delete g;
   }
private void AutoSizeControl(Control control,
 int textPadding)
{
    // Create a Graphics object for the Control.
    Graphics g = control.CreateGraphics();
    // Get the Size needed to accommodate the formatted Text.
    Size preferredSize = g.MeasureString(control.get_Text(), control.
        get_Font()).ToSize();
    // Pad the text and resize the control.
    control.set_ClientSize(new Size(preferredSize.get_Width()
 
        + textPadding * 2, preferredSize.get_Height() + textPadding * 2));
    // Clean up the Graphics object.
    g.Dispose();
} //AutoSizeControl
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からControl.CreateGraphics メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControl.CreateGraphics メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControl.CreateGraphics メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Control.CreateGraphics メソッド」の関連用語

Control.CreateGraphics メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Control.CreateGraphics メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS