Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

custom control in form click event not firing

$
0
0
Hi All,

I have a custom user control which has an image and a button on it. this works as expected. however when I put it on a form, then double click it and select click event, it never fires. is this something to do with custom controls?

seems weird as i have other custom controls that i use as buttons that work fine this way.

the code behind the custom control is
Code:

Public Class slider
    Dim asd As Boolean
    Dim xs As Integer
    Dim dsa As Integer
    Public sety As Boolean

    Private Sub Button1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        asd = True
        Dim MousePosition As Point
        MousePosition = Cursor.Position
        xs = MousePosition.X
    End Sub

    Private Sub Button1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
        If asd = True Then
            Dim MousePosition As Point
            MousePosition = Cursor.Position
            dsa = MousePosition.X
            Dim movem As Integer

            If dsa < xs Then
                movem = (xs - dsa)
                If Button1.Left <= PictureBox1.Left Then
                    Button1.Left = PictureBox1.Left

                Else
                    Button1.Left = Button1.Left - movem

                End If
            ElseIf dsa > xs Then
                movem = (dsa - xs)
                If (Button1.Left + Button1.Width) >= (PictureBox1.Left + PictureBox1.Width) Then
                    Button1.Left = ((PictureBox1.Left + PictureBox1.Width) - Button1.Width)
                Else
                    Button1.Left = Button1.Left + movem

                End If
            End If
            xs = MousePosition.X
        End If
    End Sub

    Private Sub Button1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
        asd = False
        Dim midimage As Integer
        Dim midbutt As Integer
        midbutt = (Button1.Width / 2)
        midimage = (PictureBox1.Width / 2)
        midbutt = Button1.Left + midbutt
        midimage = PictureBox1.Left + midimage

        If midbutt <= midimage Then
            Button1.Left = PictureBox1.Left
            sety = False
        End If


        If midbutt > midimage Then
            Button1.Left = ((PictureBox1.Left + PictureBox1.Width) - Button1.Width)
            sety = True
        End If
     
    End Sub
    Public Sub onme()
        Button1.Left = (PictureBox1.Left + PictureBox1.Width) - Button1.Width
        sety = True
    End Sub
    Public Sub offme()
        Button1.Left = PictureBox1.Left
        sety = False
    End Sub

    Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
        If Button1.Left = PictureBox1.Left Then
            sety = True
            Button1.Left = ((PictureBox1.Left + PictureBox1.Width) - Button1.Width)
        Else
            sety = False
            Button1.Left = PictureBox1.Left
        End If
    End Sub
End Class

the control is basically an on off switch

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>