Solved

VB.net Coloring a panel with a gradient on a button click

Posted on 2014-03-01
2
716 Views
Last Modified: 2014-03-01
Hi

I am using the following code to allow a user to select a color from the color picker that
in turn colors a panel. How do I color the panel using a gradient similar to that shown in the code further on

    Private Sub btnChartAreaColor_Click(sender As System.Object, e As System.EventArgs) Handles btnChartAreaColor.Click
        Me.ColorDialog1.ShowDialog()
        Me.pChartAreaColor.BackColor = Me.ColorDialog1.Color

    End Sub



    Private Sub ChartBackColor_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs)
        Dim graphics As Graphics = e.Graphics()

        Dim rectBrush As New System.Drawing.Rectangle(0, 0, 46, 46)
        Dim brush As LinearGradientBrush
        brush = New LinearGradientBrush(rectBrush, Color.FromArgb(46, 100, 160), _
                        Color.White, LinearGradientMode.Horizontal)
        graphics.FillRectangle(brush, rectBrush)
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39897350
something like this?

    Private _newColor As Color

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim d As New ColorDialog
        d.ShowDialog()
        _newColor = d.Color
        Panel1.Invalidate()
    End Sub

    Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
        Dim graphics As Graphics = e.Graphics()

        Dim rectBrush As New Rectangle(0, 0, Panel1.Width, Panel1.Height)
        Dim brush As LinearGradientBrush
        brush = New LinearGradientBrush(rectBrush, _newColor, Color.White, LinearGradientMode.Horizontal)
        graphics.FillRectangle(brush, rectBrush)
    End Sub
0
 

Author Closing Comment

by:murbro
ID: 39897359
Thanks very much
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server 2008 Error 7 56
Library to convert HTML to PDF. 8 46
Showdialog 8 21
Get Count in a variable with 5 digits always 1 17
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now