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 :)
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)
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:
Imports System.Drawing.Drawing2D
Public Class Form1
Inherits System.Windows.Forms.Form
'windows form designer code will be here
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'This button doesn't do anything. Just here to show control sitting on top of background
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objRectangle1 As Rectangle = New Rectangle(0, 0, GroupBox1.Width, GroupBox1.Height)
Dim objBrush1 As Brush = New LinearGradientBrush(objRectangle1, Color.White, Color.LightSeaGreen, _
LinearGradientMode.ForwardDiagonal)
Dim objBitmap1 As Bitmap = New Bitmap(GroupBox1.Width, GroupBox1.Height)
Dim objGraphics1 As Graphics = Graphics.FromImage(objBitmap1)
objGraphics1.FillRectangle(objBrush1, objRectangle1)
GroupBox1.BackgroundImage = objBitmap1
Dim objRectangle2 As Rectangle = New Rectangle(1, 1, Button1.Width - 2, Button1.Height - 2)
Dim objBrush2 As Brush = New LinearGradientBrush(objRectangle2, Color.LightBlue, Color.LightCoral, LinearGradientMode.ForwardDiagonal)
Dim objBitmap2 As Bitmap = New Bitmap(Button1.Width - 2, Button1.Height - 2)
Dim objGraphics2 As Graphics = Graphics.FromImage(objBitmap2)
objGraphics2.FillRectangle(objBrush2, objRectangle2)
Button1.BackgroundImage = objBitmap2
End Sub
End Class