Csharp/C Sharp/GUI Windows Form/Irregularly Shaped Forms

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Irregularly Shaped Forms Demo

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace IrregularlyShapedForms
{
    /// <summary>
    /// Summary description for IrregularlyShapedForms2.
    /// </summary>
    public class IrregularlyShapedForms2 : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Button Button1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public IrregularlyShapedForms2()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // Button1
            // 
            this.Button1.Location = new System.Drawing.Point(20, 24);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(136, 36);
            this.Button1.TabIndex = 1;
            this.Button1.Text = "Button1";
            // 
            // IrregularlyShapedForms2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.Button1});
            this.Name = "IrregularlyShapedForms2";
            this.Text = "Shaped Form";
            this.Load += new System.EventHandler(this.IrregularlyShapedForms2_Load);
            this.ResumeLayout(false);
        }
        #endregion
        [STAThread]
        static void Main() 
        {
            Application.Run(new IrregularlyShapedForms2());
        }
        private void IrregularlyShapedForms2_Load(object sender, System.EventArgs e)
        {
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(0, 0, this.Width / 2, this.Height / 2);
            path.AddRectangle(new Rectangle(this.Width / 2, this.Top / 2, this.Width / 2, this.Top / 2));
            path.AddEllipse(this.Width / 2, this.Height / 2, this.Width / 2, this.Height / 2);
            this.Region = new Region(path);
        }
    }
}


Irregularly Shaped Forms demo 1

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
  /// <summary>
  /// Summary description for IrregularlyShapedForms.
  /// </summary>
  public class IrregularlyShapedForms : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.Label lblDrag;
    internal System.Windows.Forms.PictureBox picFour;
    internal System.Windows.Forms.PictureBox picThree;
    internal System.Windows.Forms.PictureBox picOne;
    internal System.Windows.Forms.PictureBox picTwo;
    internal System.Windows.Forms.ImageList imgNormalButtons;
    internal System.Windows.Forms.ImageList imgSelectedButtons;
    private System.ruponentModel.IContainer components;
    public IrregularlyShapedForms()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();
      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null) 
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.ruponents = new System.ruponentModel.Container();
      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(IrregularlyShapedForms));
      this.lblDrag = new System.Windows.Forms.Label();
      this.picFour = new System.Windows.Forms.PictureBox();
      this.picThree = new System.Windows.Forms.PictureBox();
      this.picOne = new System.Windows.Forms.PictureBox();
      this.picTwo = new System.Windows.Forms.PictureBox();
      this.imgNormalButtons = new System.Windows.Forms.ImageList(this.ruponents);
      this.imgSelectedButtons = new System.Windows.Forms.ImageList(this.ruponents);
      this.SuspendLayout();
      // 
      // lblDrag
      // 
      this.lblDrag.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
      this.lblDrag.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.lblDrag.Location = new System.Drawing.Point(80, 36);
      this.lblDrag.Name = "lblDrag";
      this.lblDrag.Size = new System.Drawing.Size(124, 20);
      this.lblDrag.TabIndex = 9;
      this.lblDrag.Text = "      < Drag Here! >";
      this.lblDrag.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblDrag_MouseUp);
      this.lblDrag.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblDrag_MouseMove);
      this.lblDrag.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblDrag_MouseDown);
      // 
      // picFour
      // 
      this.picFour.Image = ((System.Drawing.Bitmap)(resources.GetObject("picFour.Image")));
      this.picFour.Location = new System.Drawing.Point(44, 176);
      this.picFour.Name = "picFour";
      this.picFour.Size = new System.Drawing.Size(209, 29);
      this.picFour.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
      this.picFour.TabIndex = 8;
      this.picFour.TabStop = false;
      this.picFour.Tag = "3";
      this.picFour.Click += new System.EventHandler(this.picFour_Click);
      this.picFour.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
      this.picFour.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
      this.picFour.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
      this.picFour.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
      // 
      // picThree
      // 
      this.picThree.Image = ((System.Drawing.Bitmap)(resources.GetObject("picThree.Image")));
      this.picThree.Location = new System.Drawing.Point(44, 144);
      this.picThree.Name = "picThree";
      this.picThree.Size = new System.Drawing.Size(209, 27);
      this.picThree.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
      this.picThree.TabIndex = 7;
      this.picThree.TabStop = false;
      this.picThree.Tag = "2";
      this.picThree.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
      this.picThree.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
      this.picThree.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
      this.picThree.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
      // 
      // picOne
      // 
      this.picOne.Image = ((System.Drawing.Bitmap)(resources.GetObject("picOne.Image")));
      this.picOne.Location = new System.Drawing.Point(44, 80);
      this.picOne.Name = "picOne";
      this.picOne.Size = new System.Drawing.Size(209, 26);
      this.picOne.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
      this.picOne.TabIndex = 6;
      this.picOne.TabStop = false;
      this.picOne.Tag = "0";
      this.picOne.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
      this.picOne.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
      this.picOne.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
      this.picOne.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
      // 
      // picTwo
      // 
      this.picTwo.Image = ((System.Drawing.Bitmap)(resources.GetObject("picTwo.Image")));
      this.picTwo.Location = new System.Drawing.Point(44, 112);
      this.picTwo.Name = "picTwo";
      this.picTwo.Size = new System.Drawing.Size(209, 28);
      this.picTwo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
      this.picTwo.TabIndex = 5;
      this.picTwo.TabStop = false;
      this.picTwo.Tag = "1";
      this.picTwo.MouseEnter += new System.EventHandler(this.pic_MouseEnter);
      this.picTwo.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pic_MouseUp);
      this.picTwo.MouseLeave += new System.EventHandler(this.pic_MouseLeave);
      this.picTwo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pic_MouseDown);
      // 
      // imgNormalButtons
      // 
      this.imgNormalButtons.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
      this.imgNormalButtons.ImageSize = new System.Drawing.Size(209, 29);
      this.imgNormalButtons.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgNormalButtons.ImageStream")));
      this.imgNormalButtons.TransparentColor = System.Drawing.Color.Transparent;
      // 
      // imgSelectedButtons
      // 
      this.imgSelectedButtons.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
      this.imgSelectedButtons.ImageSize = new System.Drawing.Size(209, 29);
      this.imgSelectedButtons.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgSelectedButtons.ImageStream")));
      this.imgSelectedButtons.TransparentColor = System.Drawing.Color.Transparent;
      // 
      // IrregularlyShapedForms
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
      this.ClientSize = new System.Drawing.Size(292, 266);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.lblDrag,
                                      this.picFour,
                                      this.picThree,
                                      this.picOne,
                                      this.picTwo});
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.Name = "IrregularlyShapedForms";
      this.Text = "IrregularlyShapedForms";
      this.Load += new System.EventHandler(this.IrregularlyShapedForms_Load);
      this.ResumeLayout(false);
    }
    #endregion
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new IrregularlyShapedForms());
    }
    private void IrregularlyShapedForms_Load(object sender, System.EventArgs e)
    {
      GraphicsPath path = new GraphicsPath();
      path.AddEllipse(10, 50, this.Width - 20, this.Height - 60);
      this.Region = new Region(path);
      
      picOne.Image = imgNormalButtons.Images[0];
      picTwo.Image = imgNormalButtons.Images[1];
      picThree.Image = imgNormalButtons.Images[2];
      picFour.Image = imgNormalButtons.Images[3];
    }
    private void picFour_Click(object sender, System.EventArgs e)
    {
      this.Close();
    }
    private void pic_MouseEnter(object sender, System.EventArgs e)
    {
      PictureBox pic = (PictureBox)sender;
      int imageIndex = int.Parse((pic.Tag.ToString()));
      pic.Image = imgSelectedButtons.Images[imageIndex];
    }
    private void pic_MouseLeave(object sender, System.EventArgs e)
    {
      PictureBox pic = (PictureBox)sender;
      int imageIndex = int.Parse((pic.Tag.ToString()));
      pic.Image = imgNormalButtons.Images[imageIndex];
    }
    private void pic_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      PictureBox pic = (PictureBox)sender;
      pic.Top += 2;
      pic.Left += 2;
    }
    private void pic_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      PictureBox pic = (PictureBox)sender;
      pic.Top -= 2;
      pic.Left -= 2;
    }
    private bool formDragging;
    private Point pointClicked;
    private void lblDrag_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
       // Set drag mode on.
      formDragging = true;
            // Store the offset where the control was clicked.
      pointClicked = new Point(e.X, e.Y);
    }
    private void lblDrag_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      if (formDragging)
      {
        Point pointMoveTo;
        
        // Find the current mouse position in screen coordinates.
        pointMoveTo = this.PointToScreen(new Point(e.X, e.Y));
        
        // Compensate for the position the control was clicked.
        pointMoveTo.Offset(-pointClicked.X, -pointClicked.Y);
        
        // Compensate for the non-client region (title bar).
        // This code is not necessary if you explicitly hide the title bar
        //  by setting the form"s BorderStyle to None.
        pointMoveTo.Offset(0, -25);
        
        // Move the form.
        this.Location = pointMoveTo;
      }
    }
    private void lblDrag_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      formDragging = false;
    }
  }

