---
title: "How to split form background color in C Sharp"  
description: "How to split form background color in C SharpThis will change Windows form back color according to Button Click.  Controls NameButton Red: btnRedBlu"  
author: "Anonymous User"  
published: 2010-08-02  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to split form background color in C Sharp

## How to split form background color in C Sharp

This will change Windows form back color according to Button Click.\

![How to split form background color in C Sharp](https://www.mindstick.com/mindstickarticle/4891b1bf-71c3-4d2f-b2d7-8916644334e2/images/161fd429-eb0b-49f9-90d5-e7009ef9d9db.png)

[Controls Name](https://www.mindstick.com/articles/1117/crud-operation-using-modal-dialog-in-asp-dot-net-mvc)

Button Red: btnRed

Blue: btnBlue

Split: btnSplit

Reset: btnReset

##### Code

```
   bool check; //boolean variable to check whether split is clicked or not.//function to split form background color  private void fnSplit()        {                        Graphics surface = this.CreateGraphics();surface.FillRectangle(new SolidBrush(Color.Red), 0, 0, (this.Width) / 2, this.Height);//drawing filled rectangle of red color on form left half side with width equal to half of form//width andheigth equalto the height of form. surface.FillRectangle(new SolidBrush(Color.Blue), (this.Width) / 2, 0, (this.Width) / 2, this.Height);//drawing another rectanfle of blue color on other hand of the form of same dimension as that of firstrectangle.        } //changing form background color to red on Red button click        private void btnRed_Click(object sender, EventArgs e)        {            this.BackColor = Color.Red;//setting background color to red.            check = false;                   }
```

![How to split form background color in C Sharp](https://www.mindstick.com/mindstickarticle/4891b1bf-71c3-4d2f-b2d7-8916644334e2/images/792faf4f-6c1d-4c8a-a539-d27ebab32e08.png)

```
//changing form background color to blue on Blue button click        private void btnBlue_Click(object sender, EventArgs e)        {            this.BackColor = Color.Blue;//setting background color to red.            check = false;                  } 
```

![How to split form background color in C Sharp](https://www.mindstick.com/mindstickarticle/4891b1bf-71c3-4d2f-b2d7-8916644334e2/images/b907e494-7e08-44f3-be01-1328483ae87d.png)

```
//spliting form background color on Split button click        private void btnSplit_Click(object sender, EventArgs e)        {                        fnSplit();//Calling function to split form color.            check = true;//assigning true to check.        }
```

![How to split form background color in C Sharp](https://www.mindstick.com/mindstickarticle/4891b1bf-71c3-4d2f-b2d7-8916644334e2/images/0db3d7fa-3ba0-41f0-936f-3a453ed61e2e.png)

```
        private void frmColor_SizeChanged(object sender, EventArgs e)        {            if(check)                fnSplit();        //calling fnSplit() function is form background color is already split on form resize event.        }          //this is reset the form bolor to its default color.        private void btnReset_Click(object sender, EventArgs e)        {                       this.BackColor = DefaultBackColor;            if (check)            {                this.Refresh();                this.BackColor = DefaultBackColor;            }        }   
```

![How to split form background color in C Sharp](https://www.mindstick.com/mindstickarticle/4891b1bf-71c3-4d2f-b2d7-8916644334e2/images/ade5aa30-b2ba-4155-a73a-cd40ad5c9e91.png)

\

---

Original Source: https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
