Two Color Shadded Background in Form C#

No.of Views1266
Bookmarked3 times
Downloads 
Votes0
By  kirtan007   On  16 Feb 2010 00:02:48
Tag : CSharp , Windows Forms
Two Color Shadded Background in Form C#
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Technologies:

.Net 2.0/3.5


Language:

C#

Prerequisite

Visual Studio 2005/2008

Introduction

Normally We can Set background color of form as Single Color/Solid Color but What if we want the Form Backgound Shaded By two colors ?

you can do it by Addin Image backgound but It will down performace so We have to use somthing that is already in .net to gain performace . See how to do that

Now See What we will get After Implementing this Code

ColoredForm

Implementation

Forms OnPaint() Method is Raised when Form is Displayed on the Screen and By Ovverrideing this Event Web can change the Look and Feel of the form in c# .net


{codecitation class="brush: csharp; gutter: true;" width="650px"}

using System.Drawing.Drawing2D;

{/codecitation}

Then in Form's Source code Write Below

{codecitation class="brush: csharp; gutter: true;" width="650px"}

protected override void OnPaint(PaintEventArgs e)
{
// Get Graphics Object Who painted the Form

Graphics g = e.Graphics;


// Define Rectangle Area in Which We Want to Work Usually Forms Whole area

Rectangle rect = new Rectangle(0, 0, this.Size.Width, this.Size.Height);

// Take a Linear Grediant Brush

LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Orange, Color.Orchid,LinearGradientMode.ForwardDiagonal);

// Fill That Rectangle Area With Brush Paint

g.FillRectangle(brush, rect);


}

{/codecitation}

Thats It . You Will Get Two Colored Shaded From When you run Project .


Thank you


About the Author


Kirtan Patel
- Bachelor of Computer Application .
- File Handling with C#
- Registry Programming With C#.
- Knowledge of Virus Programming .
- Working With third party controls like Telerik and Component Factory .
- P/invoke Win32 API.
- SQL Server Database Applications
- Client/Server Database Programming

Expertise in : C# , Asp.net ,Vb.net , SQL Server , Designing Elegant look Web interface

Familiar With : C/C++ , Core Java , Java Script , Dream weaver templates , fire Works , Photo shop Graphics ,PHP

Databases: Microsoft SQL Server 2005 , Microsoft Access and Some MySQL

Occupation: Student


 
Sign Up to vote for this article
 
About Author
 
kirtan007
Occupation-
Company-
Member Type-Senior
Location-Not Provided
Joined date-02 Jul 2009
Home Page-http://kirtan.uni.cc
Blog Page-
He completed his Bachelor of Computer Application from Gujarat University 2009 .He is doing Master of Computer Application from Gujarat Technological University right now .. His area of Interests are Web Hacking , C# .net Windows form ,asp.net , WPF ,Silverlight ,SQL Server and Some PHP.
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top