Results 1 to 9 of 9

Thread: How do you do this?

  1. #1
    Guest

    Question

    I have made an activex control that is a progress bar but WAY better looking than the one that comes with vb5. this progress bar uses a gradient as the indicator of progress instead of those stupid HIGHLY unaccurate boxes. anyways, i have a property for the control that has preset gradients made for it, such as "white to black" which the gradient starts white and ends black, also "red to green", "blue to yellow" and etc. but i also want to add a new property where the user of the control can choose the start color and end color in the properties. for example, the property "grad_start" can be clicked on so you can choose a color as if it is the "backcolor" control, also the property "grad_end" will be the same. now once the user choose two colors, i want it to make a gradient from the "grad_start" color to the "grad_end" color. how would i do this? i hope you understand what im trying to do, if you dont totally get me then tell me so i can ******** myself.

    so again, the user picks the start and ending color of the gradient, how would i make a gradient going from those two colors? thanks

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    how did you do it the first time?
    i.e from white to black?

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Smile

    This is a simple matter of math. Havent tested it yet but this shoud work: Thefirstcolor*(x/scalewidth) + Thelastcolor*(1-(x/scalewidth))
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    try this instead, this works:
    Code:
    Function colormix(color1 As Long, color2 As Long, fade)
        colormix = RGB((color1 Mod 256) * fade + (color2 Mod 256) * (1 - fade), (Int(color1 / 256) Mod 256) * fade + (Int(color2 / 256) Mod 256) * (1 - fade), Int(color1 / 65536) * fade + Int(color2 / 65536) * (1 - fade))
    End Function
    
    Private Sub Form_Resize()
        thefirstcolor& = vbRed
        thelastcolor& = vbYellow
        For x = 0 To ScaleWidth Step 15
            a = colormix(thefirstcolor&, thelastcolor&, x / ScaleWidth)
            Line (x, 0)-(x, ScaleHeight), a
        Next x
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Guest

    woah thanks

    this works but i dont get what the function is doing. can you explain in a little more basic terms what that formula is doing to the colors? thanks for the code.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    well color is a long data type that is Red+Green*2^8+Blue*2^16
    the whole thing is 24 bit
    the colorcomponents are from 0 upto 255
    my function just mixes these parts with simple math
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Guest

    oh ok, but i found a bug

    oh ok i get you, i just didn't understand how VB came up with those very large numbers for white or yellow, etc. anyways i found a bug in your code. when you change the:

    For x = 0 To ScaleWidth Step 15

    to

    For x = -500 To 500 Step 15

    then the fade doesn't start untill the very end, so it wont fade all the way. on my control you can set the "min" and ",ax" properties just like the progress bar but the gradient doesn't come out right if my min is a negative number. how would i fix this? if you dont understand what im trying to say then please reply and ill make my self more clear. thanks again

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    OK, i don't understand. Post me some more code, were does te bug appear, huh?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Guest
    you know the regular progress bars that come with vb5 or 6? well those have a property called min and max, and so does my control. now when i set the max to lets say 500 and my min to -500 then the gradient does not come out right. i can change the max to any number and it still will come out ok, but as soon as i put the min to a negative number, the gradient gets shifted more to the right so the ending color doesn't show as much or the gradient barely starts by the time it reaches the end. also when i set the min to around 100 or more, it will crash on the colormix function, i am not sure how to fix this either.

    if you still cant figuer out how to fix this problem, i could send you my control source so you can see how it works, and maybe that might help. so you want the source?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width