Exemple #1
0
        /// <summary>
        ///     編集項目コンボボックスの項目描画処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnItemComboBoxDrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            if (comboBox == null)
            {
                return;
            }
            MiscItemId   id   = (MiscItemId)comboBox.Tag;
            MiscItemType type = Misc.ItemTypes[(int)id];

            // 項目がなければ何もしない
            if (e.Index == -1)
            {
                return;
            }

            // 背景を描画する
            e.DrawBackground();

            // 項目の文字列を描画する
            Brush brush;
            int   index = 0;

            switch (type)
            {
            case MiscItemType.Bool:
                index = Misc.GetBool(id) ? 1 : 0;
                break;

            case MiscItemType.Enum:
                index = Misc.GetInt(id);
                break;
            }
            if ((e.Index + Misc.IntMinValues[id] == index) && Misc.IsDirty(id))
            {
                brush = new SolidBrush(Color.Red);
            }
            else
            {
                brush = new SolidBrush(SystemColors.WindowText);
            }
            string s = comboBox.Items[e.Index].ToString();

            e.Graphics.DrawString(s, e.Font, brush, e.Bounds);
            brush.Dispose();

            // フォーカスを描画する
            e.DrawFocusRectangle();
        }
Exemple #2
0
        /// <summary>
        ///     編集項目テキストボックスフォーカス移動後の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnItemTextBoxValidated(object sender, EventArgs e)
        {
            TextBox textBox = sender as TextBox;

            if (textBox == null)
            {
                return;
            }
            MiscItemId   id   = (MiscItemId)textBox.Tag;
            MiscItemType type = Misc.ItemTypes[(int)id];

            double d = 0;
            int    i = 0;

            // 変更後の文字列を数値に変換できなければ値を戻す
            switch (type)
            {
            case MiscItemType.Int:
            case MiscItemType.PosInt:
            case MiscItemType.NonNegInt:
            case MiscItemType.NonPosInt:
            case MiscItemType.NonNegIntMinusOne:
            case MiscItemType.NonNegInt1:
            case MiscItemType.RangedInt:
            case MiscItemType.RangedPosInt:
            case MiscItemType.RangedIntMinusOne:
            case MiscItemType.RangedIntMinusThree:
                if (!int.TryParse(textBox.Text, out i))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.Dbl:
            case MiscItemType.PosDbl:
            case MiscItemType.NonNegDbl:
            case MiscItemType.NonPosDbl:
            case MiscItemType.NonNegDbl0:
            case MiscItemType.NonNegDbl2:
            case MiscItemType.NonNegDbl5:
            case MiscItemType.NonPosDbl0:
            case MiscItemType.NonPosDbl2:
            case MiscItemType.NonNegDblMinusOne:
            case MiscItemType.NonNegDblMinusOne1:
            case MiscItemType.NonNegDbl2AoD:
            case MiscItemType.NonNegDbl4Dda13:
            case MiscItemType.NonNegDbl2Dh103Full:
            case MiscItemType.NonNegDbl2Dh103Full1:
            case MiscItemType.NonNegDbl2Dh103Full2:
            case MiscItemType.NonPosDbl5AoD:
            case MiscItemType.NonPosDbl2Dh103Full:
            case MiscItemType.RangedDbl:
            case MiscItemType.RangedDblMinusOne:
            case MiscItemType.RangedDblMinusOne1:
            case MiscItemType.RangedDbl0:
            case MiscItemType.NonNegIntNegDbl:
                if (!DoubleHelper.TryParse(textBox.Text, out d))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.None:
            case MiscItemType.Bool:
            case MiscItemType.Enum:
                break;
            }

            // 設定範囲外の値ならば戻す
            switch (type)
            {
            case MiscItemType.PosInt:
                if (i <= 0)
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.NonNegInt:
            case MiscItemType.NonNegInt1:
                if (i < 0)
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.NonPosInt:
                if (i > 0)
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.NonNegIntMinusOne:
                if ((i < 0) && (i != -1))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.RangedInt:
                if ((i < Misc.IntMinValues[id]) || (i > Misc.IntMaxValues[id]))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.RangedPosInt:
                if (i < Misc.IntMinValues[id])
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.RangedIntMinusOne:
                if (((i < Misc.IntMinValues[id]) || (i > Misc.IntMaxValues[id])) && (i != -1))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.RangedIntMinusThree:
                if (((i < Misc.IntMinValues[id]) || (i > Misc.IntMaxValues[id])) && (i != -1) && (i != -2) &&
                    (i != -3))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.PosDbl:
                if (d <= 0)
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.NonNegDbl:
            case MiscItemType.NonNegDbl0:
            case MiscItemType.NonNegDbl2:
            case MiscItemType.NonNegDbl5:
            case MiscItemType.NonNegDbl2AoD:
            case MiscItemType.NonNegDbl4Dda13:
            case MiscItemType.NonNegDbl2Dh103Full:
            case MiscItemType.NonNegDbl2Dh103Full1:
            case MiscItemType.NonNegDbl2Dh103Full2:
                if (d < 0)
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.NonPosDbl:
            case MiscItemType.NonPosDbl0:
            case MiscItemType.NonPosDbl2:
            case MiscItemType.NonPosDbl5AoD:
            case MiscItemType.NonPosDbl2Dh103Full:
                if (d > 0)
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.NonNegDblMinusOne:
            case MiscItemType.NonNegDblMinusOne1:
                if ((d < 0) && !DoubleHelper.IsEqual(d, -1))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.RangedDbl:
            case MiscItemType.RangedDbl0:
                if ((d < Misc.DblMinValues[id]) || (d > Misc.DblMaxValues[id]))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;

            case MiscItemType.RangedDblMinusOne:
            case MiscItemType.RangedDblMinusOne1:
                if (((d < Misc.DblMinValues[id]) || (d > Misc.DblMaxValues[id])) && !DoubleHelper.IsEqual(d, -1))
                {
                    textBox.Text = Misc.GetString(id);
                    return;
                }
                break;
            }

            // 値に変化がなければ何もしない
            switch (type)
            {
            case MiscItemType.Int:
            case MiscItemType.PosInt:
            case MiscItemType.NonNegInt:
            case MiscItemType.NonPosInt:
            case MiscItemType.NonNegIntMinusOne:
            case MiscItemType.NonNegInt1:
            case MiscItemType.RangedInt:
            case MiscItemType.RangedPosInt:
            case MiscItemType.RangedIntMinusOne:
            case MiscItemType.RangedIntMinusThree:
                if (i == Misc.GetInt(id))
                {
                    return;
                }
                break;

            case MiscItemType.Dbl:
            case MiscItemType.PosDbl:
            case MiscItemType.NonNegDbl:
            case MiscItemType.NonPosDbl:
            case MiscItemType.NonNegDbl0:
            case MiscItemType.NonNegDbl2:
            case MiscItemType.NonNegDbl5:
            case MiscItemType.NonPosDbl0:
            case MiscItemType.NonPosDbl2:
            case MiscItemType.NonNegDblMinusOne:
            case MiscItemType.NonNegDblMinusOne1:
            case MiscItemType.NonNegDbl2AoD:
            case MiscItemType.NonNegDbl4Dda13:
            case MiscItemType.NonNegDbl2Dh103Full:
            case MiscItemType.NonNegDbl2Dh103Full1:
            case MiscItemType.NonNegDbl2Dh103Full2:
            case MiscItemType.NonPosDbl5AoD:
            case MiscItemType.NonPosDbl2Dh103Full:
            case MiscItemType.RangedDbl:
            case MiscItemType.RangedDblMinusOne:
            case MiscItemType.RangedDblMinusOne1:
            case MiscItemType.RangedDbl0:
            case MiscItemType.NonNegIntNegDbl:
                if (DoubleHelper.IsEqual(d, Misc.GetDouble(id)))
                {
                    return;
                }
                break;
            }

            string old = Misc.GetString(id);

            // 値を更新する
            switch (type)
            {
            case MiscItemType.Int:
            case MiscItemType.PosInt:
            case MiscItemType.NonNegInt:
            case MiscItemType.NonPosInt:
            case MiscItemType.NonNegIntMinusOne:
            case MiscItemType.NonNegInt1:
            case MiscItemType.RangedInt:
            case MiscItemType.RangedPosInt:
            case MiscItemType.RangedIntMinusOne:
            case MiscItemType.RangedIntMinusThree:
                Misc.SetItem(id, i);
                break;

            case MiscItemType.Dbl:
            case MiscItemType.PosDbl:
            case MiscItemType.NonNegDbl:
            case MiscItemType.NonPosDbl:
            case MiscItemType.NonNegDbl0:
            case MiscItemType.NonNegDbl2:
            case MiscItemType.NonNegDbl5:
            case MiscItemType.NonPosDbl0:
            case MiscItemType.NonPosDbl2:
            case MiscItemType.NonNegDblMinusOne:
            case MiscItemType.NonNegDblMinusOne1:
            case MiscItemType.NonNegDbl2AoD:
            case MiscItemType.NonNegDbl4Dda13:
            case MiscItemType.NonNegDbl2Dh103Full:
            case MiscItemType.NonNegDbl2Dh103Full1:
            case MiscItemType.NonNegDbl2Dh103Full2:
            case MiscItemType.NonPosDbl5AoD:
            case MiscItemType.NonPosDbl2Dh103Full:
            case MiscItemType.RangedDbl:
            case MiscItemType.RangedDblMinusOne:
            case MiscItemType.RangedDblMinusOne1:
            case MiscItemType.RangedDbl0:
            case MiscItemType.NonNegIntNegDbl:
                Misc.SetItem(id, d);
                break;
            }

            Log.Info("[Misc] {0}: {1} -> {2}", Misc.GetItemName(id), old, Misc.GetString(id));

            // 編集済みフラグを設定する
            Misc.SetDirty(id);

            // 文字色を変更する
            textBox.ForeColor = Color.Red;

            // 他のフォームに更新を通知する
            NotifyItemChange(id);
        }
