Results 1 to 3 of 3

Thread: using gradients on controls

  1. #1

    Thread Starter
    Addicted Member Porsche944's Avatar
    Join Date
    Apr 2005
    Location
    Ann Arbor
    Posts
    182

    using gradients on controls

    Is it possible to use a gradient on a control such as a group box or a command button? I have not been able to find out any information on this subjet on google. Does anyone have a good website i could take a look at that might point me in the right direction.

    Perhaps a custom control that has this funcionality ?

    Thank you

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: using gradients on controls

    As it happens I am working on a custom button myself that allows you to set custom gradients for each state (pressed, mouseover, enabled, disabled) and also some other visual properties. Functionality is not fully complete but if you want a look, email me.
    (I mean send me your address)
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  3. #3
    Fanatic Member
    Join Date
    May 2005
    Posts
    530

    Re: using gradients on controls

    If you put a groupbox on a form and a button in the groupbox, paste this code in and it should work. The only strange behavior with this I wasn't able to get rid of was that the text background of the groupbox was the same as the secondary color of the gradient. If you don't care about that, it will work as shown. Otherwise, you'll have to play with it a bit.

    VB Code:
    1. Imports System.Drawing.Drawing2D
    2. Public Class Form1
    3.     Inherits System.Windows.Forms.Form
    4.  
    5. 'windows form designer code will be here
    6.  
    7.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.         'This button doesn't do anything.  Just here to show control sitting on top of background
    9.     End Sub
    10.  
    11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    12.         Dim objRectangle1 As Rectangle = New Rectangle(0, 0, GroupBox1.Width, GroupBox1.Height)
    13.         Dim objBrush1 As Brush = New LinearGradientBrush(objRectangle1, Color.White, Color.LightSeaGreen, _
    14.                                     LinearGradientMode.ForwardDiagonal)
    15.         Dim objBitmap1 As Bitmap = New Bitmap(GroupBox1.Width, GroupBox1.Height)
    16.         Dim objGraphics1 As Graphics = Graphics.FromImage(objBitmap1)
    17.         objGraphics1.FillRectangle(objBrush1, objRectangle1)
    18.         GroupBox1.BackgroundImage = objBitmap1
    19.  
    20.         Dim objRectangle2 As Rectangle = New Rectangle(1, 1, Button1.Width - 2, Button1.Height - 2)
    21.         Dim objBrush2 As Brush = New LinearGradientBrush(objRectangle2, Color.LightBlue, Color.LightCoral, LinearGradientMode.ForwardDiagonal)
    22.         Dim objBitmap2 As Bitmap = New Bitmap(Button1.Width - 2, Button1.Height - 2)
    23.         Dim objGraphics2 As Graphics = Graphics.FromImage(objBitmap2)
    24.         objGraphics2.FillRectangle(objBrush2, objRectangle2)
    25.         Button1.BackgroundImage = objBitmap2
    26.     End Sub
    27. End Class

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