|
-
Dec 19th, 2001, 07:29 AM
#1
Thread Starter
PowerPoster
Math Problem
Hi. I am trying to make a Vscroll type OCX. I have everything finished except figuring out how to drag the slider with the mouse and have it figure its place on the bar and turn that into a value between the minimum which is usualy 0 and the Max which could be anything but is set to 500 for this example.
I can drag the slider img up and down no problem. But figuring out the math to get the Value of the slider is hard. I've tried using the .top property divided by the Userontrol.height etc... and can't get anything reliebale.
I have attached a small .jpg so you can see the control and get an idea of what i am talking about.
Here is an idea of the code i am using as well.
VB Code:
Private Sub imgSLIDER_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
imgSLIDER.Move imgSLIDER.Left - 0, imgSLIDER.Top - (prevY - Y)
m_Value = imgSLIDER.Top - Usercontrol.Height - ImgUP.Height - imgSLIDER.Height - ImgDOWN.Height / m_Max / 2
RaiseEvent Scroll
End If
End Sub
m_Value is the current value of the slider which is somewhere between the M_Min and M_Max values 0-500 for this example.
Imgup, ImgDown and ImgSlider are the 3 images on the control.
THanks alot for any help!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 19th, 2001, 07:37 AM
#2
Hyperactive Member
Why can't you just use the scroll bars value property?
-
Dec 19th, 2001, 07:44 AM
#3
Thread Starter
PowerPoster
Huh?
You obviously dont understand. THis scroll baris being made by me. It doesnt have a scroll value property yet. THat's what i am trying to make.
It does have the change porperty. Meaning if i push the up or down buttons the slider will move and the value does change exactly like it is suppost to. But i am having trouble figuring out how to accomplish the same thing while draging the slider with the mouse...
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 19th, 2001, 08:17 AM
#4
Hyperactive Member
Oh sorry, I'll have a go and see if i can come up with anything
-
Dec 19th, 2001, 08:58 AM
#5
Thread Starter
PowerPoster
Thanks
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 19th, 2001, 09:07 AM
#6
Hyperactive Member
Try this, i haven't tried it as I domn't have your project, but mathematically it shouild work:
controlRange=(ImgDown.Top-(imgSLIDER.Height/2))-((UserControl.Top + ImgUp.Height) + (imgSLIDER.Height/2))
scrollValue= (imgSlider.top+(imgSLIDEER.Height/2)/scrollRange)*(mMax-mMin)
(I assume it imgUp is the top button and imgDown is the bottom button)
-
Dec 19th, 2001, 09:29 AM
#7
Thread Starter
PowerPoster
Nope, doesnt work. Anything based off the .top value od the slider isnt going to work because the top value will be radically different depending on the size of the control.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Dec 19th, 2001, 09:34 AM
#8
Hyperactive Member
The difference shouldn't matter, as this calculates the range that the control can reach and then works out the value by division.
could you send me the code for the OCX?
-
Dec 19th, 2001, 11:26 AM
#9
Hyperactive Member
This works, I tried it out
controlrange = (imgDown.Top - (imgSLIDER.Height / 2)) - ((imgUp.Top + imgUp.Height) + (imgSLIDER.Height / 2))
scrollvalue = ((imgSLIDER.Top + (imgSLIDER.Height / 2)) - (imgUp.Top + imgUp.Height + (imgSLIDER.Height / 2))) / controlrange * (mMax - mMin)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|