Advertisement

04.16.2008 at 10:15PM PDT, ID: 23329825
[x]
Attachment Details

Stopping my custom slider control in a set postion

Asked by davoman in Microsoft Visual Basic.Net, .NET

Hi there I have created a customer slider control

created using the below code kindly provided by Roskins from experts. I have it working as asked but just need to move it on a little so that I can get it to snap to a place of my choice.

Ie when a user moves it so far across it actually goes into a set place when they let go. (As if there were actaully only ten positions the slider could go to)

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
 Public Class UserControl1
 
    Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not MoveImage Is Nothing Then
            X1 = (Me.Width / 2) - (MoveImage.Width / 2)
            X2 = (Me.Width / 2) + (MoveImage.Width / 2)
            Y1 = (Me.Height / 2) - (MoveImage.Height / 2)
            Y2 = (Me.Height / 2) + (MoveImage.Height / 2)
            Invalidate()
        End If
    End Sub
    Dim X1, X2, Y1, Y2 As Integer 'For finding out where the Pointer will be relative to the cursor. 
    Dim IsMouseDown As Boolean 'Is the cursor pressed down.
    Private MoveImage As Bitmap
    Public Property PointerImage() As Bitmap
        Get
            Return MoveImage
        End Get
        Set(ByVal value As Bitmap)
            MoveImage = value
        End Set
    End Property
 
    Private Sub UserControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        IsMouseDown = True
    End Sub
 
    Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If IsMouseDown = True Then
            If X1 < 300 And X1 > 0 Then
                X1 = e.X - MoveImage.Width / 2
                Invalidate()
            ElseIf X1 > 299 Then
                X1 = e.X - MoveImage.Width / 2
                Invalidate()
            End If
        End If
    End Sub
 
    Private Sub UserControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        IsMouseDown = False
    End Sub
 
    Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        If Not MoveImage Is Nothing Then
            e.Graphics.DrawImage(MoveImage, New PointF(X1, Y1))
        End If
    End Sub
End Class
 
Keywords: Stopping my custom slider control in a …
 
Loading Advertisement...
 
[+][-]04.17.2008 at 06:31AM PDT, ID: 21376794

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, .NET
Sign Up Now!
Solution Provided By: roshkins
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.17.2008 at 09:14AM PDT, ID: 21378699

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628