Solved

c# panel gradient mode

Posted on 2011-03-12
9
1,246 Views
Last Modified: 2013-12-17
Hi ,

I have a panel whose background color can be gradient color eg. blue.
How can I do it?

Thanks,
JT
0
Comment
Question by:jtran007
9 Comments
 
LVL 6

Expert Comment

by:Webmonkey
ID: 35119259
Well, a [typical] gradient is a fade from one color to another.  Assuming that this is what you were looking for, you would need to look for a property where you can assign the secondary color (the color at the end of the gradient.  Although, I don't remember seeing that as an option for a Panel.  I've only seen this as part of the Chart controls.
0
 

Author Comment

by:jtran007
ID: 35119397
Hi,

I use one of the sample code from this website:
      private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Control control = (Control)sender;
            Graphics g = e.Graphics;
            g.Clear(Color.White);
            Color startColor = Color.FromArgb(106, 127, 156);
            Color endColor = Color.FromArgb(177, 197, 218);
            using (LinearGradientBrush darkBrush = new LinearGradientBrush(control.ClientRectangle, startColor, endColor, LinearGradientMode.Vertical))
            {
                g.FillRectangle(darkBrush, control.ClientRectangle);
            }
        }
 

Open in new window


However I don't see my panel changing color in gradient mode. Could you explain why?

Thanks,
JT
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 35119554
Did you wire up the Paint() event to your handler?
0
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!

 
LVL 6

Expert Comment

by:Webmonkey
ID: 35119883
This is just the definition of a method.  In order for your page to use this method, you'll need to tell the appropriate event handler to call this method.

If you are using Visual Studio, open the page's design view.  Once there select the panel itself, then open the properties tab (normally a "pullout" menu on the right).  From there locate the icon at the top of the properties panel that has a lightening bolt on it - click it.  This will allow you to see the events exposed by this object, as well as any events that have been "wired up" to a specific method.  Locate the "paint" event, and add "panel1_Paint" as it's value.
0
 

Author Comment

by:jtran007
ID: 35121455
Hi,

You are right. It is working ; but in the panel I have a text box whose background color is
shown in solid color. How can I make this text box color gradient too: same as the panel?

Thanks,
JT
0
 
LVL 8

Accepted Solution

by:
dericstone earned 250 total points
ID: 35122817
Do you really want a TextBox control with a gradient background? Because that would make it difficult for users to understand that there is a field to be changed. If you mean to have a Label control with text in it, you can set the background to gradient as follows.
public Form1()
    {
      InitializeComponent();

      this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
      this.BackColor = Color.Transparent;
    }

Open in new window

0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35129642
0
 
LVL 6

Expert Comment

by:Webmonkey
ID: 35153296
but in the panel I have a text box whose background color is shown in solid color. How can I make this text box color gradient too

In all fairness, that should be posted as a separate question.
0
 

Author Closing Comment

by:jtran007
ID: 35284774
Thanks,
JT
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 37
Visual Studio npm 1 29
linq .concat equivalent with expression syntax 4 22
Making exceptions for ValidationAttribute 2 23
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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