<A href="http://www.nfex.ru/Code/CSharpDownload/IrregularlyShapedForms.zip">IrregularlyShapedForms.zip( 164 k)</a>


Non rectangle Form window

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form{
  private System.ruponentModel.Container components = null;
  public Form1()
  {
    InitializeComponent();
  }
  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
  #region Windows Form Designer generated code
  private void InitializeComponent()
  {
      this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
      this.ClientSize = new System.Drawing.Size(472, 352);
      this.Name = "Form1";
      this.Text = "Shaped Form Demo";
      this.Load += new System.EventHandler(this.Form1_Load);
    }
  #endregion
  static void Main() 
  {
    Application.Run(new Form1());
  }
    private void Form1_Load(object sender, System.EventArgs e)
    {
      BackColor = Color.Red;
      GraphicsPath path = new GraphicsPath();
      path.AddString("www.nfex.ru",Font.FontFamily, 1, 75, new Point(0, 0), new StringFormat());
      Region = new Region(path);
    }
}


Transparent form

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace Transparensy
{
    /// <summary>
    /// Summary description for Transparensy.
    /// </summary>
    public class Transparensy : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Transparensy()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            
            this.Text = "Transparency";
            //this.Opacity = 0.5;
            //this.TransparencyKey = System.Drawing.Color.Yellow;
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // Transparensy
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(248, 78);
            this.Name = "Transparensy";
            this.Text = "Transparensy";
        }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Transparensy());
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g;
            g = Graphics.FromHwnd(this.Handle);
            g.FillRectangle(new SolidBrush(Color.Red), 10, 10, 210, 50);
    
            // Five yellow squares with different alpha values
            Rectangle r = new Rectangle(40, 20, 30, 30);
            Color c = Color.FromArgb(255, 255, 255, 0);
            g.FillRectangle(new SolidBrush(c), r);
    
            r.Offset(30, 0);
            c = Color.FromArgb(200, 255, 255, 0);
            g.FillRectangle(new SolidBrush(c), r);
    
            r.Offset(30, 0);
            c = Color.FromArgb(150, 255, 255, 0);
            g.FillRectangle(new SolidBrush(c), r);
    
            r.Offset(30, 0);
            c = Color.FromArgb(100, 255, 255, 0);
            g.FillRectangle(new SolidBrush(c), r);
    
            r.Offset(30, 0);
            c = Color.FromArgb(50, 255, 255, 0);
            g.FillRectangle(new SolidBrush(c), r);
            g.Dispose();        
        }
    }
}


Transparent Forms

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
namespace TransparentForms
{
    /// <summary>
    /// Summary description for Form2.
    /// </summary>
    public class Transparent : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.GroupBox GroupBox1;
        internal System.Windows.Forms.Button cmdApply;
        internal System.Windows.Forms.NumericUpDown udOpacity;
        internal System.Windows.Forms.Label Label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Transparent()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.GroupBox1 = new System.Windows.Forms.GroupBox();
            this.cmdApply = new System.Windows.Forms.Button();
            this.udOpacity = new System.Windows.Forms.NumericUpDown();
            this.Label1 = new System.Windows.Forms.Label();
            this.GroupBox1.SuspendLayout();
            ((System.ruponentModel.ISupportInitialize)(this.udOpacity)).BeginInit();
            this.SuspendLayout();
            // 
            // GroupBox1
            // 
            this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                    this.cmdApply,
                                                                                    this.udOpacity,
                                                                                    this.Label1});
            this.GroupBox1.Location = new System.Drawing.Point(12, 75);
            this.GroupBox1.Name = "GroupBox1";
            this.GroupBox1.Size = new System.Drawing.Size(268, 116);
            this.GroupBox1.TabIndex = 4;
            this.GroupBox1.TabStop = false;
            // 
            // cmdApply
            // 
            this.cmdApply.Location = new System.Drawing.Point(172, 64);
            this.cmdApply.Name = "cmdApply";
            this.cmdApply.Size = new System.Drawing.Size(80, 24);
            this.cmdApply.TabIndex = 5;
            this.cmdApply.Text = "Apply";
            this.cmdApply.Click += new System.EventHandler(this.cmdApply_Click);
            // 
            // udOpacity
            // 
            this.udOpacity.Increment = new System.Decimal(new int[] {
                                                                        5,
                                                                        0,
                                                                        0,
                                                                        0});
            this.udOpacity.Location = new System.Drawing.Point(88, 32);
            this.udOpacity.Name = "udOpacity";
            this.udOpacity.Size = new System.Drawing.Size(48, 21);
            this.udOpacity.TabIndex = 4;
            this.udOpacity.Value = new System.Decimal(new int[] {
                                                                    50,
                                                                    0,
                                                                    0,
                                                                    0});
            // 
            // Label1
            // 
            this.Label1.Location = new System.Drawing.Point(20, 36);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(56, 16);
            this.Label1.TabIndex = 3;
            this.Label1.Text = "Opacity:";
            // 
            // Form2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.GroupBox1});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "Form2";
            this.Text = "A Transparent Form";
            this.GroupBox1.ResumeLayout(false);
            ((System.ruponentModel.ISupportInitialize)(this.udOpacity)).EndInit();
            this.ResumeLayout(false);
        }
        #endregion
        private void cmdApply_Click(object sender, System.EventArgs e)
        {
            this.Opacity = (double)udOpacity.Value / 100;
        }
        [STAThread]
        static void Main() 
        {
            Application.Run(new Transparent());
        }
    }
}


