예제 #1
0
        private void cbColor_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ComboBox cb = (ComboBox)sender;

            stroke.Color = DrawUtils.ColorFromIndex(cb.SelectedIndex);
            pbPreview.Refresh();
        }
예제 #2
0
        private void cbColor_SelectionChangeCommitted(object sender, System.EventArgs e)
        {
            ComboBox cb = (ComboBox)sender;

            if (cb == cbColor)
            {
                fill.Color = DrawUtils.ColorFromIndex(cb.SelectedIndex);
            }
            else
            {
                fill.PatternColor = DrawUtils.ColorFromIndex(cb.SelectedIndex);
            }
            cbPattern.Refresh();
            pbPreview.Refresh();
        }
예제 #3
0
        private void cbColor_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox cb         = (ComboBox)sender;
            Graphics g          = e.Graphics;
            Color    brushColor = DrawUtils.ColorFromIndex(e.Index);

            // Draw the background of the item.
            e.DrawBackground();
            Rectangle largerect = new Rectangle(e.Bounds.X, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1);
            Rectangle colorrect = new Rectangle(4, e.Bounds.Top + 2, e.Bounds.Height - 2, e.Bounds.Height - 5);

            if (DrawUtils.IsNamedColorIndex(e.Index)) // отрисовка рамки цвета пунктов основеых цветов
            {
                using (SolidBrush brush = new SolidBrush(brushColor))
                {
                    g.FillRectangle(brush, colorrect);
                }
                g.DrawRectangle(Pens.Black, colorrect);
            }
            RectangleF textRect = new RectangleF(e.Bounds.X + colorrect.Width + 5, e.Bounds.Y + 1,
                                                 e.Bounds.Width, e.Bounds.Height);

            using (SolidBrush textColor = new SolidBrush(e.ForeColor))
            {
                if (DrawUtils.IsNamedColorIndex(e.Index))
                {// отрисовка пунктов основных цветов
                    g.DrawString(DrawUtils.GetColorNameFromIndex(e.Index), cb.Font, textColor, textRect);
                }
                else
                if (DrawUtils.IsCustomColorIndex(e.Index))     // отрисовка пунктов дополнительных цветов
                {
                    using (SolidBrush brush = new SolidBrush(brushColor))
                    {
                        g.FillRectangle(brush, largerect);
                    }
                    using (Pen pen = new Pen(cb.BackColor))
                    {
                        g.DrawRectangle(pen, largerect);
                    }
                }
                else     // отрисовка последнего пункта: Выбор цвета...
                {
                    g.DrawString(cb.Items[e.Index].ToString(), cb.Font, textColor, largerect);
                }
            }
            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }
예제 #4
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();
            }
        }
예제 #5
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();
            }
        }