Solved

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

Posted on 2014-03-01
2
740 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

13 Experts available now in Live!

Get 1:1 Help Now