Transparent Forms: holes

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace TransparentForms
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Holes : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.PictureBox PictureBox4;
        internal System.Windows.Forms.PictureBox PictureBox2;
        internal System.Windows.Forms.PictureBox PictureBox1;
        internal System.Windows.Forms.PictureBox PictureBox3;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Holes()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.PictureBox4 = new System.Windows.Forms.PictureBox();
            this.PictureBox2 = new System.Windows.Forms.PictureBox();
            this.PictureBox1 = new System.Windows.Forms.PictureBox();
            this.PictureBox3 = new System.Windows.Forms.PictureBox();
            this.SuspendLayout();
            // 
            // PictureBox4
            // 
            this.PictureBox4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(128)));
            this.PictureBox4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureBox4.Location = new System.Drawing.Point(108, 108);
            this.PictureBox4.Name = "PictureBox4";
            this.PictureBox4.Size = new System.Drawing.Size(76, 76);
            this.PictureBox4.TabIndex = 10;
            this.PictureBox4.TabStop = false;
            // 
            // PictureBox2
            // 
            this.PictureBox2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(128)));
            this.PictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureBox2.Location = new System.Drawing.Point(12, 108);
            this.PictureBox2.Name = "PictureBox2";
            this.PictureBox2.Size = new System.Drawing.Size(76, 76);
            this.PictureBox2.TabIndex = 9;
            this.PictureBox2.TabStop = false;
            // 
            // PictureBox1
            // 
            this.PictureBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(128)));
            this.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureBox1.Location = new System.Drawing.Point(108, 16);
            this.PictureBox1.Name = "PictureBox1";
            this.PictureBox1.Size = new System.Drawing.Size(76, 76);
            this.PictureBox1.TabIndex = 8;
            this.PictureBox1.TabStop = false;
            // 
            // PictureBox3
            // 
            this.PictureBox3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(128)));
            this.PictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.PictureBox3.Location = new System.Drawing.Point(12, 16);
            this.PictureBox3.Name = "PictureBox3";
            this.PictureBox3.Size = new System.Drawing.Size(76, 76);
            this.PictureBox3.TabIndex = 7;
            this.PictureBox3.TabStop = false;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(232, 234);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.PictureBox4,
                                                                          this.PictureBox2,
                                                                          this.PictureBox1,
                                                                          this.PictureBox3});
            this.Name = "Form1";
            this.Text = "A Form With Holes";
            this.TransparencyKey = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(128)));
            this.ResumeLayout(false);
        }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Holes());
        }
    }
}


Transparent form window

  using System;
  using System.Drawing;
  using System.Collections;
  using System.ruponentModel;
  using System.Windows.Forms;
  using System.Data;
  public class MainForm : System.Windows.Forms.Form
  {
    private System.ruponentModel.Container components;
    public MainForm()
    {
      InitializeComponent();
      BackColor = Color.Tomato;
      Opacity = 0.5d;
      Text = "www.nfex.ru";
      Cursor = Cursors.WaitCursor;
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null) 
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "Form1";
    }
    [STAThread]
    static void Main() 
    {
      Application.Run(new MainForm());
    }
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
      Graphics g = e.Graphics;
      g.DrawString("www.nfex.ru", 
        new Font("Times New Roman", 20), 
        new SolidBrush(Color.Black), 40, 10);
    }
  }


Transparent window and screen capture

/*
GDI+ Programming in C# and VB .NET
by Nick Symmonds
Publisher: Apress
ISBN: 159059035X
*/

