Click here to Skip to main content
6,630,901 members and growing! (20,068 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

Carved Dialog

By Nidheesh T.Mani

A dialog class whose top is made carved and the title bar is gradient filled
C#.NET 1.1, Win2K, WinXP, Win2003VS.NET2003, Dev
Posted:20 Jan 2004
Views:20,386
Bookmarked:10 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
17 votes for this article.
Popularity: 1.34 Rating: 1.09 out of 5
15 votes, 88.2%
1
2 votes, 11.8%
2

3

4

5

Sample Image - CarvedDialog.jpg

Introduction


This article specifies the following areas
1) To make a Dialog having a carved top using Graphics Path Class
2) How to use Gradient Fill.
3) To retrieve a resource from the corresponding resource file.
4) How to move a Dialog whose FormBorderStyle property is set to none
Using the code


Carving

The carving is done using Graphics path and Region classes

 

Rectangle rect = this.ClientRectangle;
 using (GraphicsPath path = new GraphicsPath ())
 {
 const int diameter = 25;
 Rectangle arcRect = new Rectangle (rect.Location, new Size (diameter, diameter));
 path.AddArc (arcRect, 180, 90);
 arcRect.X = rect.Right - diameter;
 path.AddArc (arcRect, 270, 90);
 path.AddLine (rect.Width, rect.Height, rect.X, rect.Height);
 path.CloseFigure ();
 this.Region = new Region (path);
 }

 

Resource


The Resource Manager class instance is instantiated using the Resource Manager of the current type.
I have embedded the image into the .resx file using a resource editor. You can do it programmatically using Classes
For writing into the resource file

resManager = new ResourceManager(this.GetType());
imageClose = (Bitmap)resManager.GetObject("Image_Close");

One of the problems, I have noted is I have added a resource using Resource Editor. After that suppose I�m going to make Changes from the
Designer View ,The  resource which has already been added gets deleted automatically


Gradient Fill

The following is the Code Snippet for producing Gradient Fill. We are blending the Colors specified in the Color array at the Respective points as in the array of Floats.Add this code in the implementation of paint event

Brush = new LinearGradientBrush(new Point(0,0),new  Point(0,this.Height) Color.FromArgb(0xA3,0xD7,0xFF),Color.FromArgb(0x49,0x99,0xFF));  
System.Drawing.Drawing2D.ColorBlend clrBlend = new ColorBlend();
Color []clrs = { Color.FromArgb(0x49,0x99,0xFF),  Color.FromArgb (0xA3,0xD7,0xFF),Color.FromArgb(0x49,0x99,0xFF),
                    Color.FromArgb(0x49,0x99,0xFF),Color.FromArgb(0x49,0x99,0xFF)};
float []flts = { 0.0f,0.2f,0.5f,0.75f,1.0f } ;
clrBlend.Colors    = clrs;
clrBlend.Positions = flts;
Brush.InterpolationColors = clrBlend;
g.FillRectangle(Brush,0,0,this.Width,this.Height);


Moving the Dialog


The following is the Code has to be added under mouse down event

if (e.Button == MouseButtons.Left)
{
 if(e.Button == MouseButtons.Left)
 {
  if((e.X > this.Width-25) && (e.X < (this.Width-25+imageClose.Width))
    && (e.Y > 2) && (e.Y < (2+imageClose.Height)))
  {
   this.Close();
  }
 }
 int xOffset = e.X;
 int yOffset = e.Y;
 isMouseDown = true;
 }         
}

 

The following is the Code has to be added under mouse move

if (isMouseDown)
{
 Point mousePos = Control.MousePosition;
 mousePos.Offset(mouseOffset.X, mouseOffset.Y);
 Location = mousePos;
}


The following is the Code has to be added under mouse up event

if (e.Button == MouseButtons.Left)
{
 isMouseDown = false;
}
  

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nidheesh T.Mani


Member

Occupation: Web Developer
Location: India India

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Jan 2004
Editor:
Copyright 2004 by Nidheesh T.Mani
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project