![]() |
Languages »
C# »
General
Intermediate
Carved DialogBy Nidheesh T.ManiA dialog class whose top is made carved and the title bar is gradient filled |
C#.NET 1.1, Win2K, WinXP, Win2003VS.NET2003, Dev
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

Introduction
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;
}
General
News
Question
Answer
Joke
Rant
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 |