using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace Clipper_c {
    /// <summary>
    /// Copyright Nicholas Symmonds 2002
    /// This software is for instructional purposes only.
    /// It may not be sold as is.
    /// </summary>
    public class Clipper : System.Windows.Forms.Form {
        Bitmap bmp;
        NotifyIcon trayIcon       = new  NotifyIcon();
        ContextMenu trayIconMenu  = new ContextMenu();
        private System.Windows.Forms.Button cmdCatch;
        private System.Windows.Forms.Button cmdQuit;
        
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Clipper() {
            InitializeComponent();
            this.Icon = new Icon("icon.ico");
            this.BackColor          = Color.BlanchedAlmond;
            this.TransparencyKey    = this.BackColor;
            this.cmdCatch.BackColor = Color.Tomato;
            this.cmdQuit.BackColor  = Color.Tomato;
            trayIconMenu.MenuItems.Add("Catch", 
                                  new EventHandler(this.cmdCatch_Click));
            trayIconMenu.MenuItems.Add("Always On Top", 
                                  new EventHandler(this.ClipperOnTop));
            trayIconMenu.MenuItems.Add("Show",  
                                  new EventHandler(this.Show_Main));
            trayIconMenu.MenuItems.Add("Quit",  
                                  new EventHandler(this.cmdQuit_Click));
            trayIcon.Icon = new Icon("icon.ico");
            trayIcon.Text = "Clipper - Screen Capture";
            trayIcon.ContextMenu = trayIconMenu;
            trayIcon.Visible = true;
      
            this.ShowInTaskbar = false;
        }
        
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if (components != null) {
                    components.Dispose();
                }
                if (bmp != null)
                    bmp.Dispose();
                trayIcon.Dispose();
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.cmdCatch = new System.Windows.Forms.Button();
            this.cmdQuit = new System.Windows.Forms.Button();
            this.SuspendLayout();
            
            // 
            // cmdCatch
            // 
            this.cmdCatch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.cmdCatch.Location = new System.Drawing.Point(16, 24);
            this.cmdCatch.Name = "cmdCatch";
            this.cmdCatch.Size = new System.Drawing.Size(88, 32);
            this.cmdCatch.TabIndex = 0;
            this.cmdCatch.Text = "&Capture";
            this.cmdCatch.Click += new System.EventHandler(this.cmdCatch_Click);
            
            // 
            // cmdQuit
            // 
            this.cmdQuit.Location = new System.Drawing.Point(144, 24);
            this.cmdQuit.Name = "cmdQuit";
            this.cmdQuit.Size = new System.Drawing.Size(64, 32);
            this.cmdQuit.TabIndex = 1;
            this.cmdQuit.Text = "&Quit";
            this.cmdQuit.Click += new System.EventHandler(this.cmdQuit_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(224, 75);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.cmdQuit,
                                                                  this.cmdCatch});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Screen Capture";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
        }
        #endregion
        [STAThread]
        static void Main() {
            Application.Run(new Clipper());
        }
        private void Form1_Load(object sender, System.EventArgs e) {
        }
        protected override void OnResize(EventArgs e) {
            base.OnResize(e);
               if (this.WindowState == FormWindowState.Minimized)
                   this.Opacity = 0;
               else
                   this.Opacity = 1;
        }
        /// <summary>
        /// The desktop capture method makes this form invisible before 
        /// showing the picture. Once the Save form has run this form becomes
        /// visible. Making this form invisible is done via the forms opacity.
        /// </summary>
        private void cmdCatch_Click(object sender, System.EventArgs e) {
            bmp = DeskTop.Capture();
      
            //Make the form invisible
            this.Opacity = 0;
            dtBitmap bmpShow = new dtBitmap(bmp);
            bmp = bmpShow.GetBitmap;
            if (bmp != null) {
                frmSave frm = new frmSave(bmp);
                frm.ShowDialog();
            }
            this.Opacity = 1;
        }
        private void cmdQuit_Click(object sender, System.EventArgs e) {
            trayIcon.Visible = false;
            this.Close();
        }
        private void Show_Main(object sender, System.EventArgs e) {
            this.Visible = true;
            this.WindowState = FormWindowState.Normal;
        }
        private void ClipperOnTop(object sender, System.EventArgs e) {
            if ( trayIconMenu.MenuItems[1].Checked ) {
                trayIconMenu.MenuItems[1].Checked = false;
                this.TopMost = false;
            } else {
                trayIconMenu.MenuItems[1].Checked = true;
                this.TopMost = true;
            }
        }
    }
    /// <summary>
    /// Copyright Nicholas Symmonds 2002
    /// This software is for instructional purposes only.
    /// It may not be sold as is.
    /// 
    /// Allow the user to select a frame for the image before saving it.
    /// </summary>
    public class frmSave : System.Windows.Forms.Form {
        private PictureBox          m_Pic;
        private Bitmap              m_bmp;
        private Bitmap              m_OriginalBmp;
        private PrintPreviewDialog  Pv;
        private PageSetupDialog     Ps;
        private PrintDocument       Pd;
        private PrintDialog         Pr;
        private Font                FooterFont = new Font("Arial", 8);
        private int                 PrintCount = 0;
        private System.Windows.Forms.Panel P1;
        private System.Windows.Forms.MainMenu mainMenu1;
        private System.Windows.Forms.MenuItem mnuFile;
        private System.Windows.Forms.MenuItem mnuSave;
        private System.Windows.Forms.MenuItem mnuPrint;
        private System.Windows.Forms.MenuItem mnuClose;
        private System.Windows.Forms.MenuItem mnuPrintPreview;
        private System.Windows.Forms.MenuItem mnuPrintNow;
        private System.Windows.Forms.MenuItem NoMenu;
        private System.Windows.Forms.MenuItem mnuAttr;
        private System.Windows.Forms.MenuItem mnuBorder;
        private System.ruponentModel.Container components = null;
        public frmSave(Bitmap bmp) {
            InitializeComponent();
            m_bmp = (Bitmap)bmp.Clone();
            m_OriginalBmp = (Bitmap)bmp.Clone();
            P1.BackgroundImage = GetPanelImage();
            P1.Dock = DockStyle.Fill;
      
            m_Pic = new PictureBox();
            m_Pic.BorderStyle = BorderStyle.None;
            m_Pic.SizeMode = PictureBoxSizeMode.AutoSize;
            m_Pic.Image = m_bmp;
            P1.Controls.Add(m_Pic);
            P1.Controls[0].Location = new Point(1, 1);
            //Set up the prnting 
            Pv = new PrintPreviewDialog();
            Ps = new PageSetupDialog();
            Pr = new PrintDialog();
            Pd = new PrintDocument();
            Pd.DocumentName = "ScreenShot";
            Pv.Document = Pd;
            Ps.Document = Pd;
            Pr.Document = Pd;
            Pd.BeginPrint += new PrintEventHandler(this.pd_BeginPrint);
            Pd.PrintPage += new PrintPageEventHandler(this.pd_Print);
        }
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if(components != null) {
                    components.Dispose();
                }
                P1.Dispose();
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.P1 = new System.Windows.Forms.Panel();
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.mnuFile = new System.Windows.Forms.MenuItem();
            this.mnuSave = new System.Windows.Forms.MenuItem();
            this.mnuClose = new System.Windows.Forms.MenuItem();
            this.NoMenu = new System.Windows.Forms.MenuItem();
            this.mnuAttr = new System.Windows.Forms.MenuItem();
            this.mnuBorder = new System.Windows.Forms.MenuItem();
            this.mnuPrint = new System.Windows.Forms.MenuItem();
            this.mnuPrintPreview = new System.Windows.Forms.MenuItem();
            this.mnuPrintNow = new System.Windows.Forms.MenuItem();
            this.SuspendLayout();
            // 
            // P1
            // 
            this.P1.AutoScroll = true;
            this.P1.BackColor = System.Drawing.SystemColors.Control;
            this.P1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.P1.Location = new System.Drawing.Point(8, 16);
            this.P1.Name = "P1";
            this.P1.Size = new System.Drawing.Size(768, 520);
            this.P1.TabIndex = 0;
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                              this.mnuFile,
                                                                              this.NoMenu,
                                                                              this.mnuPrint});
            // 
            // mnuFile
            // 
            this.mnuFile.Index = 0;
            this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                            this.mnuSave,
                                                                            this.mnuClose});
            this.mnuFile.Text = "&File";
            // 
            // mnuSave
            // 
            this.mnuSave.Index = 0;
            this.mnuSave.Text = "&Save";
            this.mnuSave.Click += new System.EventHandler(this.mnuSave_Click);
            // 
            // mnuClose
            // 
            this.mnuClose.Index = 1;
            this.mnuClose.Text = "&Close";
            this.mnuClose.Click += new System.EventHandler(this.mnuClose_Click);
            // 
            // NoMenu
            // 
            this.NoMenu.Index = 1;
            this.NoMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                           this.mnuAttr,
                                                                           this.mnuBorder});
            this.NoMenu.Text = "&Attributes";
            this.NoMenu.Click += new System.EventHandler(this.mnuAttr_Click);
            // 
            // mnuAttr
            // 
            this.mnuAttr.Index = 0;
            this.mnuAttr.Text = "Resolution";
            this.mnuAttr.Click += new System.EventHandler(this.mnuAttr_Click);
            // 
            // mnuBorder
            // 
            this.mnuBorder.Index = 1;
            this.mnuBorder.Text = "Border";
            this.mnuBorder.Click += new System.EventHandler(this.mnuBorder_Click);
            // 
            // mnuPrint
            // 
            this.mnuPrint.Index = 2;
            this.mnuPrint.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                             this.mnuPrintPreview,
                                                                             this.mnuPrintNow});
            this.mnuPrint.Text = "&Print";
            // 
            // mnuPrintPreview
            // 
            this.mnuPrintPreview.Index = 0;
            this.mnuPrintPreview.Text = "Pre&view";
            this.mnuPrintPreview.Click += new System.EventHandler(this.mnuPrintPreview_Click);
            // 
            // mnuPrintNow
            // 
            this.mnuPrintNow.Index = 1;
            this.mnuPrintNow.Text = "&Print";
            this.mnuPrintNow.Click += new System.EventHandler(this.mnuPrintNow_Click);
            // 
            // frmSave
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(792, 553);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.P1});
            this.Menu = this.mainMenu1;
            this.MinimizeBox = false;
            this.Name = "frmSave";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Save Image";
            this.Load += new System.EventHandler(this.frmSave_Load);
            this.ResumeLayout(false);
        }
        #endregion
        private void frmSave_Load(object sender, System.EventArgs e) {
        }
        /// <summary>
        /// This routine makes a blank image and colors it with a hatch brush
        /// This image is handed back to the caller who then uses this image as 
        /// the background image for the panel.  The panel will tile this image 
        /// for as many times as it takes to fill the panel.
        /// </summary>
        private Image GetPanelImage() {
            Image i = new Bitmap(50, 50);
            using(Graphics G = Graphics.FromImage(i)) {
            //No need for high quality here.  We need Speed!!!
                G.SmoothingMode = SmoothingMode.HighSpeed;
                Brush B = new HatchBrush(HatchStyle.Cross, Color.Cyan, Color.LightCyan);
                G.FillRectangle(B, 0, 0, i.Width, i.Height);
            }
            return i;
        }
        private void mnuAttr_Click(object sender, System.EventArgs e)  {
            Attributes frm = new Attributes(m_bmp.HorizontalResolution, m_bmp.Size);
            frm.ShowDialog();
            m_bmp.SetResolution(frm.SaveRes, frm.SaveRes);
        }
        private void mnuClose_Click(object sender, System.EventArgs e) {
            this.Close();
        }
        private void mnuSave_Click(object sender, System.EventArgs e) {
            SaveFileDialog sd = new SaveFileDialog();
 
            sd.Filter = "Bitmap (*.bmp)|*.bmp|" +
                  "JPEG (*.jpg)|*.jpg|" + 
                  "GIF (*.Gif)|*.gif|"  +
                  "TIFF (*.tif)|*.tif|"  +
                  "PNG (*.png)|*.png|"  +
                  "EMF (*.emf)|*.emf"  ;
            sd.FilterIndex = 1 ;
            sd.RestoreDirectory = true ;
            sd.AddExtension = true;
 
            if(sd.ShowDialog() == DialogResult.OK)  {
                if (sd.FileName.Length != 0) {
                    switch(sd.FilterIndex) {
                        case 1:
                        //Save as bitmap
                            m_bmp.Save(sd.FileName, ImageFormat.Bmp);
                            break;
                        case 2:
                        //Save as JPEG
                            m_bmp.Save(sd.FileName, ImageFormat.Jpeg);
                            break;
                        case 3:
                        //Save as GIF
                            m_bmp.Save(sd.FileName, ImageFormat.Gif);
                            break;
                        case 4:
                        //Save as TIFF
                            m_bmp.Save(sd.FileName, ImageFormat.Tiff);
                            break;
                        case 5:
                        //Save as PNG
                            m_bmp.Save(sd.FileName, ImageFormat.Png);
                            break;
                        case 6:
                        //Save as EMF
                            m_bmp.Save(sd.FileName, ImageFormat.Emf);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        #region Printer routines
        private void pd_BeginPrint ( object sender, PrintEventArgs e) {
            Pd.DocumentName = "ScreenShot " + (++PrintCount).ToString();
        }
        private void pd_Print(object sender, PrintPageEventArgs e)  {
            Graphics G = e.Graphics;
            float LeftMargin = e.MarginBounds.Left;
            float TopMargin = e.MarginBounds.Top;
            float BottomMargin = e.MarginBounds.Bottom;
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Far;
            sf.LineAlignment = StringAlignment.Center;
            Rectangle Border = e.MarginBounds;
            Border.Inflate(1, 1);
            RectangleF Footer = new Rectangle(e.MarginBounds.Left, 
                                        e.MarginBounds.Bottom,
                                        e.MarginBounds.Width,
                                        e.PageBounds.Bottom - 
                                        e.MarginBounds.Bottom);
            //Type in the footer
            G.DrawString(Pd.DocumentName, FooterFont, Brushes.Black, Footer, sf);
            sf.Alignment = StringAlignment.Near;
            G.DrawString(DateTime.Now.ToLongDateString(), FooterFont, 
                   Brushes.Black, 
                   Footer, sf);
            //Draw the rectangle and the image.  Image is stretched to fit!!!
            G.DrawRectangle(Pens.Black, Border);
            G.DrawImage(m_bmp, e.MarginBounds);
            sf.Dispose();
        }
        private void mnuPrintPreview_Click(object sender, System.EventArgs e) {
            Pv.WindowState = FormWindowState.Maximized;
            Pv.ShowDialog();
        }
        private void mnuPrintNow_Click(object sender, System.EventArgs e) {
            if (Pr.ShowDialog() == DialogResult.OK)
                Pd.Print();
        }
        #endregion
        private void mnuBorder_Click(object sender, System.EventArgs e) {
            if (!mnuBorder.Checked) {
                using (Graphics G = Graphics.FromImage(m_bmp)) {
                    using (Pen P = new Pen(Brushes.Black, 2)) {
                        G.DrawRectangle(P, new Rectangle(0, 0, m_bmp.Size.Width, 
                            m_bmp.Size.Height));
                        m_Pic.Image = m_bmp;
                        mnuBorder.Checked = true;
                    }
                }
            }  else {
                m_bmp = (Bitmap)m_OriginalBmp.Clone();
                m_Pic.Image = m_bmp;
                mnuBorder.Checked = false;
            }
        }
    }
    /// <summary>
    ///  Copyright Nicholas Symmonds 2002
    /// This software is for instructional purposes only.
    /// It may not be sold as is.
    /// 
    /// This form is the one that holds the complete bitmap of the screen.  
    /// The border is set to nothing and the form is maximized.  The cursor 
    /// is also changed to tell the user (s)he can now drag a line and make 
    /// a capture box. When the screen is captured this form shows up almost 
    /// immediately.
    /// </summary>
    public class dtBitmap : Form {
        #region Class local storage
        private Bitmap bmp;
        private Rectangle InvalidRect = Rectangle.Empty;
        private Pen mRectPen;
        private Corectangle mbmpRect;
        #endregion
    
        public dtBitmap(Bitmap b) {
            mbmpRect = new  Corectangle();
            mRectPen = new Pen(Brushes.Red, 1);
            mRectPen.DashStyle = DashStyle.DashDot;
            bmp = b.Clone(new RectangleF(0, 0, b.Width, b.Height), b.PixelFormat);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
            this.SetStyle(ControlStyles.DoubleBuffer,true);
            this.Size = bmp.Size;
            this.FormBorderStyle = FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Cursor = new Cursor("hcross.cur");
            this.BackgroundImage = bmp;
            //Show as modal
            this.ShowDialog();
        }
        private void InitializeComponent() {
            // 
            // dtBitmap
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Name = "dtBitmap";
            this.Load += new System.EventHandler(this.dtBitmap_Load);
        }
        protected override void Dispose( bool disposing ) {
            if( disposing ) {
                if (bmp != null)
                    bmp.Dispose();
            }
            base.Dispose( disposing );
        }
        public Bitmap GetBitmap {
            get{return bmp;}
        }
        private void dtBitmap_Load(object sender, System.EventArgs e) {
        }
        protected override void OnPaint(PaintEventArgs e) {
            base.OnPaint(e);
            e.Graphics.DrawRectangle(mRectPen, mbmpRect.Rect);
        }
        #region Squeek
        protected override void OnMouseDown(MouseEventArgs e) {
            base.OnMouseDown(e);
            if (e.Button != MouseButtons.Left)
                return;
            mbmpRect = new  Corectangle(e.X, e.Y);
        }
        protected override void OnMouseUp(MouseEventArgs e) {
            base.OnMouseUp(e);
            Invalidate();
            bmp = bmp.Clone(mbmpRect.Rect, bmp.PixelFormat);
            this.Close();
        }
        protected override void OnMouseMove(MouseEventArgs e) {
            base.OnMouseMove(e);
            if (e.Button != MouseButtons.Left)
                return;
            mbmpRect.EndX = e.X;
            mbmpRect.EndY = e.Y;
            Invalidate();
        }
        #endregion
    }
    /// <summary>
    /// Copyright Nicholas Symmonds 2002
    /// This software is for instructional purposes only.
    /// It may not be sold as is.
    /// 
    /// This class encapsulates the API functions necessary to get the
    /// desktop image and form a bitmap from it.
    /// Not everything can be done in GDI+ :)
    /// </summary>
    
    public sealed class DeskTop {
        [DllImport("user32.dll")]
        internal extern static IntPtr GetDesktopWindow();
        [DllImport("user32.dll")]
        internal extern static IntPtr GetDC( IntPtr windowHandle );
        [DllImport("gdi32.dll")]
        internal extern static IntPtr GetCurrentObject( IntPtr hdc, 
                                                    ushort objectType );
        [DllImport("user32.dll")]
        internal extern static void ReleaseDC( IntPtr hdc );
        [DllImport("user32.dll")]
        internal extern static void UpdateWindow( IntPtr hwnd );
        public static Bitmap Capture() {
            //Get a pointer to the desktop window
            IntPtr    desktopWindow = GetDesktopWindow();
            //Get a device context from the desktop window
            IntPtr    desktopDC = GetDC( desktopWindow );
            //Get a GDI handle to the image
            IntPtr    desktopBitmap = GetCurrentObject( desktopDC, 7 );
            //This call takes as an argument the handle to a GDI image
            Bitmap    desktopImage = Image.FromHbitmap( desktopBitmap );
            //Do not create any memory leaks
            ReleaseDC( desktopDC );
            return desktopImage;
        }
    }
    /// <summary>
    /// This class takes any starting point and any ending point
    /// structures and makes a rectangle.  Using this class you can use the mouse
    /// to draw a rectangle on the screen from any starting point to any ending
    /// point.  You cannot do this with a regular rectangle.
    /// </summary>
    public class Corectangle {
        #region Class Local Variables
        private Point mStart;
        private Point mEnd;
        private Point mRealStart;
        private Point mRealEnd;
        private Size  mRealSize;
        private Rectangle mRect;
        #endregion

        public Corectangle(int X, int Y)  {
            mStart        = Point.Empty;
            mEnd          = Point.Empty;
            mRealStart    = Point.Empty;
            mRealEnd      = Point.Empty;
            mRealSize     = Size.Empty;
            mStart.X      = X;
            mStart.Y      = Y;
            mRealStart.X  = X;
            mRealStart.Y  = Y;
            mRect = Rectangle.Empty;
        }
        public Corectangle() {
            mStart        = Point.Empty;
            mEnd          = Point.Empty;
            mRealStart    = Point.Empty;
            mRealEnd      = Point.Empty;
            mRealSize     = Size.Empty;
            mStart.X      = 0;
            mStart.Y      = 0;
            mRealStart.X  = 0;
            mRealStart.Y  = 0;
            mRect = Rectangle.Empty;
        }
        /// <summary>
        /// Ending X Value of rectangle
        /// </summary>
        public int EndX {
            set{ mEnd.X = value; 
            }
        }
        /// <summary>
        /// Ending Y Value of rectangle
        /// </summary>
        public int EndY {
            set{ 
                mEnd.Y = value; 
            }
        }
        /// <summary>
        /// Get the corrected rectangle
        /// </summary>
        public Rectangle Rect {
            get { 
                MakeReal();
                mRect.Location = mRealStart;
                mRect.Size = mRealSize;
                return mRect; 
            }
        }
        private void MakeReal() {
            //Started top left, ended bottom right
            if (mEnd.X > mStart.X && mEnd.Y > mStart.Y) {
                mRealStart = mStart;
                mRealEnd = mEnd;
                mRealSize = new Size(mRealEnd.X-mRealStart.X, mRealEnd.Y-mRealStart.Y);
                return;
            }
            //Started bottom right, ended top left
            if (mEnd.X < mStart.X && mEnd.Y < mStart.Y) {
                mRealEnd = mStart;
                mRealStart = mEnd;
                mRealSize = new Size(mRealEnd.X-mRealStart.X, mRealEnd.Y-mRealStart.Y);
                return;
            }
            //Started top right left, ended bottom left
            if (mEnd.X < mStart.X && mEnd.Y > mStart.Y) {
                mRealStart.X = mEnd.X;
                mRealStart.Y = mStart.Y;
                mRealEnd.X   = mStart.X;
                mRealEnd.Y   = mEnd.Y;
                mRealSize = new Size(mRealEnd.X-mRealStart.X, mRealEnd.Y-mRealStart.Y);
                return;
            }
            //Started bottom left, ended top right
            if (mEnd.X > mStart.X && mEnd.Y < mStart.Y) {
                mRealStart.X = mStart.X;
                mRealStart.Y = mEnd.Y;
                mRealEnd.X   = mEnd.X;
                mRealEnd.Y   = mStart.Y;
                mRealSize = new Size(mRealEnd.X-mRealStart.X, mRealEnd.Y-mRealStart.Y);
                return;
            }
        }
    }
    /// <summary>
    /// Summary description for Attributes.
    /// </summary>
    public class Attributes : System.Windows.Forms.Form  {
        private float m_Res;
        private System.Windows.Forms.Label lblCurrentRes;
        private System.Windows.Forms.Label lblRes;
        private System.Windows.Forms.Button cmdOK;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.RadioButton optCurrent;
        private System.Windows.Forms.RadioButton opt120;
        private System.Windows.Forms.RadioButton opt150;
        private System.Windows.Forms.RadioButton opt300;
        private System.Windows.Forms.Label lblSize;
        private System.Windows.Forms.Label lblSizeVal;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Attributes(float CurrentResolution, Size sz) {
            InitializeComponent();
            m_Res = CurrentResolution;
            lblRes.Text = m_Res.ToString() + " DPI";
            lblSizeVal.Text = sz.Width.ToString() + "w X " + sz.Height.ToString() + "h";
            optCurrent.Checked = true;
            this.Opacity = 1.0;
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lblCurrentRes = new System.Windows.Forms.Label();
            this.lblRes = new System.Windows.Forms.Label();
            this.cmdOK = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.opt300 = new System.Windows.Forms.RadioButton();
            this.opt150 = new System.Windows.Forms.RadioButton();
            this.opt120 = new System.Windows.Forms.RadioButton();
            this.optCurrent = new System.Windows.Forms.RadioButton();
            this.lblSize = new System.Windows.Forms.Label();
            this.lblSizeVal = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // lblCurrentRes
            // 
            this.lblCurrentRes.Location = new System.Drawing.Point(24, 16);
            this.lblCurrentRes.Name = "lblCurrentRes";
            this.lblCurrentRes.Size = new System.Drawing.Size(160, 16);
            this.lblCurrentRes.TabIndex = 0;
            this.lblCurrentRes.Text = "Current Resolution";
          // 
          // lblRes
          // 
          this.lblRes.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
          this.lblRes.Location = new System.Drawing.Point(24, 32);
          this.lblRes.Name = "lblRes";
          this.lblRes.Size = new System.Drawing.Size(152, 16);
          this.lblRes.TabIndex = 1;
          // 
          // cmdOK
          // 
          this.cmdOK.Location = new System.Drawing.Point(232, 160);
          this.cmdOK.Name = "cmdOK";
          this.cmdOK.Size = new System.Drawing.Size(48, 32);
          this.cmdOK.TabIndex = 2;
          this.cmdOK.Text = "OK";
          this.cmdOK.Click += new System.EventHandler(this.cmdOK_Click);
          // 
          // groupBox1
          // 
          this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                                this.opt300,
                                                                                this.opt150,
                                                                                this.opt120,
                                                                                this.optCurrent});
          this.groupBox1.Location = new System.Drawing.Point(24, 64);
          this.groupBox1.Name = "groupBox1";
          this.groupBox1.Size = new System.Drawing.Size(168, 128);
          this.groupBox1.TabIndex = 3;
          this.groupBox1.TabStop = false;
          this.groupBox1.Text = "Save Resolution";
          // 
          // opt300
          // 
          this.opt300.Location = new System.Drawing.Point(16, 96);
          this.opt300.Name = "opt300";
          this.opt300.Size = new System.Drawing.Size(104, 16);
          this.opt300.TabIndex = 3;
          this.opt300.Text = "300 DPI";
          // 
          // opt150
          // 
          this.opt150.Location = new System.Drawing.Point(16, 72);
          this.opt150.Name = "opt150";
          this.opt150.Size = new System.Drawing.Size(104, 16);
          this.opt150.TabIndex = 2;
          this.opt150.Text = "150 DPI";
          // 
          // opt120
          // 
          this.opt120.Location = new System.Drawing.Point(16, 48);
          this.opt120.Name = "opt120";
          this.opt120.Size = new System.Drawing.Size(104, 16);
          this.opt120.TabIndex = 1;
          this.opt120.Text = "120 DPI";
          // 
          // optCurrent
          // 
          this.optCurrent.Location = new System.Drawing.Point(16, 24);
          this.optCurrent.Name = "optCurrent";
          this.optCurrent.Size = new System.Drawing.Size(104, 16);
          this.optCurrent.TabIndex = 0;
          this.optCurrent.Text = "Current";
          // 
          // lblSize
          // 
          this.lblSize.Location = new System.Drawing.Point(192, 16);
          this.lblSize.Name = "lblSize";
          this.lblSize.Size = new System.Drawing.Size(88, 16);
          this.lblSize.TabIndex = 4;
          this.lblSize.Text = "Size";
          // 
          // lblSizeVal
          // 
          this.lblSizeVal.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
          this.lblSizeVal.Location = new System.Drawing.Point(192, 32);
          this.lblSizeVal.Name = "lblSizeVal";
          this.lblSizeVal.Size = new System.Drawing.Size(88, 16);
          this.lblSizeVal.TabIndex = 5;
          // 
          // Attributes
          // 
          this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
          this.ClientSize = new System.Drawing.Size(294, 205);
          this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.lblSizeVal,
                                                                      this.lblSize,
                                                                      this.groupBox1,
                                                                      this.cmdOK,
                                                                      this.lblRes,
                                                                      this.lblCurrentRes});
          this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
          this.MaximizeBox = false;
          this.MinimizeBox = false;
          this.Name = "Attributes";
          this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
          this.Text = "Attributes";
          this.Load += new System.EventHandler(this.Attributes_Load);
          this.groupBox1.ResumeLayout(false);
          this.ResumeLayout(false);
        }
        #endregion
        private void Attributes_Load(object sender, System.EventArgs e) {
        }
        public float SaveRes { 
            get{
               return m_Res;
            } 
        }
        private void cmdOK_Click(object sender, System.EventArgs e)  {
            if (opt120.Checked)
                m_Res = 120f;
            if (opt150.Checked)
                m_Res = 150f;
            if (opt300.Checked)
                m_Res = 300f;
            this.Close();
        }
    }
    
}

