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

Graphics.GetHdc メソッド

この Graphics関連付けられているデバイス コンテキスト識別するハンドル取得します

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。この例では、Windows GDI 関数呼び出してGDI+Graphics メソッドと同じタスク実行します。このコード次のアクション実行します

Public Class GDI
    <System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")>
 _
    Friend Shared Function
 Rectangle(ByVal hdc As IntPtr, _
    ByVal ulCornerX As Integer,
 ByVal ulCornerY As Integer,
 ByVal lrCornerX As Integer, _
    ByVal lrCornerY As Integer)
 As Boolean
    End Function
End Class

<System.Security.Permissions.SecurityPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, Flags := _
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Public Sub GetHdcForGDI1(ByVal
 e As PaintEventArgs)

    ' Create pen.
    Dim redPen As New Pen(Color.Red,
 1)

    ' Draw rectangle with GDI+.
    e.Graphics.DrawRectangle(redPen, 10, 10, 100, 50)

    ' Get handle to device context.
    Dim hdc As IntPtr = e.Graphics.GetHdc()

    ' Draw rectangle with GDI using default pen.
    GDI.Rectangle(hdc, 10, 70, 110, 120)

    ' Release handle to device context.
    e.Graphics.ReleaseHdc(hdc)
End Sub
public class GDI
{
    [System.Runtime.InteropServices.DllImport("gdi32.dll")]
    internal static extern bool Rectangle(
       IntPtr hdc,
       int ulCornerX, int ulCornerY,
       int lrCornerX, int lrCornerY);
}

[System.Security.Permissions.SecurityPermission(
System.Security.Permissions.SecurityAction.LinkDemand, Flags = 
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]            
public void GetHdcForGDI1(PaintEventArgs e)
{

    // Create pen.
    Pen redPen = new Pen(Color.Red, 1);

    // Draw rectangle with GDI+.
    e.Graphics.DrawRectangle(redPen, 10, 10, 100, 50);

    // Get handle to device context.
    IntPtr hdc = e.Graphics.GetHdc();

    // Draw rectangle with GDI using default pen.
    GDI.Rectangle(hdc, 10, 70, 110, 120);

    // Release handle to device context.
    e.Graphics.ReleaseHdc(hdc);
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

「Graphics.GetHdc メソッド」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS