Click here to Skip to main content
Licence 
First Posted 20 Jan 2004
Views 22,867
Bookmarked 11 times

Carved Dialog

By | 20 Jan 2004 | Article
A dialog class whose top is made carved and the title bar is gradient filled

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

Web Developer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 21 Jan 2004
Article Copyright 2004 by Nidheesh T.Mani
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid