Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-03-01
2
Medium Priority
?
904 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:Murray Brown
[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 2000 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:Murray Brown
ID: 39897359
Thanks very much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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