?
Solved

c# panel gradient mode

Posted on 2011-03-12
9
Medium Priority
?
1,328 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 1000 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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