.
In Depth Banner
Skip Navigation Links

Select your preferred language

The DialogTransEditor listing

 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

 

namespace TypeEditorsCS

{

 

  public class DialogTransEditor : System.Windows.Forms.Form

  {

 

    int _transparency;

    public int Transparency

    {

      get{return _transparency;}

      set

      {

        _transparency=value;

        this.trackBar1.Value=255-value;

        this.label1.Text=((255-value)*100/255).ToString("0.0")+"%";

      }

    }

 

 

    private System.Windows.Forms.TrackBar trackBar1;

    private System.Windows.Forms.Label label1;

    private System.Windows.Forms.Button button1;

    /// <summary>

    /// Required designer variable.

    /// </summary>

    private System.ComponentModel.Container components = null;

 

    public DialogTransEditor()

    {

      //

      // Required for Windows Form Designer support

      //

      InitializeComponent();

 

      this.SetStyle(ControlStyles.AllPaintingInWmPaint |

        ControlStyles.DoubleBuffer |

        ControlStyles.UserPaint,true);

    }

 

    /// <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.trackBar1 = new System.Windows.Forms.TrackBar();

      this.label1 = new System.Windows.Forms.Label();

      this.button1 = new System.Windows.Forms.Button();

      ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();

      this.SuspendLayout();

      //

      // trackBar1

      //

      this.trackBar1.Location = new System.Drawing.Point(0, 16);

      this.trackBar1.Maximum = 255;

      this.trackBar1.Name = "trackBar1";

      this.trackBar1.Orientation = System.Windows.Forms.Orientation.Vertical;

      this.trackBar1.Size = new System.Drawing.Size(45, 232);

      this.trackBar1.TabIndex = 0;

      this.trackBar1.TickFrequency = 8;

      this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);

      //

      // label1

      //

      this.label1.Font = new System.Drawing.Font("Tahoma", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

      this.label1.Location = new System.Drawing.Point(48, 8);

      this.label1.Name = "label1";

      this.label1.Size = new System.Drawing.Size(136, 48);

      this.label1.TabIndex = 1;

      //

      // button1

      //

      this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;

      this.button1.Location = new System.Drawing.Point(208, 16);

      this.button1.Name = "button1";

      this.button1.TabIndex = 2;

      this.button1.Text = "Ok";

      //

      // DialogTransEditor

      //

      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

      this.ClientSize = new System.Drawing.Size(292, 266);

      this.Controls.Add(this.button1);

      this.Controls.Add(this.label1);

      this.Controls.Add(this.trackBar1);

      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

      this.Name = "DialogTransEditor";

      this.Text = "Edit Transparency";

      this.Paint += new System.Windows.Forms.PaintEventHandler(this.DialogTransEditor_Paint);

      ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();

      this.ResumeLayout(false);

 

    }

    #endregion

 

    private void DialogTransEditor_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

    {

      e.Graphics.FillRectangle(Brushes.Black,64,96,192,100);

      SolidBrush sb=new SolidBrush(Color.FromArgb(_transparency,Color.Red));

      e.Graphics.FillRectangle(sb,168,64,88,168);

      sb.Dispose();

    }

 

    private void trackBar1_Scroll(object sender, System.EventArgs e)

    {

      float pc=((float)this.trackBar1.Value)/255*100f;

      this.label1.Text=pc.ToString("0.0")+"%";

      this._transparency=255-this.trackBar1.Value;

      this.Invalidate();

    }

  }

}

 

 

Return to the article.

Copyright © Bob Powell 2000-.  All rights reserved.