Add image to Label and set ImageAlign to MiddleRight


   


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    private System.Windows.Forms.Label label1;

  public Form1() {
        InitializeComponent();
  }

    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();

        this.label1.Image = new Bitmap("winter.jpg");
        this.label1.ImageAlign = System.Drawing.ContentAlignment.TopRight;
        this.label1.Location = new System.Drawing.Point(20, 9);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(105, 77);
        this.label1.TabIndex = 0;
        this.label1.Text = "label1";

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(299, 271);

        this.Controls.Add(this.label1);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "ImagesInCommonControls";
        this.Text = "ImagesInCommonControls";
        this.ResumeLayout(false);

    }

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

}


           
          


Label: Localtion, Name, Size, TabIndex, Text

   
 

using System;
using System.Windows.Forms;

class MainForm : Form
{
    private Label label1;
    private TextBox textBox1;
    private Button button1;

    public MainForm()
    {
         this.label1 = new Label();
         this.textBox1 = new TextBox();
         this.button1 = new Button();
         this.SuspendLayout();

         this.label1.Location = new System.Drawing.Point(16, 36);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(128, 16);
         this.label1.TabIndex = 0;
         this.label1.Text = "Please enter your name:"; 

         this.textBox1.Location = new System.Drawing.Point(152, 32);
         this.textBox1.Name = "textBox1";
         this.textBox1.TabIndex = 1;
         this.textBox1.Text = "";

         this.button1.Location = new System.Drawing.Point(109, 80);
         this.button1.Name = "button1";
         this.button1.TabIndex = 2;
         this.button1.Text = "Enter";
         this.button1.Click += new System.EventHandler(this.button1_Click);

         this.ClientSize = new System.Drawing.Size(292, 126);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.textBox1);
         this.Controls.Add(this.label1);
         this.Name = "form1";
         this.Text = "Visual C#";

         this.ResumeLayout(false);
     }
     private void button1_Click(object sender, System.EventArgs e)
     {
        System.Console.WriteLine("User entered: " + textBox1.Text);
        MessageBox.Show("Welcome, " + textBox1.Text, "Visual C#");
     }
     [STAThread]
     public static void Main()
     {
        Application.EnableVisualStyles();
        Application.Run(new MainForm());
     }
}

    


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.ComponentModel;
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.ComponentModel.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: 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.ComponentModel;
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.ComponentModel.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 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.ComponentModel;
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.ComponentModel.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.ComponentModel.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.ComponentModel.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());
        }
    }
}



           
          


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.ComponentModel;
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.ComponentModel.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.ComponentModel;
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.ComponentModel.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.components = new System.ComponentModel.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.components);
      this.imgSelectedButtons = new System.Windows.Forms.ImageList(this.components);
      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&#039;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;
    }

  }



           
          


IrregularlyShapedForms.zip( 164 k)