Results 1 to 23 of 23

Thread: How do you copy the gradient color??

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Question How do you copy the gradient color??

    hi
    How do you copy the gradient color??

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do you copy the gradient color??

    What gradient color?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by dilettante View Post
    What gradient color?
    What color gradation?

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    How do you copy the gradient color??
    This has no meaning unless you specify which gradient color you mean and what you want to do with it

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    hi
    What do I mean by color gradient?
    Attached Images Attached Images  

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    For a gradient you need at least 2 colors.
    The startcolor and the endcolor.
    You can not compute the gradient from a single given pixel.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by Arnoutdv View Post
    For a gradient you need at least 2 colors.
    The startcolor and the endcolor.
    You can not compute the gradient from a single given pixel.
    --------------------------------------------------------------------
    Yes, this is what I want

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    No copy, because I still don't get what you want to copy.
    But just a routine to draw a gradient bar, just with basic VB6 commands
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Me.BackColor = vbWhite
      Me.ForeColor = vbBlack
      Me.ScaleMode = vbPixels
      Me.Show
      Me.Print "Click the form"
    End Sub
    
    Private Sub Form_Click()
      Dim lStartColor As Long, lEndColor As Long
      Dim lGradientColor As Long
      Dim i As Long
      
      lStartColor = RGB(31, 191, 31)
      lEndColor = RGB(191, 31, 31)
      
      For i = 0 To 99
        lGradientColor = BlendColor(lStartColor, lEndColor, i)
        Line (0, i)-(200, i), lGradientColor
      Next i
      
    End Sub
    
    Private Function BlendColor(ByVal lColor1 As Long, lColor2 As Long, ByVal dPerc As Double) As Long
      Dim iR As Integer, iG As Integer, iB As Integer
      Dim iR1 As Integer, iG1 As Integer, iB1 As Integer
      Dim iR2 As Integer, iG2 As Integer, iB2 As Integer
      Dim dS1 As Double, dS2 As Double
      
      ' Translate to color to the RGB values
      ColorToRGB lColor1, iR1, iG1, iB1
      ColorToRGB lColor2, iR2, iG2, iB2
    
      ' Merging the 2 colors
      dS2 = dPerc / 100 ' share for color 2
      dS1 = 1 - dS2     ' share for color 1
      
      ' Create the new RGB values
      iR = iR1 * dS1 + iR2 * dS2
      iG = iG1 * dS1 + iG2 * dS2
      iB = iB1 * dS1 + iB2 * dS2
      
      ' Return the color value
      BlendColor = RGB(iR, iG, iB)
    End Function
    
    Public Function ColorToRGB(lColorCode As Long, ByRef iRed As Integer, ByRef iGreen As Integer, ByRef iBlue As Integer) As Boolean
      Dim lColor As Long
      
      On Error GoTo ColorToRGB_Error
    
      iRed = lColorCode And &HFF
      iGreen = (lColorCode And &HFF00&) \ &H100&
      iBlue = (lColorCode And &HFF0000) \ &H10000
    
      ColorToRGB = True
    
    ColorToRGB_Error:
      On Error GoTo 0
    
    End Function

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Thank you
    But I still hope for help from everyone

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    But what is your question??

    You want to get gradient color, but that doesn't mean anything.
    Me:
    For a gradient you need at least 2 colors.
    The startcolor and the endcolor.
    You can not compute the gradient from a single given pixel.

    You:
    Yes, this is what I want
    You want to get the startcolor and the endcolor from a single pixel?
    That's not possible.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by Arnoutdv View Post
    But what is your question??

    You want to get gradient color, but that doesn't mean anything.

    You want to get the startcolor and the endcolor from a single pixel?
    That's not possible.
    ------------------------------------------------
    Yes, if you please

  12. #12
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    Your English must be even more limited than mine.
    Your answer makes no sense.

    Yes please to what?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by Arnoutdv View Post
    Your English must be even more limited than mine.
    Your answer makes no sense.

    Yes please to what?
    I am sorry

  14. #14
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    No need to apologize, just use more words to describe what you want to do.

    You can use Google Translate if it helps you

  15. #15
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    Re: How do you copy the gradient color??

    Quote Originally Posted by Arnoutdv View Post
    You can use Google Translate if it helps you
    Yes, when the English is too limited, Google translate will most of the times produce a better result than trying to write directly in English (or whatever language).

    About the question, I'm not sure whether he wants to get some color (From Windows? From other program?) or to "get" a form to show with a gradient background, I think most probably tit is the second.

    Code:
    Private Sub Form_Resize()
        Dim l As Long
        Dim w As Single
        Dim h As Single
        Dim p1 As Byte
        Dim p2 As Byte
        Dim r1 As Byte
        Dim g1 As Byte
        Dim b1 As Byte
        Dim r2 As Byte
        Dim g2 As Byte
        Dim b2 As Byte
        Dim Color1 As Long
        Dim Color2 As Long
        
        Color1 = 15457228
        Color2 = 16315377
    
        r1 = Color1 And 255: g1 = (Color1 \ 256) And 255: b1 = (Color1 \ 65536) And 255
        r2 = Color2 And 255: g2 = (Color2 \ 256) And 255: b2 = (Color2 \ 65536) And 255
    
        Me.AutoRedraw = True
        w = Me.ScaleWidth
        h = Me.ScaleHeight
        For l = 0 To Me.ScaleWidth Step Me.ScaleX(1, vbPixels, Me.ScaleMode)
            p1 = 255 / w * l
            p2 = 255 - p1
            Me.Line (l, 0)-(l, h), RGB(r1 / 255 * p1 + r2 / 255 * p2, g1 / 255 * p1 + g2 / 255 * p2, b1 / 255 * p1 + b2 / 255 * p2)
        Next
        Me.AutoRedraw = False
    End Sub

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by Eduardo- View Post
    Yes, when the English is too limited, Google translate will most of the times produce a better result than trying to write directly in English (or whatever language).

    About the question, I'm not sure whether he wants to get some color (From Windows? From other program?) or to "get" a form to show with a gradient background, I think most probably tit is the second.

    Code:
    Private Sub Form_Resize()
        Dim l As Long
        Dim w As Single
        Dim h As Single
        Dim p1 As Byte
        Dim p2 As Byte
        Dim r1 As Byte
        Dim g1 As Byte
        Dim b1 As Byte
        Dim r2 As Byte
        Dim g2 As Byte
        Dim b2 As Byte
        Dim Color1 As Long
        Dim Color2 As Long
        
        Color1 = 15457228
        Color2 = 16315377
    
        r1 = Color1 And 255: g1 = (Color1 \ 256) And 255: b1 = (Color1 \ 65536) And 255
        r2 = Color2 And 255: g2 = (Color2 \ 256) And 255: b2 = (Color2 \ 65536) And 255
    
        Me.AutoRedraw = True
        w = Me.ScaleWidth
        h = Me.ScaleHeight
        For l = 0 To Me.ScaleWidth Step Me.ScaleX(1, vbPixels, Me.ScaleMode)
            p1 = 255 / w * l
            p2 = 255 - p1
            Me.Line (l, 0)-(l, h), RGB(r1 / 255 * p1 + r2 / 255 * p2, g1 / 255 * p1 + g2 / 255 * p2, b1 / 255 * p1 + b2 / 255 * p2)
        Next
        Me.AutoRedraw = False
    End Sub
    --------------------------------------------------------------------------

    hi

    beautiful thank you
    Can this be applied to the command button?

  17. #17
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    Re: How do you copy the gradient color??

    Do you want to color the command button or do you want perform the color action when the command button is clicked?

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by Arnoutdv View Post
    Do you want to color the command button or do you want perform the color action when the command button is clicked?
    I want to color the buttons

  19. #19
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    Re: How do you copy the gradient color??

    Quote Originally Posted by Mysystem View Post
    I want to color the buttons
    It is not possible with the VB buttons.
    The alternative is to use some other button, but that is somewhat advanced.

  20. #20
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: How do you copy the gradient color??

    I have never tried it but I would think it would be possible with the vb command button if you set its style to graphical. I'm not sure it can be colored directly but you could create a gradient bitmap and set it as the picture of the button. I would think that would work but again have not tried it.

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    Quote Originally Posted by Eduardo- View Post
    It is not possible with the VB buttons.
    The alternative is to use some other button, but that is somewhat advanced.
    -----------------------------------------------------------------------------
    hi

    Can this be done with the included tools ?
    Attached Files Attached Files
    • File Type: 7z ms.7z (680.9 KB, 45 views)

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Question Re: How do you copy the gradient color??

    Quote Originally Posted by DataMiser View Post
    I have never tried it but I would think it would be possible with the vb command button if you set its style to graphical. I'm not sure it can be colored directly but you could create a gradient bitmap and set it as the picture of the button. I would think that would work but again have not tried it.
    ----------------------------------------------------------------------

    hi

    Can this be done with the included tools ?
    Attached Files Attached Files
    • File Type: 7z ms.7z (680.9 KB, 61 views)

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2021
    Posts
    257

    Re: How do you copy the gradient color??

    thanks a lot

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