<A href="http://www.nfex.ru/Code/CSharpDownload/Clipper-c.zip">Clipper-c.zip( 72 k)</a>


Transparent window: holes

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
  private System.Windows.Forms.PictureBox PictureBox4;
  private System.Windows.Forms.PictureBox PictureBox2;
  private System.Windows.Forms.PictureBox PictureBox1;
  private System.Windows.Forms.PictureBox PictureBox3;
  public Form1() {
        InitializeComponent();
  }
  private void InitializeComponent()
  {
    this.PictureBox4 = new System.Windows.Forms.PictureBox();
    this.PictureBox2 = new System.Windows.Forms.PictureBox();
    this.PictureBox1 = new System.Windows.Forms.PictureBox();
    this.PictureBox3 = new System.Windows.Forms.PictureBox();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox4)).BeginInit();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox2)).BeginInit();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox1)).BeginInit();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox3)).BeginInit();
    this.SuspendLayout();
    // 
    // PictureBox4
    // 
    this.PictureBox4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
    this.PictureBox4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.PictureBox4.Location = new System.Drawing.Point(156, 141);
    this.PictureBox4.Name = "PictureBox4";
    this.PictureBox4.Size = new System.Drawing.Size(76, 76);
    this.PictureBox4.TabIndex = 14;
    this.PictureBox4.TabStop = false;
    // 
    // PictureBox2
    // 
    this.PictureBox2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
    this.PictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.PictureBox2.Location = new System.Drawing.Point(60, 141);
    this.PictureBox2.Name = "PictureBox2";
    this.PictureBox2.Size = new System.Drawing.Size(76, 76);
    this.PictureBox2.TabIndex = 13;
    this.PictureBox2.TabStop = false;
    // 
    // PictureBox1
    // 
    this.PictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
    this.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.PictureBox1.Location = new System.Drawing.Point(156, 49);
    this.PictureBox1.Name = "PictureBox1";
    this.PictureBox1.Size = new System.Drawing.Size(76, 76);
    this.PictureBox1.TabIndex = 12;
    this.PictureBox1.TabStop = false;
    // 
    // PictureBox3
    // 
    this.PictureBox3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
    this.PictureBox3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.PictureBox3.Location = new System.Drawing.Point(60, 49);
    this.PictureBox3.Name = "PictureBox3";
    this.PictureBox3.Size = new System.Drawing.Size(76, 76);
    this.PictureBox3.TabIndex = 11;
    this.PictureBox3.TabStop = false;
    // 
    // Holes
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.PictureBox4);
    this.Controls.Add(this.PictureBox2);
    this.Controls.Add(this.PictureBox1);
    this.Controls.Add(this.PictureBox3);
    this.Name = "Holes";
    this.Text = "Holes";
    this.TransparencyKey = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox4)).EndInit();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox2)).EndInit();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox1)).EndInit();
    ((System.ruponentModel.ISupportInitialize)(this.PictureBox3)).EndInit();
    this.ResumeLayout(false);
  }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }
}


