Longkong.ColorPicker.Controls.ColorSpaceComponent.txtComponentValue_LostFocus C# (CSharp) Method

txtComponentValue_LostFocus() private method

Handles the LostFocus event that the txtComponentValue object raises.
private txtComponentValue_LostFocus ( object sender, EventArgs e ) : void
sender object The source of the event.
e System.EventArgs An EventArgs containing the event data.
return void
        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();
        }