Click here to Skip to main content
11,716,249 members (86,478 online)
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads
Add your own
alternative version

Non-transparent controls on a semi-transparent window

, 6 Jul 2006 59.8K 3.1K 53
The article describes the use and the principle of operation of semi-transparent controls with non-transparent child controls.
transparent_controls_demo.zip
TestSkinControl
App.ico
bin
Debug
KBSoft.Components.dll
TestSkinControl.exe
TestSkinControl.exe.manifest
TestSkinControl.csproj.user
transparent_controls_src.zip
Components
bin
components
common
components.csproj.user
skincomponents
///////////////////////////////////////////////////////////////////////////////
//
//  File:           Form1.cs
//
//  Facility:		The unit contains the Form1 class.
//
//  Abstract:       The test application demonstrating the work of the 
//                  SkinTooltip control.
//
//  Environment:    VC 7.1
//
//  Author:         KB_Soft Group Ltd.
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using KBSoft.Components;

namespace TestSkinControl
{
	/// <summary>
	/// The main window class.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		#region Fields

        /// <summary>
        /// The pop-up tooltip.
        /// </summary>
		private KBSoft.Components.SkinTooltip skinTooltip1;
        /// <summary>
        /// the round button
        /// </summary>
		private KBSoft.Components.SkinButton skinButton1;
        /// <summary>
        /// the test combobox.
        /// </summary>
		private System.Windows.Forms.ComboBox comboBox1;
        /// <summary>
        /// the test button.
        /// </summary>
		private System.Windows.Forms.Button button3;

		private System.Windows.Forms.GroupBox groupBox1;
        /// <summary>
        /// the Animation type label.
        /// </summary>
		private System.Windows.Forms.Label label1;
        /// <summary>
        /// The "show tooltip" button.
        /// </summary>
		private System.Windows.Forms.Button showTooltipButton;
        /// <summary>
        /// The "hide tolltip" button.
        /// </summary>
		private System.Windows.Forms.Button hideTooltipButton;
        /// <summary>
        /// the combobox setting the animation type.
        /// </summary>
		private System.Windows.Forms.ComboBox animationTypeComboBox;
        /// <summary>
        /// The group of elements setting the animation.
        /// </summary>
		private System.Windows.Forms.GroupBox animationGroupBox;
        /// <summary>
        /// The checkbox managing the animation with the help of the alpha channel.
        /// </summary>
		private System.Windows.Forms.CheckBox alphaAnimationCheckBox;

        /// <summary>
        /// The checkbox managing the animation by changing the control's sizes.
        /// </summary>
		private System.Windows.Forms.CheckBox expandAnimationCheckBox;

        /// <summary>
        /// The Animation time text field.
        /// </summary>
		private System.Windows.Forms.Label label2;

        /// <summary>
        /// The filed of the NumericUpDown type that sets the period of the animation timer.
        /// </summary>
		private System.Windows.Forms.NumericUpDown animationTimeNumericUpDown;
        /// <summary>
        /// The Animation steps text field.
        /// </summary>
		private System.Windows.Forms.Label label3;
        /// <summary>
        /// The filed of the NumericUpDown type that sets the number of animation steps.
        /// </summary>
		private System.Windows.Forms.NumericUpDown animationStepsNumericUpDown;
        /// <summary>
        /// The form conatining the help text.
        /// </summary>
        private HelpForm helpForm = null;
        /// <summary>
        /// The button displaying the help window.
        /// </summary>
        private System.Windows.Forms.Button helpButton;
        /// <summary>
        /// The button displaying the help window.
        /// </summary>
        private System.Windows.Forms.Button button1;
        /// <summary>
        /// The button displaying the help window.
        /// </summary>
        private System.Windows.Forms.Button button2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		#endregion

		#region Constructors

        /// <summary>
        /// The class constructor.
        /// </summary>
		public Form1()
		{
			InitializeComponent();

			string[] enumMembers = Enum.GetNames( typeof(ExpandAnimationType) );

			foreach( string name in enumMembers )
			{
				animationTypeComboBox.Items.Add( name );
			}

			animationTypeComboBox.SelectedIndex = 1;

			skinTooltip1.ExpandType = ( ExpandAnimationType )Enum.Parse( typeof(ExpandAnimationType), 
				this.animationTypeComboBox.SelectedItem.ToString() );

			this.alphaAnimationCheckBox.Checked = skinTooltip1.AlphaAnimation;
			this.expandAnimationCheckBox.Checked = skinTooltip1.ExpandAnimation;

			this.animationTimeNumericUpDown.Value = skinTooltip1.AnimationInterval;
			this.animationStepsNumericUpDown.Value = skinTooltip1.AnimationSteps;

            helpForm = new HelpForm();
		}