Transparent window: set Opacity

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
  private System.Windows.Forms.GroupBox GroupBox1;
  private System.Windows.Forms.Button cmdApply;
  private System.Windows.Forms.NumericUpDown udOpacity;
  private System.Windows.Forms.Label Label1;
  public Form1() {
        InitializeComponent();
  }

  private void cmdApply_Click(object sender, EventArgs e)
  {
    this.Opacity = (double)udOpacity.Value / 100;
  }
  private void InitializeComponent()
  {
    this.GroupBox1 = new System.Windows.Forms.GroupBox();
    this.cmdApply = new System.Windows.Forms.Button();
    this.udOpacity = new System.Windows.Forms.NumericUpDown();
    this.Label1 = new System.Windows.Forms.Label();
    this.GroupBox1.SuspendLayout();
    ((System.ruponentModel.ISupportInitialize)(this.udOpacity)).BeginInit();
    this.SuspendLayout();
    // 
    // GroupBox1
    // 
    this.GroupBox1.Controls.Add(this.cmdApply);
    this.GroupBox1.Controls.Add(this.udOpacity);
    this.GroupBox1.Controls.Add(this.Label1);
    this.GroupBox1.Location = new System.Drawing.Point(12, 89);
    this.GroupBox1.Name = "GroupBox1";
    this.GroupBox1.Size = new System.Drawing.Size(268, 116);
    this.GroupBox1.TabIndex = 5;
    this.GroupBox1.TabStop = false;
    // 
    // cmdApply
    // 
    this.cmdApply.Location = new System.Drawing.Point(172, 64);
    this.cmdApply.Name = "cmdApply";
    this.cmdApply.Size = new System.Drawing.Size(80, 24);
    this.cmdApply.TabIndex = 5;
    this.cmdApply.Text = "Apply";
    this.cmdApply.Click += new System.EventHandler(this.cmdApply_Click);
    // 
    // udOpacity
    // 
    this.udOpacity.Increment = new decimal(new int[] {
        5,
        0,
        0,
        0});
    this.udOpacity.Location = new System.Drawing.Point(88, 32);
    this.udOpacity.Name = "udOpacity";
    this.udOpacity.Size = new System.Drawing.Size(48, 21);
    this.udOpacity.TabIndex = 4;
    this.udOpacity.Value = new decimal(new int[] {
        50,
        0,
        0,
        0});
    // 
    // Label1
    // 
    this.Label1.Location = new System.Drawing.Point(20, 36);
    this.Label1.Name = "Label1";
    this.Label1.Size = new System.Drawing.Size(56, 16);
    this.Label1.TabIndex = 3;
    this.Label1.Text = "Opacity:";
    // 
    // Transparent
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(309, 289);
    this.Controls.Add(this.GroupBox1);
    this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "Transparent";
    this.Text = "Transparent";
    this.GroupBox1.ResumeLayout(false);
    ((System.ruponentModel.ISupportInitialize)(this.udOpacity)).EndInit();
    this.ResumeLayout(false);
  }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }
}