Results 1 to 6 of 6

Thread: Draw Panel Gradient [Resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    Question Draw Panel Gradient [Resolved]

    Greetings all,

    I need code modification help for the code below. It's part of a gradient draw on a form but I want to use custom colors in HEX
    like below or the translated RGB format instead of the standard Green to Pale Green etc.. format. Any examples how it could be done?

    Code:
    Private Sub DrawGradient(ByVal color1 As Color, ByVal color2 As Color, ByVal mode As System.Drawing.Drawing2D.LinearGradientMode)
            Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New RectangleF(0, 0, Me.Width, Me.Height), color1, color2, mode)
            Dim g As Graphics = Me.CreateGraphics
            g.FillRectangle(a, New RectangleF(0, 0, Me.Width, Me.Height))
            g.Dispose()
        End Sub
    
    Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
            DrawGradient(Color.#33CC33, Color.#009900, Drawing.Drawing2D.LinearGradientMode.Vertical)
        End Sub
    Last edited by teamdad; Aug 3rd, 2004 at 01:09 PM.

  2. #2
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Hi,

    If you want to use a hexadecimal integer values, simply add the phrase "&H" which means "The upcoming values are in the hexadecimal number base..." before the hex number:
    Code:
    &H92FE67B   154134139   The compiler treats these two values alike.
    So, for example if you want Red you will use:
    VB Code:
    1. Color.FromArgb(255,0 ,0 , &HFF)

    If like this, because the hexadecimal values for colors like markup languages are easier to work with

    Extra Tip:Also if you want to use octal values, add the &O (this is an "O" letter, not zero) phrase before the number:
    Code:
    &O626452   208170   The compiler treats these two values alike.
    Last edited by TLord; Jul 24th, 2004 at 04:14 PM.
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Not sure if i'm doing it right or if there's another problem. Still gives a syntax error. Keep in mind this is a gradient draw.

    Code:
    DrawGradient(Color.&H33CC33, Color&H009900, Drawing.Drawing2D.LinearGradientMode.Vertical)

  4. #4
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Originally posted by teamdad
    Not sure if i'm doing it right or if there's another problem. Still gives a syntax error. Keep in mind this is a gradient draw.

    Code:
    DrawGradient(Color.&H33CC33, Color&H009900, Drawing.Drawing2D.LinearGradientMode.Vertical)
    You can't use these values directly for colors, use the Color.FromArgb function and there put the hexadecimal value of each color.
    Code:
    DrawGradient(Color.FromArgb(255, &H33, &HCC, &H33), Color.FromArgb(255, 0, &H99, 0), Drawing.Drawing2D.LinearGradientMode.Vertical)
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    All right!!! it works like a charm. I never accused myself of being intelligent but just smart enough to get by with. LOL

    While i'm at it with this gradient stuff.... all my label's on the form are set to Tranparent backgrounds but they still show the grey control color the background of the form has for some reason.

    It's like the label's just don't accept the fact that you want them to let you see through to the colors of the gradient and not all the way through the gradient to the form color or something.
    Last edited by teamdad; Jul 25th, 2004 at 09:20 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Well... after researching with Pirate's favorite tool "Google" I have discovered an inheritance issue is what's causing my labels to see thru the gradient I have drawn on the face of the form thus showing the true color of the form beneath the gradient and causing me problems.

    Now, short of trying to hatch an uprising of Visual Basic Power Pack that can be used with VB.NET 2002 "don't think it'll happen" it only works with VS.NET 2002 and VB.NET 2003; I need help drawing the gradient on a panel instead of on the form itself. This should fix the inheritance problem by allowing the transparent property of a label placed on the panel to show the true color of the gradient beneath it instead of the inherited color of the form itself.

    That's the plan anyway....

    Think it'll work ?? anyone have a refrence how I can draw the gradient on the panel and i'll test it out.

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