Inheritance: System.Windows.Forms.ColorDialog
Beispiel #1
0
        private void ColorInputHelperToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!InputFromTextboxRadioButton.Checked)
            {
                MessageBox.Show(Properties.Resources.ONLY_INPUTMODE, "TeX2img");
                return;
            }
            var enUS = new System.Globalization.CultureInfo("en-US");
            Func <Color, string> GetColorString = (c) => {
                return("{" +
                       ((double)c.R / (double)255).ToString(enUS) + "," +
                       ((double)c.G / (double)255).ToString(enUS) + "," +
                       ((double)c.B / (double)255).ToString(enUS) + "}");
            };

            using (var cdg = new SupportInputColorDialog()) {
                cdg.CustomColors = (int[])Properties.Settings.Default.ColorDialogCustomColors.Clone();
                cdg.AnyColor     = true;
                if (cdg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    sourceTextBox.Document.SetSelection(sourceTextBox.CaretIndex, sourceTextBox.CaretIndex);
                    int startcaret = sourceTextBox.CaretIndex;
                    var colstring  = GetColorString(cdg.Color);
                    switch (cdg.CheckedControlSequence)
                    {
                    case SupportInputColorDialog.ControlSequence.colorbox:
                        sourceTextBox.Document.Replace("\\colorbox[rgb]" + colstring + "{}");
                        sourceTextBox.SetSelection(sourceTextBox.CaretIndex - 1, sourceTextBox.CaretIndex - 1);
                        break;

                    case SupportInputColorDialog.ControlSequence.textcolor:
                        sourceTextBox.Document.Replace("\\textcolor[rgb]" + colstring + "{}");
                        sourceTextBox.SetSelection(sourceTextBox.CaretIndex - 1, sourceTextBox.CaretIndex - 1);
                        break;

                    case SupportInputColorDialog.ControlSequence.definecolor:
                        sourceTextBox.Document.Replace("\\definecolor{}{rgb}" + colstring);
                        int shift = "\\definecolor{".Length;
                        sourceTextBox.SetSelection(startcaret + shift, startcaret + shift);
                        break;

                    case SupportInputColorDialog.ControlSequence.color:
                    default:
                        sourceTextBox.Document.Replace("\\color[rgb]" + colstring);
                        break;
                    }
                }
                cdg.CustomColors.CopyTo(Properties.Settings.Default.ColorDialogCustomColors, 0);
            }
        }
Beispiel #2
0
 private void ColorInputHelperToolStripMenuItem_Click(object sender, EventArgs e) {
     if(!InputFromTextboxRadioButton.Checked) {
         MessageBox.Show(Properties.Resources.ONLY_INPUTMODE,"TeX2img");
         return;
     }
     Func<Color, string> GetColorString = (c) => {
         return "{" + 
             ((double) c.R / (double) 255).ToString() + "," +
             ((double) c.G / (double) 255).ToString() + "," +
             ((double) c.B / (double) 255).ToString() + "}";
     };
     using(var cdg = new SupportInputColorDialog()) {
         cdg.CustomColors = (int[])Properties.Settings.Default.ColorDialogCustomColors.Clone();
         cdg.AnyColor = true;
         if(cdg.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
             sourceTextBox.Document.SetSelection(sourceTextBox.CaretIndex, sourceTextBox.CaretIndex);
             int startcaret = sourceTextBox.CaretIndex;
             var colstring = GetColorString(cdg.Color);
             switch(cdg.CheckedControlSequence) {
             case SupportInputColorDialog.ControlSequence.colorbox:
                 sourceTextBox.Document.Replace("\\colorbox[rgb]" + colstring + "{}");
                 sourceTextBox.SetSelection(sourceTextBox.CaretIndex-1,sourceTextBox.CaretIndex-1);
                 break;
             case SupportInputColorDialog.ControlSequence.textcolor:
                 sourceTextBox.Document.Replace("\\textcolor[rgb]" + colstring + "{}");
                 sourceTextBox.SetSelection(sourceTextBox.CaretIndex-1,sourceTextBox.CaretIndex-1);
                 break;
             case SupportInputColorDialog.ControlSequence.definecolor:
                 sourceTextBox.Document.Replace("\\definecolor{}{rgb}" + colstring);
                 int shift = "\\definecolor{".Length;
                 sourceTextBox.SetSelection(startcaret + shift,startcaret +shift);
                 break;
             case SupportInputColorDialog.ControlSequence.color:
             default:
                 sourceTextBox.Document.Replace("\\color[rgb]" + colstring);
                 break;
             }
         }
         cdg.CustomColors.CopyTo(Properties.Settings.Default.ColorDialogCustomColors, 0);
     }
 }