Transparent form : Irregularly Shaped Forms « GUI Windows Form « C# / C Sharp






Transparent form

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

           
       








Related examples in the same category

1.Transparent window: holes
2.Transparent window: set Opacity
3.Transparent form windowTransparent form window
4.Non rectangle Form windowNon rectangle Form window
5.Transparent window and screen captureTransparent window and screen capture
6.Irregularly Shaped Forms demo 1Irregularly Shaped Forms demo 1
7.Irregularly Shaped Forms DemoIrregularly Shaped Forms Demo
8.Transparent FormsTransparent Forms
9.Transparent Forms: holesTransparent Forms: holes