Exemple #3
0
        /// <summary>
        ///     編集項目を作成する
        /// </summary>
        /// <param name="tabPage">対象のタブページ</param>
        private void CreateEditableItems(TabPage tabPage)
        {
            List <List <MiscItemId> > table = tabPage.Tag as List <List <MiscItemId> >;

            if (table == null)
            {
                return;
            }

            Graphics g                   = Graphics.FromHwnd(Handle);
            int      itemHeight          = DeviceCaps.GetScaledHeight(25);
            int      labelStartX         = DeviceCaps.GetScaledWidth(10);
            int      labelStartY         = DeviceCaps.GetScaledHeight(13);
            int      editStartY          = DeviceCaps.GetScaledHeight(10);
            int      labelEditMargin     = DeviceCaps.GetScaledWidth(8);
            int      columnMargin        = DeviceCaps.GetScaledWidth(10);
            int      textBoxWidth        = DeviceCaps.GetScaledWidth(50);
            int      textBoxHeight       = DeviceCaps.GetScaledHeight(19);
            int      comboBoxWidthUnit   = DeviceCaps.GetScaledWidth(15);
            int      comboBoxWidthBase   = DeviceCaps.GetScaledWidth(50);
            int      comboBoxWidthMargin = DeviceCaps.GetScaledWidth(8);
            int      comboBoxHeight      = DeviceCaps.GetScaledHeight(20);

            int labelX = labelStartX;

            foreach (List <MiscItemId> list in table)
            {
                int labelY = labelStartY;
                int editX  = labelX; // 編集コントロールの右端X座標(左端ではない)
                foreach (MiscItemId id in list)
                {
                    // ラベルを作成する
                    Label label = new Label
                    {
                        Text     = Misc.GetItemName(id),
                        AutoSize = true,
                        Location = new Point(labelX, labelY)
                    };
                    string t = Misc.GetItemToolTip(id);
                    if (!string.IsNullOrEmpty(t))
                    {
                        miscToolTip.SetToolTip(label, t);
                    }
                    tabPage.Controls.Add(label);

                    // 編集コントロールの幅のみ求める
                    int          x    = labelX + label.Width + labelEditMargin;
                    MiscItemType type = Misc.ItemTypes[(int)id];
                    switch (type)
                    {
                    case MiscItemType.Bool:
                    case MiscItemType.Enum:
                        int maxWidth = comboBoxWidthBase;
                        for (int i = Misc.IntMinValues[id]; i <= Misc.IntMaxValues[id]; i++)
                        {
                            string s = Misc.GetItemChoice(id, i);
                            if (string.IsNullOrEmpty(s))
                            {
                                continue;
                            }
                            maxWidth = Math.Max(maxWidth,
                                                (int)g.MeasureString(s, Font).Width + SystemInformation.VerticalScrollBarWidth
                                                + comboBoxWidthMargin);
                            maxWidth = comboBoxWidthBase
                                       + (maxWidth - comboBoxWidthBase + (comboBoxWidthUnit - 1))
                                       / comboBoxWidthUnit * comboBoxWidthUnit;
                        }
                        x += maxWidth;
                        break;

                    default:
                        // テキストボックスの項目は固定
                        x += textBoxWidth;
                        break;
                    }
                    if (x > editX)
                    {
                        editX = x;
                    }
                    labelY += itemHeight;
                }
                int editY = editStartY;
                foreach (MiscItemId id in list)
                {
                    // 編集コントロールを作成する
                    MiscItemType type = Misc.ItemTypes[(int)id];
                    switch (type)
                    {
                    case MiscItemType.Bool:
                    case MiscItemType.Enum:
                        ComboBox comboBox = new ComboBox
                        {
                            DropDownStyle = ComboBoxStyle.DropDownList,
                            DrawMode      = DrawMode.OwnerDrawFixed,
                            Tag           = id
                        };
                        // コンボボックスの選択項目を登録し、最大幅を求める
                        int maxWidth = comboBoxWidthBase;
                        for (int i = Misc.IntMinValues[id]; i <= Misc.IntMaxValues[id]; i++)
                        {
                            string s = Misc.GetItemChoice(id, i);
                            if (string.IsNullOrEmpty(s))
                            {
                                continue;
                            }
                            comboBox.Items.Add(s);
                            maxWidth = Math.Max(maxWidth,
                                                (int)g.MeasureString(s, Font).Width + SystemInformation.VerticalScrollBarWidth
                                                + comboBoxWidthMargin);
                            maxWidth = comboBoxWidthBase
                                       + (maxWidth - comboBoxWidthBase + (comboBoxWidthUnit - 1))
                                       / comboBoxWidthUnit * comboBoxWidthUnit;
                        }
                        comboBox.Size                  = new Size(maxWidth, comboBoxHeight);
                        comboBox.Location              = new Point(editX - maxWidth, editY);
                        comboBox.DrawItem             += OnItemComboBoxDrawItem;
                        comboBox.SelectedIndexChanged += OnItemComboBoxSelectedIndexChanged;
                        tabPage.Controls.Add(comboBox);
                        break;

                    default:
                        TextBox textBox = new TextBox
                        {
                            Size      = new Size(textBoxWidth, textBoxHeight),
                            Location  = new Point(editX - textBoxWidth, editY),
                            TextAlign = HorizontalAlignment.Right,
                            Tag       = id
                        };
                        textBox.Validated += OnItemTextBoxValidated;
                        tabPage.Controls.Add(textBox);
                        break;
                    }
                    editY += itemHeight;
                }
                // 次の列との間を空ける
                labelX = editX + columnMargin;
            }
        }
