Solved

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

Posted on 2014-03-01
2
814 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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