		#endregion

		#region Methods
		/// <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()
		{
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
            this.skinTooltip1 = new KBSoft.Components.SkinTooltip();
            this.button2 = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.skinButton1 = new KBSoft.Components.SkinButton();
            this.helpButton = new System.Windows.Forms.Button();
            this.showTooltipButton = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.hideTooltipButton = new System.Windows.Forms.Button();
            this.animationTypeComboBox = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.animationGroupBox = new System.Windows.Forms.GroupBox();
            this.animationStepsNumericUpDown = new System.Windows.Forms.NumericUpDown();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.animationTimeNumericUpDown = new System.Windows.Forms.NumericUpDown();
            this.expandAnimationCheckBox = new System.Windows.Forms.CheckBox();
            this.alphaAnimationCheckBox = new System.Windows.Forms.CheckBox();
            ((System.ComponentModel.ISupportInitialize)(this.skinTooltip1)).BeginInit();
            this.skinTooltip1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.skinButton1)).BeginInit();
            this.animationGroupBox.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.animationStepsNumericUpDown)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.animationTimeNumericUpDown)).BeginInit();
            this.SuspendLayout();
            // 
            // skinTooltip1
            // 
            this.skinTooltip1.AlphaAnimation = true;
            this.skinTooltip1.AnimationInterval = 40;
            this.skinTooltip1.AnimationPosition = new System.Drawing.Point(16, 24);
            this.skinTooltip1.AnimationSteps = 20;
            this.skinTooltip1.BackgroundBitmap = null;
            this.skinTooltip1.Controls.Add(this.button2);
            this.skinTooltip1.Controls.Add(this.button1);
            this.skinTooltip1.Controls.Add(this.comboBox1);
            this.skinTooltip1.Controls.Add(this.skinButton1);
            this.skinTooltip1.ExpandAnimation = false;
            this.skinTooltip1.ExpandType = KBSoft.Components.ExpandAnimationType.FromLeftTopCorner;
            this.skinTooltip1.FrontImage = ((System.Drawing.Bitmap)(resources.GetObject("skinTooltip1.FrontImage")));
            this.skinTooltip1.Location = new System.Drawing.Point(16, 24);
            this.skinTooltip1.Name = "skinTooltip1";
            this.skinTooltip1.ObtainBackground = true;
            this.skinTooltip1.PatternBitmap = ((System.Drawing.Bitmap)(resources.GetObject("skinTooltip1.PatternBitmap")));
            this.skinTooltip1.Size = new System.Drawing.Size(565, 355);
            this.skinTooltip1.TabIndex = 0;
            this.skinTooltip1.TransparentColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
            this.skinTooltip1.UpdateBitmapsOnce = false;
            this.skinTooltip1.UseCashing = false;
            // 
            // button2
            // 
            this.button2.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.button2.Location = new System.Drawing.Point(376, 272);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(120, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "demo";
            // 
            // button1
            // 
            this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.button1.Location = new System.Drawing.Point(376, 232);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(120, 23);
            this.button1.TabIndex = 3;
            this.button1.Text = "demo";
            // 
            // comboBox1
            // 
            this.comboBox1.Location = new System.Drawing.Point(376, 200);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(121, 21);
            this.comboBox1.TabIndex = 2;
            this.comboBox1.Text = "comboBox1";
            // 
            // skinButton1
            // 
            this.skinButton1.DisabledImage = ((System.Drawing.Bitmap)(resources.GetObject("skinButton1.DisabledImage")));
            this.skinButton1.HotImage = ((System.Drawing.Bitmap)(resources.GetObject("skinButton1.HotImage")));
            this.skinButton1.Location = new System.Drawing.Point(368, 32);
            this.skinButton1.Name = "skinButton1";
            this.skinButton1.NormalImage = ((System.Drawing.Bitmap)(resources.GetObject("skinButton1.NormalImage")));
            this.skinButton1.PatternBitmap = ((System.Drawing.Bitmap)(resources.GetObject("skinButton1.PatternBitmap")));
            this.skinButton1.PressedImage = ((System.Drawing.Bitmap)(resources.GetObject("skinButton1.PressedImage")));
            this.skinButton1.Size = new System.Drawing.Size(136, 136);
            this.skinButton1.TabIndex = 0;
            this.skinButton1.TransparentColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255)));
            this.skinButton1.UseCashing = false;
            // 
            // helpButton
            // 
            this.helpButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.helpButton.Location = new System.Drawing.Point(24, 400);
            this.helpButton.Name = "helpButton";
            this.helpButton.Size = new System.Drawing.Size(88, 32);
            this.helpButton.TabIndex = 1;
            this.helpButton.Text = "Help";
            this.helpButton.Click += new System.EventHandler(this.helpButton_Click);
            // 
            // showTooltipButton
            // 
            this.showTooltipButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.showTooltipButton.Location = new System.Drawing.Point(128, 400);
            this.showTooltipButton.Name = "showTooltipButton";
            this.showTooltipButton.Size = new System.Drawing.Size(88, 32);
            this.showTooltipButton.TabIndex = 1;
            this.showTooltipButton.Text = "Show tooltip";
            this.showTooltipButton.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.button3.Location = new System.Drawing.Point(120, 40);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(112, 32);
            this.button3.TabIndex = 2;
            this.button3.Text = "button3";
            // 
            // groupBox1
            // 
            this.groupBox1.Location = new System.Drawing.Point(120, 104);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(176, 136);
            this.groupBox1.TabIndex = 3;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "groupBox1";
            // 
            // hideTooltipButton
            // 
            this.hideTooltipButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.hideTooltipButton.Location = new System.Drawing.Point(232, 400);
            this.hideTooltipButton.Name = "hideTooltipButton";
            this.hideTooltipButton.Size = new System.Drawing.Size(88, 32);
            this.hideTooltipButton.TabIndex = 5;
            this.hideTooltipButton.Text = "Hide tooltip";
            this.hideTooltipButton.Click += new System.EventHandler(this.button4_Click);
            // 
            // animationTypeComboBox
            // 
            this.animationTypeComboBox.Location = new System.Drawing.Point(24, 72);
            this.animationTypeComboBox.Name = "animationTypeComboBox";
            this.animationTypeComboBox.Size = new System.Drawing.Size(121, 21);
            this.animationTypeComboBox.TabIndex = 6;
            this.animationTypeComboBox.Text = "comboBox2";
            this.animationTypeComboBox.SelectedIndexChanged += new System.EventHandler(this.animationTypeComboBox_SelectedIndexChanged);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(24, 48);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(121, 16);
            this.label1.TabIndex = 9;
            this.label1.Text = "Animation type";
            // 
            // animationGroupBox
            // 
            this.animationGroupBox.Controls.Add(this.animationStepsNumericUpDown);
            this.animationGroupBox.Controls.Add(this.label3);
            this.animationGroupBox.Controls.Add(this.label2);
            this.animationGroupBox.Controls.Add(this.animationTimeNumericUpDown);
            this.animationGroupBox.Controls.Add(this.expandAnimationCheckBox);
            this.animationGroupBox.Controls.Add(this.alphaAnimationCheckBox);
            this.animationGroupBox.Controls.Add(this.animationTypeComboBox);
            this.animationGroupBox.Controls.Add(this.label1);
            this.animationGroupBox.Location = new System.Drawing.Point(24, 432);
            this.animationGroupBox.Name = "animationGroupBox";
            this.animationGroupBox.Size = new System.Drawing.Size(536, 104);
            this.animationGroupBox.TabIndex = 10;
            this.animationGroupBox.TabStop = false;
            this.animationGroupBox.Text = "Animation";
            // 
            // animationStepsNumericUpDown
            // 
            this.animationStepsNumericUpDown.Location = new System.Drawing.Point(448, 72);
            this.animationStepsNumericUpDown.Name = "animationStepsNumericUpDown";
            this.animationStepsNumericUpDown.Size = new System.Drawing.Size(64, 20);
            this.animationStepsNumericUpDown.TabIndex = 15;
            this.animationStepsNumericUpDown.ValueChanged += new System.EventHandler(this.animationStepsNumericUpDown_ValueChanged);
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(344, 73);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(88, 16);
            this.label3.TabIndex = 14;
            this.label3.Text = "Animation steps";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(344, 41);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(88, 16);
            this.label2.TabIndex = 13;
            this.label2.Text = "Animation time ";
            // 
            // animationTimeNumericUpDown
            // 
            this.animationTimeNumericUpDown.Location = new System.Drawing.Point(448, 40);
            this.animationTimeNumericUpDown.Name = "animationTimeNumericUpDown";
            this.animationTimeNumericUpDown.Size = new System.Drawing.Size(64, 20);
            this.animationTimeNumericUpDown.TabIndex = 12;
            this.animationTimeNumericUpDown.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
            // 
            // expandAnimationCheckBox
            // 
            this.expandAnimationCheckBox.Location = new System.Drawing.Point(184, 72);
            this.expandAnimationCheckBox.Name = "expandAnimationCheckBox";
            this.expandAnimationCheckBox.Size = new System.Drawing.Size(128, 16);
            this.expandAnimationCheckBox.TabIndex = 11;
            this.expandAnimationCheckBox.Text = "Expand animation";
            this.expandAnimationCheckBox.CheckedChanged += new System.EventHandler(this.expandAnimationCheckBox_CheckedChanged);
            // 
            // alphaAnimationCheckBox
            // 
            this.alphaAnimationCheckBox.Location = new System.Drawing.Point(184, 40);
            this.alphaAnimationCheckBox.Name = "alphaAnimationCheckBox";
            this.alphaAnimationCheckBox.Size = new System.Drawing.Size(120, 24);
            this.alphaAnimationCheckBox.TabIndex = 10;
            this.alphaAnimationCheckBox.Text = "Alpha animation";
            this.alphaAnimationCheckBox.CheckedChanged += new System.EventHandler(this.alphaAnimationCheckBox_CheckedChanged);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.SystemColors.Window;
            this.ClientSize = new System.Drawing.Size(592, 550);
            this.Controls.Add(this.skinTooltip1);
            this.Controls.Add(this.animationGroupBox);
            this.Controls.Add(this.hideTooltipButton);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.showTooltipButton);
            this.Controls.Add(this.helpButton);
            this.Name = "Form1";
            this.Text = "KB_Soft Demo";
            ((System.ComponentModel.ISupportInitialize)(this.skinTooltip1)).EndInit();
            this.skinTooltip1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.skinButton1)).EndInit();
            this.animationGroupBox.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.animationStepsNumericUpDown)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.animationTimeNumericUpDown)).EndInit();
            this.ResumeLayout(false);

        }
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run( new Form1() );
		}

        /// <summary>
        /// Responses the Show tooltip nutton pressure.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void button2_Click( object sender, System.EventArgs e )
		{
			this.skinTooltip1.Animate();
		}

        /// <summary>
        /// Responses the Hide tooltip nutton pressure.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void button4_Click(object sender, System.EventArgs e)
		{
			this.skinTooltip1.Hide();
		}

        /// <summary>
        /// Responses the user's sellecting another animation type.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void animationTypeComboBox_SelectedIndexChanged( object sender, System.EventArgs e )
		{
				skinTooltip1.ExpandType = ( ExpandAnimationType )Enum.Parse( typeof(ExpandAnimationType), 
					this.animationTypeComboBox.SelectedItem.ToString() );
		}

        /// <summary>
        /// Responses the user's choosing the Alpha Animation checkbox.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void alphaAnimationCheckBox_CheckedChanged(object sender, System.EventArgs e)
		{
			skinTooltip1.AlphaAnimation = this.alphaAnimationCheckBox.Checked;
		}

        /// <summary>
        /// Responses the user's choosing the Expand Animation checkbox.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void expandAnimationCheckBox_CheckedChanged(object sender, System.EventArgs e)
		{
			skinTooltip1.ExpandAnimation = this.expandAnimationCheckBox.Checked;
		}

        /// <summary>
        /// Responses the event of user's changing the step of the animation timer.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
		{
			skinTooltip1.AnimationInterval = (int)this.animationTimeNumericUpDown.Value;
		}

        /// <summary>
        /// Responses the event of user's changing the number of animation steps.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
		private void animationStepsNumericUpDown_ValueChanged(object sender, System.EventArgs e)
		{
			skinTooltip1.AnimationSteps = (int)this.animationStepsNumericUpDown.Value;
		}

        /// <summary>
        /// Responses the helpButton button pressure.
        /// </summary>
        /// <param name="sender">The object that invoked the event.</param>
        /// <param name="e">The event's parameters.</param>
        private void helpButton_Click(object sender, System.EventArgs e)
        {
            if( !helpForm.Visible )
            {
                helpForm = new HelpForm();
                helpForm.Show();
            }
        }

         #endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Alexandr Golovanov
Web Developer
Russian Federation Russian Federation
Alexandr Golovanov is a .NET developer at KB_Soft Group, an offshore software development company located in Russia, Novosibirsk. Here he has worked
on various .NET projects.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150901.1 | Last Updated 6 Jul 2006
Article Copyright 2006 by Alexandr Golovanov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid