Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:05:59+00:00 2026-06-15T16:05:59+00:00

I created a gradient for my form background but Im having this issue now.

  • 0

I created a gradient for my form background but Im having this issue now. In winforms, when I minimize and then maximize the form i get this:

imageshack.us/photo/my-images/35/errorbl.png.

I guess the bug is that the form has to redraw itself after maximizing and it doesn’t. Somebody knows how to solve it?

Thanks!

Calling gradient:

public Base()
    {
        InitializeComponent();

        this.Paint += new PaintEventHandler(Form_Background);

    }

Gradient method:

public void Form_Background(object sender, PaintEventArgs e)
    {
        Color c1 = Color.FromArgb(255, 252, 254, 255);
        Color c2 = Color.FromArgb(255, 247, 251, 253);
        Color c3 = Color.FromArgb(255, 228, 239, 247);
        Color c4 = Color.FromArgb(255, 217, 228, 238);
        Color c5 = Color.FromArgb(255, 200, 212, 217);
        Color c6 = Color.FromArgb(255, 177, 198, 215);
        Color c7 = Color.FromArgb(255, 166, 186, 208);

        LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle, c1, c7, 90, true);
        ColorBlend cb = new ColorBlend();
        cb.Positions = new[] { 0, (float)0.146, (float)0.317, (float)0.439, (float)0.585, (float)0.797, 1 };
        cb.Colors = new[] { c1, c2, c3, c4, c5, c6, c7 };
        br.InterpolationColors = cb;


        // paint
        e.Graphics.FillRectangle(br, this.ClientRectangle);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:06:00+00:00Added an answer on June 15, 2026 at 4:06 pm

    The reason it does not work is that width and height of this.ClientRectangle is zero after being minimized.

    You need to implement a check of the rectangle before applying any gradient and drawing with it:

    Rectangle r = this.ClientRectangle;
    
    if (r.Width > 0 && r.Height > 0) {
    
        //draw
    
    }
    

    So your code would like something like this:

    public void Form_Background(object sender, PaintEventArgs e) {
    
        Rectangle r = this.ClientRectangle;
    
        if (r.Width > 0 && r.Height > 0) {
    
            Color c1 = Color.FromArgb(252, 254, 255);
            Color c2 = Color.FromArgb(247, 251, 253);
            Color c3 = Color.FromArgb(228, 239, 247);
            Color c4 = Color.FromArgb(217, 228, 238);
            Color c5 = Color.FromArgb(200, 212, 217);
            Color c6 = Color.FromArgb(177, 198, 215);
            Color c7 = Color.FromArgb(166, 186, 208);
    
            LinearGradientBrush br = new LinearGradientBrush(r, c1, c7, 90, true);
            ColorBlend cb = new ColorBlend();
            cb.Positions = new[] { 0, (float)0.146, (float)0.317, _
                                      (float)0.439, (float)0.585, _
                                      (float)0.797, 1 };
    
            cb.Colors = new[] { c1, c2, c3, c4, c5, c6, c7 };
            br.InterpolationColors = cb;
    
            // paint
            e.Graphics.FillRectangle(br, r);
    
            br.Dispose; //added dispose for the brush
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no idea why this is happening, but I created the below code
How can I create a gradient background for my form and text without using
This is the form I need to do: For now I'm in this point:
I've created a linear gradient with following CSS code for a linear gradient: background-color:
Is it possible to create gradient lines like this? background: -webkit-gradient(linear, 0 0, 100%
I have a gradient I really like but I created it using XML drawable:
i created the custom seek bar layout from this , now i am getting
I've created an element that uses repeating-linear-gradient as the background image. At the moment,
In Interface Builder components I have Gradient Button I would like to create this
Here's what I have in VERY simple easy to grasp terms. My form background

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.