private void InitializeComponent() { this.lblComponentUnit = new System.Windows.Forms.Label(); this.txtComponentValue = new Longkong.ColorPicker.Controls.ColorSpaceComponentTextBox(); this.rdoComponent = new System.Windows.Forms.RadioButton(); this.lblComponent = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lblComponentUnit // this.lblComponentUnit.Location = new System.Drawing.Point(80, 6); this.lblComponentUnit.Name = "lblComponentUnit"; this.lblComponentUnit.Size = new System.Drawing.Size(16, 16); this.lblComponentUnit.TabIndex = 49; this.lblComponentUnit.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // txtComponentValue // this.txtComponentValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtComponentValue.Location = new System.Drawing.Point(40, 4); this.txtComponentValue.MaxLength = 3; this.txtComponentValue.Name = "txtComponentValue"; this.txtComponentValue.Size = new System.Drawing.Size(40, 20); this.txtComponentValue.TabIndex = 0; this.txtComponentValue.Text = ""; this.txtComponentValue.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtComponentValue_KeyDown); this.txtComponentValue.LostFocus += new System.EventHandler(this.txtComponentValue_LostFocus); this.txtComponentValue.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtComponentValue_KeyUp); this.txtComponentValue.ContextMenu = new ContextMenu(null); // // rdoComponent // this.rdoComponent.Location = new System.Drawing.Point(4, 2); this.rdoComponent.Name = "rdoComponent"; this.rdoComponent.Size = new System.Drawing.Size(36, 24); this.rdoComponent.TabIndex = 50; this.rdoComponent.Click += new System.EventHandler(this.rdoComponent_Click); // // lblComponent // this.lblComponent.Location = new System.Drawing.Point(18, 2); this.lblComponent.Name = "lblComponent"; this.lblComponent.Size = new System.Drawing.Size(20, 24); this.lblComponent.TabIndex = 51; this.lblComponent.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lblComponent.Visible = false; // // ColorSpaceComponent // this.Controls.Add(this.lblComponent); this.Controls.Add(this.lblComponentUnit); this.Controls.Add(this.txtComponentValue); this.Controls.Add(this.rdoComponent); this.Name = "ColorSpaceComponent"; this.Size = new System.Drawing.Size(112, 32); this.ResumeLayout(false); }
/// <summary> /// Handles the LostFocus event that the txtComponentValue object /// raises. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An EventArgs containing the event data.</param> private void txtComponentValue_LostFocus(object sender, EventArgs e) { ColorSpaceComponentTextBox textbox = ( ColorSpaceComponentTextBox )sender; int componentValue; int resetValue; bool showError = true; if (textbox.Text != null && textbox.Text.Length != 0) { componentValue = Int32.Parse(textbox.Text); resetValue = componentValue; if ((componentValue > this.MaximumValue)) { resetValue = this.MaximumValue; } else if (componentValue < this.MinimumValue) { resetValue = this.MinimumValue; } else { showError = false; } } else { resetValue = this.MinimumValue; } if (showError) { //MessageBox.Show( this, String.Format( "An integer between {0} and {1} is required. Closest value inserted.", this.MinimumValue, this.MaximumValue), "Color Picker", MessageBoxButtons.OK, MessageBoxIcon.Error ); } textbox.Text = resetValue.ToString(); }