Solved

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

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 50
write xml in vb.net 2 41
VB.net and sql server 4 54
VB.Net Determine if a mapped network drive exists 2 53
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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

735 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