Solved

c# panel gradient mode

Posted on 2011-03-12
9
1,207 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
Comment Utility
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
Comment Utility
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
Comment Utility
Did you wire up the Paint() event to your handler?
0
 
LVL 6

Expert Comment

by:Webmonkey
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jtran007
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 6

Expert Comment

by:Webmonkey
Comment Utility
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
Comment Utility
Thanks,
JT
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now