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

txtComponentValue_KeyDown() private method

private txtComponentValue_KeyDown ( object sender, KeyEventArgs e ) : void
sender object
e System.Windows.Forms.KeyEventArgs
return void
        private void txtComponentValue_KeyDown(object sender, KeyEventArgs e)
        {
            if ( txtComponentValue.Text.Length > 0 &&
                ( ( e.KeyData | Keys.Shift ) == ( Keys.Up | Keys.Shift ) ||
                ( e.KeyData | Keys.Shift ) == ( Keys.Down | Keys.Shift ) ) ) {

                int componentValue = Int16.Parse( txtComponentValue.Text );
                int incrementValue = 0;

                if ( ( e.KeyData & Keys.Shift ) == Keys.Shift ) {
                    incrementValue = 0x00000A;
                } else {
                    incrementValue = 0x000001;
                }

                if ( ( e.KeyData & Keys.Up ) == Keys.Up ) {

                    if ( componentValue + incrementValue <= this.MaximumValue ) {
                        componentValue += incrementValue;
                    } else {
                        componentValue = this.MaximumValue;
                    }

                } else if ( ( e.KeyData | Keys.Shift ) == ( Keys.Down | Keys.Shift ) ) {

                    if ( e.KeyData == ( Keys.Down | Keys.Shift ) ) {
                        incrementValue = -10;
                    } else {
                        incrementValue = -1;
                    }

                    if ( componentValue + incrementValue > this.MinimumValue ) {
                        componentValue += incrementValue;
                    } else {
                        componentValue = this.MinimumValue;
                    }

                }

                txtComponentValue.Text = componentValue.ToString();
                ComponentTextKeyUp( this, EventArgs.Empty );

                // this is a hack to fix some of the problems with the key
                // combination selecting part of the text (only happens
                // with shift+down).
                //
                // TODO: see if there is a better way to do this.

                if ( e.KeyData == ( Keys.Shift | Keys.Down ) ) {
                    txtComponentValue.SelectionStart = txtComponentValue.Text.Length;
                }

            }
        }