Friday, March 20, 2009
Friday, February 20, 2009
Disabling Close Button on Forms using .net 2.0
Using the Code
During construction and creation of the Form object, .NET would use the default creation parameters available in the base class CreateParams property. In fact, CreateParams property is available in Forms.Control class. In our form class (derived from System.Windows.Forms.Form), override this property and modify the creation flags. For disabling the Close button use 0x200 to modify the ClassStyle member of the CreateParams.
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
Friday, February 13, 2009
Tuesday, February 10, 2009
Wednesday, January 21, 2009
Tuesday, December 30, 2008
Convert Image to Icon in .Net
- ///
- /// Converts an image into an icon.
- ///
- /// The image that shall become an icon
- /// The width and height of the icon. Standard
- /// sizes are 16x16, 32x32, 48x48, 64x64.
- /// Whether the image should be squashed into a
- /// square or whether whitespace should be put around it.
- ///
An icon!! - private Icon MakeIcon(Image img, int size, bool keepAspectRatio) {
- Graphics g = Graphics.FromImage(square); // allow drawing to it
- int x, y, w, h; // dimensions for new image
- if(!keepAspectRatio || img.Height == img.Width) {
- // just fill the square
- x = y = 0; // set x and y to 0
- w = h = size; // set width and height to size
- } else {
- // work out the aspect ratio
- float r = (float)img.Width / (float)img.Height;
- // set dimensions accordingly to fit inside size^2 square
- if(r > 1) { // w is bigger, so divide h by r
- w = size;
- h = (int)((float)size / r);
- x = 0; y = (size - h) / 2; // center the image
- } else { // h is bigger, so multiply w by r
- w = (int)((float)size * r);
- h = size;
- y = 0; x = (size - w) / 2; // center the image
- }
- }
- // make the image shrink nicely by using HighQualityBicubic mode
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.DrawImage(img, x, y, w, h); // draw image with specified dimensions
- g.Flush(); // make sure all drawing operations complete before we get the icon
- // following line would work directly on any image, but then
- // it wouldn't look as nice.
- return Icon.FromHandle(square.GetHicon());
- }
Subscribe to:
Posts (Atom)