Exemplo n.º 1
0
        private void cbColor_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cbox = (ComboBox)sender;

            if (cbox.SelectedIndex == cbox.Items.Count - 1)
            {
                try
                {
                    int selIndex;
                    dlgSelectColor.Color = DrawUtils.ColorFromIndex(LastColorIndex);
                    selIndex             = LastColorIndex;
                    if (dlgSelectColor.ShowDialog() == DialogResult.OK)
                    {
                        Color selColor = dlgSelectColor.Color;
                        stroke.Color = selColor;
                        if (!DrawUtils.FindColor(selColor))
                        {
                            DrawUtils.AddCustomColor(selColor);
                            dlgSelectColor.CustomColors = DrawUtils.GetCustomColors();
                            cbColor.Items.Insert(cbColor.Items.Count - 1, "Мой цвет");
                            cbColor.SelectedIndex = cbColor.Items.Count - 2;
                        }
                        else
                        {
                            cbox.SelectedIndex = DrawUtils.ColorToIndex(selColor);
                        }
                    }
                    else
                    {
                        cbox.SelectedIndex = selIndex;
                    }
                }
                catch
                { }
            }
            else
            {
                LastColorIndex = cbox.SelectedIndex;
                cbox.Refresh();
                pbPreview.Refresh();
            }
        }
Exemplo n.º 2
0
        private void cbColor_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            ComboBox cbox = (ComboBox)sender;

            if (cbox.SelectedIndex == cbox.Items.Count - 1)
            {
                try
                {
                    int selIndex;
                    if (cbox == cbColor)
                    {
                        dlgSelectColor.Color = DrawUtils.ColorFromIndex(LastColorIndex);
                        selIndex             = LastColorIndex;
                    }
                    else
                    {
                        dlgSelectColor.Color = DrawUtils.ColorFromIndex(LastPatternColorIndex);
                        selIndex             = LastPatternColorIndex;
                    }
                    if (dlgSelectColor.ShowDialog() == DialogResult.OK)
                    {
                        Color selColor = dlgSelectColor.Color;
                        if (cbox == cbColor)
                        {
                            fill.Color = selColor;
                        }
                        else
                        {
                            fill.PatternColor = selColor;
                        }
                        if (!DrawUtils.FindColor(selColor))
                        {
                            DrawUtils.AddCustomColor(selColor);
                            dlgSelectColor.CustomColors = DrawUtils.GetCustomColors();
                            cbColor.Items.Insert(cbColor.Items.Count - 1, "Мой цвет");
                            cbColorPattern.Items.Insert(cbColorPattern.Items.Count - 1, "Мой цвет");
                            if (cbox == cbColor)
                            {
                                cbColor.SelectedIndex = cbColor.Items.Count - 2;
                            }
                            else
                            {
                                cbColorPattern.SelectedIndex = cbColorPattern.Items.Count - 2;
                            }
                        }
                        else
                        {
                            cbox.SelectedIndex = DrawUtils.ColorToIndex(selColor);
                        }
                    }
                    else
                    {
                        cbox.SelectedIndex = selIndex;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0} Exception caught.", ex);
                    throw;
                }
            }
            else
            {
                if (cbox == cbColor)
                {
                    LastColorIndex = cbox.SelectedIndex;
                }
                else
                {
                    LastPatternColorIndex = cbox.SelectedIndex;
                }
                cbox.Refresh();
                pbPreview.Refresh();
            }
        }