ピクチャーボックスにボタンを描く


VB Tips And Sample(HOME)(VB.NET Sample インデックス)

VB6ではAPI(DrawEdge)を使用して描いていましたがNETでは以下で描けるようです。


    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

        'ピクチャーボックスのグラフィックスを取得
        Dim hwnd As New IntPtr
        hwnd = Me.PictureBox1.Handle
        Dim g As Graphics = Graphics.FromHwnd(hwnd)

        Dim Rect As Rectangle

        Rect.X = 10
        Rect.Y = 10
        Rect.Width = 100
        Rect.Height = 100

        'ボタンが押された状態を描く
        ControlPaint.DrawBorder3D(g, Rect, Border3DStyle.SunkenInner, Border3DSide.Bottom + Border3DSide.Left + Border3DSide.Top + Border3DSide.Right)
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp

        'ピクチャーボックスのグラフィックスを取得
        Dim hwnd As New IntPtr
        hwnd = Me.PictureBox1.Handle
        Dim g As Graphics = Graphics.FromHwnd(hwnd)

        Dim Rect As Rectangle

        Rect.X = 10
        Rect.Y = 10
        Rect.Width = 100
        Rect.Height = 100

        'ボタンを押した後を描く
        ControlPaint.DrawBorder3D(g, Rect, Border3DStyle.RaisedInner, Border3DSide.Bottom + Border3DSide.Left + Border3DSide.Top + Border3DSide.Right)
    End Sub


End Class

画像は押した状態

VB Tips And Sample(HOME)(VB.NET Sample インデックス)