6

3 つの画像ボックスを含む新しいフォームを作成します。このコードは、マウスが画像ボックスに入ると境界線を描画し、離れるとそれを削除することを目的としています。結果に矛盾があります。境界線を描画/削除する場合もあれば、そうでない場合もあります。このコードは複雑ではありません。VS 2012 を使用しています。

Private Sub PictureBox_MouseEnter(sender As Object, e As EventArgs) _
    Handles PictureBox1.MouseEnter, PictureBox2.MouseEnter, PictureBox3.MouseEnter
    Dim pb As PictureBox = DirectCast(sender, PictureBox)
    pb.BorderStyle = BorderStyle.FixedSingle
    ' Debug.WriteLine("E " & pb.Name)
End Sub

Private Sub PictureBox_MouseLeave(sender As Object, e As EventArgs) _
    Handles PictureBox1.MouseLeave, PictureBox2.MouseLeave, PictureBox3.MouseLeave

    Dim pb As PictureBox = DirectCast(sender, PictureBox)
    pb.BorderStyle = BorderStyle.None
    ' Debug.WriteLine("X " & pb.Name)
End Sub
4

3 に答える 3

1

問題を再現することもできました。したがって、Picturebox のプロパティを使用する代わりに「何か他のものを描画する」という上記のコメントを拡張して、この迅速で汚いアプローチを提案させてください。

  • VisualBasic Powerpack 3.0アドオンによって提供される RectangleShape オブジェクトを使用します。それらの 1 つを PictureBox と同じフォームに配置し、非表示 (visible = false) にします。

  • コードも簡単です。

    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.RectangleShape1.Location = New Point(Me.PictureBox1.Left - 1, Me.PictureBox1.Top - 1)
            Me.RectangleShape1.Size = New Size(Me.PictureBox1.Width + 1, Me.PictureBox1.Height + 1)
        End Sub
    
        Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
            Me.RectangleShape1.Visible = True
        End Sub
        Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
            Me.RectangleShape1.Visible = False
        End Sub
    End Class
    
于 2013-06-07T01:51:46.983 に答える
0

Form MouseEnter Event からの助けが必要です..

Dim pb As PictureBox = New PictureBox

Private Sub Form1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
   pb.BorderStyle = BorderStyle.None
End Sub

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

   pb = PictureBox1
   pb.BorderStyle = BorderStyle.FixedSingle

End Sub
于 2013-06-07T03:05:41.740 に答える
0

私は自分のピクチャボックスをパネル内に置くことでKalaNagのアイデアに従い、このようにしてピクチャボックスでイベントを処理しました

private void PictureBox_MouseEnter(object sender, EventArgs e)
    {
        PictureBox control = sender as PictureBox;

        (control.Parent as Panel).Width = 20;
        (control.Parent as Panel).Height = 20;
        (control.Parent as Panel).BorderStyle = BorderStyle.Fixed3D;

    }

    private void PictureBox_MouseLeave(object sender, EventArgs e)
    {
        PictureBox control = sender as PictureBox;

        (control.Parent as Panel).Width = 18;
        (control.Parent as Panel).Height = 18;
        (control.Parent as Panel).BorderStyle = BorderStyle.None;

    }

コントロールのサイズを変更しました。そうしないと、境界線がコントロールのサイズを変更するため、カーソルが境界線に出入りするときにマウスが境界線に乗ったときにピクチャボックスがちらつき続けるためです。

魅力のように動作します!

于 2013-12-05T16:51:06.763 に答える