2014-05-09 61 views
1

如此有趣的困境,我設法使標籤完全看不見,我可以用它在圖片的某些部分點擊事件。VB.NET PictureBox/Controls

我然後使用單擊事件使用調用另一個PictureBox的成爲關注的焦點picturebox3.visible =真..

我遇到的問題是,當它調用來自新PictureBox的是PictureBox的visibility..the控制(看不見的標籤)在picturebox2中的圖片似乎不起作用或缺失。

我需要用大約30張不同的圖片做這個,以便爲某人創建一種「模擬器」項目。

對此的任何想法?如果需要,我可以發佈代碼。 Picturebox +控制picturebox =頭痛。

Public Class InvisibleLabel 
Inherits Label 

Public Sub New() 
    Me.SetStyle(ControlStyles.Opaque, True) 
    Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False) 
End Sub 
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams 
    Get 
     Dim CC As CreateParams = MyBase.CreateParams 
     CC.ExStyle = CC.ExStyle Or &H20 
     Return CC 
    End Get 
End Property 

末級

這是不可見的標籤的代碼,然後我只使用picturebox2.visible =真被點擊的圖像的某些部分時。

+1

擺脫的標籤。只需使用PictureBox的MouseDown事件,檢查座標等。如果你有代碼,那麼是的,發佈它。 – LarsTech

+0

已更新。代碼很簡單,我只是不知道如何處理mousedown事件。 – ShawnB

回答

1

我做了3個文本框

TextBox1中的X '只是給你看

TextBox2中的Y' 只是給你看

CurPicture當前圖片比較

我的PictureBox是300,300

私人小組PictureBox1_MouseClick(發送者爲對象,E作爲MouseEventArgs)處理PictureBox1.MouseClick

Dim LocX As Integer = e.X 
    Dim LocY As Integer = e.Y 
    TextBox1.Text = e.X.ToString 
    TextBox2.Text = e.Y.ToString 

    If LocX > 200 Then ' click right side op the picture , change LocX With LocY to make it bottom 
     If CurPicture.Text = "1" Then 
      PictureBox1.Image = My.Resources.Pic2 
      CurPicture.Text = "2" 
     ElseIf CurPicture.Text = "2" Then 
      PictureBox1.Image = My.Resources.Pic3 
      CurPicture.Text = "3" 
     ElseIf CurPicture.Text = "3" Then 
      PictureBox1.Image = My.Resources.Pic4 
      CurPicture.Text = "4" 
     ElseIf CurPicture.Text = "4" Then 
      PictureBox1.Image = My.Resources.Pic5 
      CurPicture.Text = "5" 
     ElseIf CurPicture.Text = "5" Then 
      PictureBox1.Image = My.Resources.Pic1 
      CurPicture.Text = "1" 
     End If 
    End If 

End Sub 

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    PictureBox1.Image = My.Resources.Pic1 
    CurPicture.Text = "1" 
End Sub 

希望這將有助於你得到的方式:)

1

用途:

Private Sub PictureBox_MouseDown(sender As Object, e As MouseEventArgs) _ 
    Handles PictureBox.MouseDown 

    'The code to change the picture goes here 

End Sub 
+0

但是,我會如何爲特定區域設置?這是獲取我的部分,我知道我可以在右下角看到X,Y,但我將如何使用它來設置點擊區域以執行特定的操作? – ShawnB

+0

完美。謝謝。 – ShawnB