Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        private void cbPattern_DrawItem(object sender, DrawItemEventArgs e)
        {
            ComboBox cb = (ComboBox)sender;
            Graphics g  = e.Graphics;

            // 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);

            try
            {
                switch (DrawUtils.FillModeFromIndex(e.Index))
                {
                case FillMode.None: ShowItemText(e, cb, g, largerect); break;

                case FillMode.Solid: ShowItemText(e, cb, g, largerect); break;

                case FillMode.LinearGradient:
                    using (LinearGradientBrush brush =
                               new LinearGradientBrush(largerect, fill.PatternColor, fill.Color,
                                                       DrawUtils.LinearGradientModeFromIndex(e.Index)))
                    {
                        g.FillRectangle(brush, largerect);
                    }
                    break;

                case FillMode.Hatch:
                    using (HatchBrush brush =
                               new HatchBrush(DrawUtils.HatchStyleFromIndex(e.Index),
                                              fill.PatternColor, fill.Color))
                    {
                        g.FillRectangle(brush, largerect);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
                throw;
            }
            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 5
0
        public StrokeProps(Draws drw)
        {
            InitializeComponent();
            // -------------------------------------------------------------------
            cbPattern.Items.Clear();
            cbPattern.Items.AddRange(DrawUtils.GetPenPatternNames()); // получение всех имён доступных типов линий
            cbPattern.SelectedIndex = 1;
            // -------------------------------------------------------------------
            cbWidth.Items.Clear();
            for (int i = 1; i < 61; i++)
            {
                cbWidth.Items.Add(i.ToString());
            }
            // -------------------------------------------------------------------
            cbColor.Items.Clear();
            cbColor.Items.AddRange(DrawUtils.GetAllColorNames()); // получение всех имён доступных цветов
            cbColor.Items.Add("Выбор цвета...");                  // добавление пункта выбора цвета
            cbColor.Text = DrawUtils.GetColorNameFromIndex(LastColorIndex);
            // -------------------------------------------------------------------
            stroke.Assign(drw.Stroke);
            // -------------------------------
            int Index = DrawUtils.ColorToIndex(stroke.Color);

            if (Index < 0)
            {
                DrawUtils.AddCustomColor(stroke.Color);
                cbColor.Items.Insert(cbColor.Items.Count - 1, "Мой цвет");
                Index = cbColor.Items.Count - 2;
            }
            if (Index >= 0)
            {
                cbColor.SelectedIndex = Index;
            }
            // -------------------------------
            tbTrasparent.Value = 255 - stroke.Alpha;
            lbTrasparent.Text  = String.Format("{0} %", (int)(tbTrasparent.Value / 255.0 * 100.0));
            // -------------------------------
            cbWidth.SelectedIndex = (int)stroke.Width - 1;
            // -------------------------------
            if (stroke.DashStyle == DashStyle.Custom)
            {
                cbPattern.SelectedIndex = 0;
            }
            else
            {
                cbPattern.SelectedIndex = (int)stroke.DashStyle + 1;
            }
            // -------------------------------------------------------------------
            cbLineJoin.Items.Clear();
            // получение всех имён доступных типов соединений линий
            cbLineJoin.Items.AddRange(DrawUtils.GetLineJoinNames());
            cbLineJoin.SelectedIndex = (int)stroke.LineJoin;
            // -------------------------------------------------------------------
            cbStartCap.Items.Clear();
            // получение всех имён доступных типов окончаний линий
            cbStartCap.Items.AddRange(DrawUtils.GetLineCapNames());
            cbStartCap.SelectedIndex = (int)stroke.StartCap;
            // -------------------------------------------------------------------
            cbEndCap.Items.Clear();
            // получение всех имён доступных типов окончаний линий
            cbEndCap.Items.AddRange(DrawUtils.GetLineCapNames());
            cbEndCap.SelectedIndex = (int)stroke.EndCap;
        }
Exemplo n.º 6
0
        public TextProps(Draws drw)
        {
            InitializeComponent();
            FontFamily[] ffam = FontFamily.Families;
            cbFont.Items.Clear();
            foreach (FontFamily ff in ffam)
            {
                cbFont.Items.Add(ff.Name);
            }
            // -------------------------------------------------------------------
            cbFont.SelectedIndex = cbFont.Items.IndexOf(cbFont.Text);
            cbColor.Items.Clear();
            // получение всех имён доступных цветов
            cbColor.Items.AddRange(DrawUtils.GetAllColorNames());
            // добавление пункта выбора цвета
            cbColor.Items.Add("Выбор цвета...");
            cbColor.Text = DrawUtils.GetColorNameFromIndex(LastColorIndex);
            // -------------------------------------------------------------------
            text.Assign(drw.Text);
            // -------------------------------
            int Index = DrawUtils.ColorToIndex(text.Color);

            if (Index < 0)
            {
                DrawUtils.AddCustomColor(text.Color);
                cbColor.Items.Insert(cbColor.Items.Count - 1, "Мой цвет");
                Index = cbColor.Items.Count - 2;
            }
            if (Index >= 0)
            {
                cbColor.SelectedIndex = Index;
            }
            // -------------------------------
            tbTrasparent.Value = 255 - text.Alpha;
            lbTrasparent.Text  = String.Format("{0} %",
                                               (int)(tbTrasparent.Value / 255.0 * 100.0));
            // -------------------------------
            cbFont.Text = text.FontName;
            // -------------------------------
            cbSize.Text = text.FontSize.ToString();
            // -------------------------------
            if (text.Bold && text.Italic)
            {
                cbStyle.SelectedIndex = 3;
            }
            else if (text.Bold)
            {
                cbStyle.SelectedIndex = 2;
            }
            else if (text.Italic)
            {
                cbStyle.SelectedIndex = 1;
            }
            else
            {
                cbStyle.SelectedIndex = 0;
            }
            // -------------------------------
            cbUnderline.Checked = text.Underline;
            // -------------------------------
            cbSrikeout.Checked = text.Strikeout;
            // -------------------------------
            cbHorizontal.SelectedIndex = (int)(text.Alignment);
            cbVertical.SelectedIndex   = (int)(text.LineAlignment);
            cbVerticalText.Checked     = text.Vertical;
        }
Exemplo n.º 7
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();
            }
        }