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;
}