0

画像ボックスの周りに境界線を引くための 2 つのオプションを用意しようとしています。ピクチャボックスをクリックして強調表示できますが、ボタンを使用して同じことを実行できるようにしたいと考えています。

 Private Sub imgLabel_Click(sender As Object, e As EventArgs) Handles imgLabel.Click

Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle BorderBounds.Inflate(-1, -1)

ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics, BorderBounds, Color.Orange, ButtonBorderStyle.Solid)

If Not (HighLightededPictureBox Is Nothing) Then
    HighLightededPictureBox.Invalidate()
End If

'Rememeber the last highlighted PictureBox  
HighLightededPictureBox = CType(sender, PictureBox)

ボタン クリックを追加しようとすると、Exception Unhandled - System.windows.forms.button to type System.windows.forms.picturebox エラーが発生します。

上記のエラーの原因となる「ハンドル」の後にボタンクリックイベントを追加しようとしました。

 Private Sub imgLabel_Click(sender As Object, e As EventArgs) Handles imgLabel.Click, button1.click

私はプログラミングにかなり慣れていないので、検索結果は価値のあるものを見つけています。Ctypes/Directcasts を完全には理解していません。

どんな助けでも大歓迎です。

わかりました、それで私はこれで行きました...

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim boxsize As New Size(192, 169)
    Dim recpoint As New Point(0, 0)
    Dim myrectangle As New Rectangle(recpoint, boxsize)
    myrectangle.Inflate(-3, -3)
    Dim G As Drawing.Graphics = PictureBox1.CreateGraphics
    Dim Pen As New Pen(Color.Orange, 5)
    G.DrawRectangle(Pen, myrectangle)
End Sub

正常に動作しているようですが、ポイントを手動で入力する必要があります。私はこれをあと6つ持っています。

4

1 に答える 1