Solved

c# panel gradient mode

Posted on 2011-03-12
9
1,258 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
[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
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 86

Expert Comment

by:Mike Tomlinson
ID: 35119554
Did you wire up the Paint() event to your handler?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

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