Click here to Skip to main content
15,892,809 members
Articles / Desktop Programming / Windows Forms

Using Color to Perform Hit Testing

Rate me:
Please Sign up or sign in to vote.
3.86/5 (3 votes)
4 May 2010CPOL9 min read 25.8K   876   5  
Provide a Color Hit Testing User Control that supports hit testing using color
using System;
using System.Drawing;

namespace TimeZonesDemo
    {
    partial class Form1
        {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose ( bool disposing )
            {
            if ( disposing && ( 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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager ( typeof ( Form1 ) );
            this.tz_name_LAB = new System.Windows.Forms.Label ( );
            this.tz_color_LAB = new System.Windows.Forms.Label ( );
            this.desired_width_LAB = new System.Windows.Forms.Label ( );
            this.desired_width_NUD = new System.Windows.Forms.NumericUpDown ( );
            this.time_zones_CH = new ColorHitTest.ColorHitTest ( );
            this.click_on_map_LAB = new System.Windows.Forms.Label ( );
            ( ( System.ComponentModel.ISupportInitialize ) ( this.desired_width_NUD ) ).BeginInit ( );
            this.SuspendLayout ( );
            // 
            // tz_name_LAB
            // 
            this.tz_name_LAB.AutoSize = true;
            this.tz_name_LAB.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.tz_name_LAB.Location = new System.Drawing.Point ( 287, 11 );
            this.tz_name_LAB.Name = "tz_name_LAB";
            this.tz_name_LAB.Size = new System.Drawing.Size ( 60, 15 );
            this.tz_name_LAB.TabIndex = 1;
            this.tz_name_LAB.Text = "                 ";
            // 
            // tz_color_LAB
            // 
            this.tz_color_LAB.AutoSize = true;
            this.tz_color_LAB.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.tz_color_LAB.Location = new System.Drawing.Point ( 355, 11 );
            this.tz_color_LAB.Name = "tz_color_LAB";
            this.tz_color_LAB.Size = new System.Drawing.Size ( 60, 15 );
            this.tz_color_LAB.TabIndex = 2;
            this.tz_color_LAB.Text = "                 ";
            // 
            // desired_width_LAB
            // 
            this.desired_width_LAB.AutoSize = true;
            this.desired_width_LAB.Location = new System.Drawing.Point ( 12, 11 );
            this.desired_width_LAB.Name = "desired_width_LAB";
            this.desired_width_LAB.Size = new System.Drawing.Size ( 109, 13 );
            this.desired_width_LAB.TabIndex = 4;
            this.desired_width_LAB.Text = "Desired Width (pixels)";
            // 
            // desired_width_NUD
            // 
            this.desired_width_NUD.Increment = new decimal ( new int [ ] {
            50,
            0,
            0,
            0} );
            this.desired_width_NUD.Location = new System.Drawing.Point ( 131, 7 );
            this.desired_width_NUD.Maximum = new decimal ( new int [ ] {
            600,
            0,
            0,
            0} );
            this.desired_width_NUD.Minimum = new decimal ( new int [ ] {
            100,
            0,
            0,
            0} );
            this.desired_width_NUD.Name = "desired_width_NUD";
            this.desired_width_NUD.Size = new System.Drawing.Size ( 50, 20 );
            this.desired_width_NUD.TabIndex = 5;
            this.desired_width_NUD.Value = new decimal ( new int [ ] {
            100,
            0,
            0,
            0} );
            this.desired_width_NUD.ValueChanged += new System.EventHandler ( this.desired_width_NUD_ValueChanged );
            // 
            // time_zones_CH
            // 
            this.time_zones_CH.Location = new System.Drawing.Point ( 12, 45 );
            this.time_zones_CH.Name = "time_zones_CH";
            this.time_zones_CH.Size = new System.Drawing.Size ( 100, 100 );
            this.time_zones_CH.TabIndex = 3;
            // 
            // click_on_map_LAB
            // 
            this.click_on_map_LAB.AutoSize = true;
            this.click_on_map_LAB.Location = new System.Drawing.Point ( 187, 11 );
            this.click_on_map_LAB.Name = "click_on_map_LAB";
            this.click_on_map_LAB.Size = new System.Drawing.Size ( 69, 13 );
            this.click_on_map_LAB.TabIndex = 6;
            this.click_on_map_LAB.Text = "Click on Map";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF ( 6F, 13F );
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size ( 444, 312 );
            this.Controls.Add ( this.click_on_map_LAB );
            this.Controls.Add ( this.desired_width_NUD );
            this.Controls.Add ( this.desired_width_LAB );
            this.Controls.Add ( this.time_zones_CH );
            this.Controls.Add ( this.tz_color_LAB );
            this.Controls.Add ( this.tz_name_LAB );
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ( ( System.Drawing.Icon ) ( resources.GetObject ( "$this.Icon" ) ) );
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.Text = "Time Zones Demo";
            ( ( System.ComponentModel.ISupportInitialize ) ( this.desired_width_NUD ) ).EndInit ( );
            this.ResumeLayout ( false );
            this.PerformLayout ( );

            }

        #endregion

        private System.Windows.Forms.Label tz_name_LAB;
        private System.Windows.Forms.Label tz_color_LAB;
        private ColorHitTest.ColorHitTest time_zones_CH;
        private System.Windows.Forms.Label desired_width_LAB;
        private System.Windows.Forms.NumericUpDown desired_width_NUD;
        private System.Windows.Forms.Label click_on_map_LAB;
        }
    }

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
In 1964, I was in the US Coast Guard when I wrote my first program. It was written in RPG (note no suffixing numbers). Programs and data were entered using punched cards. Turnaround was about 3 hours. So much for the "good old days!"

In 1970, when assigned to Washington DC, I started my MS in Mechanical Engineering. I specialized in Transportation. Untold hours in statistical theory and practice were required, forcing me to use the university computer and learn the FORTRAN language, still using punched cards!

In 1973, I was employed by the Norfolk VA Police Department as a crime analyst for the High Intensity Target program. There, I was still using punched cards!

In 1973, I joined Computer Sciences Corporation (CSC). There, for the first time, I was introduced to a terminal with the ability to edit, compile, link, and test my programs on-line. CSC also gave me the opportunity to discuss technical issues with some of the brightest minds I've encountered during my career.

In 1975, I moved to San Diego to head up an IR&D project, BIODAB. I returned to school (UCSD) and took up Software Engineering at the graduate level. After BIODAB, I headed up a team that fixed a stalled project. I then headed up one of the two most satisfying projects of my career, the Automated Flight Operations Center at Ft. Irwin, CA.

I left Anteon Corporation (the successor to CSC on a major contract) and moved to Pensacola, FL. For a small company I built their firewall, given free to the company's customers. An opportunity to build an air traffic controller trainer arose. This was the other most satisfying project of my career.

Today, I consider myself capable.

Comments and Discussions