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




Reply With Quote