예제 #1
0
        //
        // Listbox activation
        //
        private void ActivateListBox()
        {
            KaiListBox.KaiListBox klb = null;

            switch (eDataType)
            {
            case EDataType.Stress:
            {
                klb = kaiListBoxStress;
                buttonAddStress.Enabled         = false;
                buttonAddLeftContext.Enabled    = true;
                buttonAddRightContext.Enabled   = true;
                buttonAddException.Enabled      = true;
                buttonAddOutputModifier.Enabled = true;
                InitializeStressCombo();

                break;
            }

            case EDataType.LeftContext:
            {
                klb = kaiListBoxLeftContext;
                buttonAddStress.Enabled         = true;
                buttonAddLeftContext.Enabled    = false;
                buttonAddRightContext.Enabled   = true;
                buttonAddException.Enabled      = true;
                buttonAddOutputModifier.Enabled = true;
                InitializeLeftContextCombo();

                break;
            }

            case EDataType.RightContext:
            {
                klb = kaiListBoxRightContext;
                buttonAddStress.Enabled         = true;
                buttonAddLeftContext.Enabled    = true;
                buttonAddRightContext.Enabled   = false;
                buttonAddException.Enabled      = true;
                buttonAddOutputModifier.Enabled = true;
                InitializeRightContextCombo();

                break;
            }

            case EDataType.Exceptions:
            {
                klb = kaiListBoxExceptions;
                buttonAddStress.Enabled         = true;
                buttonAddLeftContext.Enabled    = true;
                buttonAddRightContext.Enabled   = true;
                buttonAddException.Enabled      = false;
                buttonAddOutputModifier.Enabled = true;
                InitializeExceptionsCombo();

                break;
            }

            case EDataType.OutputModifiers:
            {
                klb = kaiListBoxOutputModifiers;
                buttonAddStress.Enabled         = true;
                buttonAddLeftContext.Enabled    = true;
                buttonAddRightContext.Enabled   = true;
                buttonAddOutputModifier.Enabled = false;
                InitializeOutputModifiersCombo();

                break;
            }

            case EDataType.InputTypeUndefined:
            {
                MessageBox.Show("Internal error: Unknown input type");
                return;
            }

            default:
            {
                MessageBox.Show("Internal error: Illegal input type");
                return;
            }
            }

            klb.BeginUpdate();

            klb.Items.Add("");
            iCurrentItem = klb.Items.Count - 1;
            Rectangle rcRow = klb.GetItemRectangle(iCurrentItem);

            if ((rcRow.Y + rcRow.Height > klb.Height) &&
                (klb.TopIndex < iCurrentItem))
            {
                ++klb.TopIndex;
                rcRow = klb.GetItemRectangle(iCurrentItem);
            }

            klb.EndUpdate();

            klb.Items.RemoveAt(iCurrentItem);

            Point ptLocation = klb.Location;

            ptLocation.Y += rcRow.Y;

            comboBox.Size     = new Size(rcRow.Width, rcRow.Height);
            comboBox.Location = ptLocation;
            comboBox.BringToFront();
            comboBox.DroppedDown = true;

            comboBox.EndUpdate();

            comboBox.Visible = true;
            comboBox.Focus();

            klb.DisableEdit = true;
        }   //  ActivateListBox()
예제 #2
0
        // Combos
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox.SelectedIndex < 0)
            {
                return;
            }

            KaiListBox.KaiListBox klb = null;
            Button btnAdd             = null;

            switch (eDataType)
            {
            case EDataType.InputTypeUndefined:
            {
                MessageBox.Show("Internal Error: InputTypeUndefined");
                return;
                //                    break;
            }

            case EDataType.Stress:
            {
                klb    = kaiListBoxStress;
                btnAdd = buttonAddStress;
                break;
            }

            case EDataType.LeftContext:
            {
                klb    = kaiListBoxLeftContext;
                btnAdd = buttonAddLeftContext;
                break;
            }

            case EDataType.RightContext:
            {
                klb    = kaiListBoxRightContext;
                btnAdd = buttonAddRightContext;
                break;
            }

            case EDataType.Exceptions:
            {
                klb    = kaiListBoxExceptions;
                btnAdd = buttonAddException;
                break;
            }

            case EDataType.OutputModifiers:
            {
                klb    = kaiListBoxOutputModifiers;
                btnAdd = buttonAddOutputModifier;
                break;
            }

            default:
            {
                MessageBox.Show("Internal Error: Illegal input type");
                return;
            }
            }

            klb.DisableEdit = false;

            // i couldn't figure out how to use ObjectCollection.Contains()
            bool bDuplicate = false;

            foreach (DataItem kvpLeft in klb.Items)
            {
                DataItem kvpRight =
                    (DataItem)comboBox.Items[comboBox.SelectedIndex];
                if ((kvpLeft.Key == kvpRight.Key) && (kvpLeft.Value == kvpRight.Value))
                {
                    bDuplicate = true;
                }
            }
            if (!bDuplicate)
            {
                klb.Items.Insert(iCurrentItem,
                                 comboBox.Items[comboBox.SelectedIndex]);
            }
            btnAdd.Enabled         = true;
            comboBox.Visible       = false;
            comboBox.SelectedIndex = -1;

            eDataType = EDataType.InputTypeUndefined;

            enableDisableButtons();
        }   //  comboBox_SelectedIndexChanged