[英]How do I convert picturebox.click event into a button.click event
我試圖有兩個選擇在圖片框周圍繪制邊框。 我可以單擊圖片框以突出顯示,但現在希望能夠使用按鈕來執行相同的操作。
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)
當我嘗試添加按鈕時,單擊“出現未處理的異常-System.windows.forms.button”,鍵入System.windows.forms.picturebox錯誤。
我試圖在導致上述錯誤的“句柄”之后添加按鈕單擊事件。
Private Sub imgLabel_Click(sender As Object, e As EventArgs) Handles imgLabel.Click, button1.click
我對編程還很陌生,我的搜索結果正在使任何東西變得有價值。 我不太了解Ctypes / Directcast。
任何幫助是極大的贊賞。
好的,所以我最終選擇了這個...
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
似乎可以正常運行,但需要大量手動輸入點。 我還有六個。
你可以試試
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
imgLabel_Click(imgLabel, nothing)
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.