hi
How do you copy the gradient color??
Printable View
hi
How do you copy the gradient color??
What gradient color?
This has no meaning unless you specify which gradient color you mean and what you want to do with itQuote:
How do you copy the gradient color??
hi
What do I mean by color gradient?
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.
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
Thank you
But I still hope for help from everyone
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?Quote:
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
That's not possible.
Your English must be even more limited than mine.
Your answer makes no sense.
Yes please to what?
No need to apologize, just use more words to describe what you want to do.
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
Do you want to color the command button or do you want perform the color action when the command button is clicked?
It is not possible with the VB buttons.
The alternative is to use some other button, but that is somewhat advanced.
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.
thanks a lot