Exemple #4
0
        /// <summary>
        ///     編集項目コンボボックスの選択項目変更時の処理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnItemComboBoxSelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBox = sender as ComboBox;

            if (comboBox == null)
            {
                return;
            }
            MiscItemId   id   = (MiscItemId)comboBox.Tag;
            MiscItemType type = Misc.ItemTypes[(int)id];

            if (comboBox.SelectedIndex == -1)
            {
                return;
            }

            bool b = false;
            int  i = 0;

            // 値に変化がなければ何もしない
            switch (type)
            {
            case MiscItemType.Bool:
                b = comboBox.SelectedIndex == 1;
                if (b == Misc.GetBool(id))
                {
                    return;
                }
                break;

            case MiscItemType.Enum:
                i = comboBox.SelectedIndex + Misc.IntMinValues[id];
                if (i == Misc.GetInt(id))
                {
                    return;
                }
                break;
            }

            // 値を更新する
            switch (type)
            {
            case MiscItemType.Bool:
                Log.Info("[Misc] {0}: {1} -> {2}", Misc.GetItemName(id),
                         Misc.GetItemChoice(id, Misc.GetBool(id) ? 1 : 0), Misc.GetItemChoice(id, b ? 1 : 0));
                Misc.SetItem(id, b);
                break;

            case MiscItemType.Enum:
                Log.Info("[Misc] {0}: {1} -> {2}", Misc.GetItemName(id),
                         Misc.GetItemChoice(id, Misc.GetInt(id)), Misc.GetItemChoice(id, i));
                Misc.SetItem(id, i);
                break;
            }

            // 編集済みフラグを設定する
            Misc.SetDirty(id);

            // 項目色を変更するために描画更新する
            comboBox.Refresh();
        }