Example #1
0
        private void LoadConfig(string path)
        {
            ImageTextBox.Text    = "";
            TemplateTextBox.Text = "";
            using (var file = File.OpenText(path))
            {
                while (!file.EndOfStream)
                {
                    var line        = file.ReadLine();
                    var split_point = line.IndexOf(':');
                    var key         = line.Substring(0, split_point).Trim();
                    var value       = line.Substring(split_point + 1);

                    switch (key)
                    {
                    case "XMLPath": XMLTextBox.Text = value; break;

                    case "XLSXPath": XLSXTextBox.Text = value; break;

                    case "Image": ImageTextBox.AppendText(value + Environment.NewLine); break;

                    case "CRR": Properties.CRRValue = float.Parse(value); break;

                    case "ICWR": Properties.ICWRValue = float.Parse(value); break;

                    case "Template": TemplateTextBox.AppendText(value + Environment.NewLine); break;
                    }
                }
            }

            TemplateTextBox.Text = TemplateTextBox.Text.TrimEnd();
            TemplateTextBox.SelectAll();
            TemplateTextBox_TextChanged(TemplateTextBox, EventArgs.Empty);
            TemplateTextBox.Select(0, 0);
        }
Example #2
0
        private void TemplateTextBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int os = TemplateTextBox.SelectionStart;
                int ol = TemplateTextBox.SelectionLength;

                for (int index = TemplateTextBox.GetLineFromCharIndex(os); index <=
                     TemplateTextBox.GetLineFromCharIndex(os + ol); index++)
                {
                    if (index < 0 || index >= TemplateTextBox.Lines.Length)
                    {
                        continue;
                    }
                    var line   = TemplateTextBox.Lines[index].Trim();
                    int start  = TemplateTextBox.GetFirstCharIndexFromLine(index);
                    int length = TemplateTextBox.Lines[index].Length;
                    var text   = TemplateTextBox.Text;


                    if (line.StartsWith("#"))
                    {
                        TemplateTextBox.SelectionStart  = start;
                        TemplateTextBox.SelectionLength = length;
                        TemplateTextBox.SelectionColor  = Color.Green;
                    }
                    else
                    {
                        bool in_value  = false;
                        int  cur_start = start;
                        for (int i = start; i < start + length; i++)
                        {
                            if (text[i] == '\"' && (i == 0 || text[i - 1] != '\\'))
                            {
                                if (in_value)
                                {
                                    TemplateTextBox.SelectionStart  = cur_start;
                                    TemplateTextBox.SelectionLength = i - cur_start + 1;
                                    TemplateTextBox.SelectionColor  = Color.Chocolate;
                                }
                                else
                                {
                                    TemplateTextBox.SelectionStart  = cur_start + 1;
                                    TemplateTextBox.SelectionLength = i - cur_start;
                                    TemplateTextBox.SelectionColor  = Color.Black;
                                }
                                cur_start = i;
                                in_value  = !in_value;
                            }
                        }

                        if (in_value)
                        {
                            TemplateTextBox.SelectionStart  = cur_start;
                            TemplateTextBox.SelectionLength = start + length - cur_start + 1;
                            TemplateTextBox.SelectionColor  = Color.Chocolate;
                        }
                        else
                        {
                            TemplateTextBox.SelectionStart  = cur_start + 1;
                            TemplateTextBox.SelectionLength = start + length - cur_start;
                            TemplateTextBox.SelectionColor  = Color.Black;
                        }
                    }
                }

                TemplateTextBox.SelectionStart  = os;
                TemplateTextBox.SelectionLength = ol;
            }
            catch { }
        }
 private void EnterInSituEdit()
 {
     if (!this.inSituMode)
     {
         if (this._miniToolStrip.Parent != null)
         {
             this._miniToolStrip.Parent.SuspendLayout();
         }
         try
         {
             this.Active = true;
             this.inSituMode = true;
             if (this.renderer != null)
             {
                 this.renderer.State = 1;
             }
             TextBox c = new TemplateTextBox(this._miniToolStrip, this) {
                 BorderStyle = BorderStyle.FixedSingle,
                 Text = this.centerLabel.Text,
                 ForeColor = SystemColors.WindowText
             };
             this.centerTextBox = new ToolStripControlHost(c);
             this.centerTextBox.Dock = DockStyle.None;
             this.centerTextBox.AutoSize = false;
             this.centerTextBox.Width = MINITOOLSTRIP_TEXTBOX_WIDTH;
             ToolStripDropDownItem activeItem = this.activeItem as ToolStripDropDownItem;
             if ((activeItem != null) && !activeItem.IsOnDropDown)
             {
                 this.centerTextBox.Margin = new Padding(1, 2, 1, 3);
             }
             else
             {
                 this.centerTextBox.Margin = new Padding(1);
             }
             this.centerTextBox.Size = this._miniToolStrip.DisplayRectangle.Size - this.centerTextBox.Margin.Size;
             this.centerTextBox.Name = "centerTextBox";
             this.centerTextBox.MouseEnter += new EventHandler(this.CenterTextBoxMouseEnter);
             this.centerTextBox.MouseLeave += new EventHandler(this.CenterTextBoxMouseLeave);
             int index = this._miniToolStrip.Items.IndexOf(this.centerLabel);
             if (index != -1)
             {
                 this._miniToolStrip.Items.Insert(index, this.centerTextBox);
                 this._miniToolStrip.Items.Remove(this.centerLabel);
             }
             c.KeyUp += new KeyEventHandler(this.OnKeyUp);
             c.KeyDown += new KeyEventHandler(this.OnKeyDown);
             c.SelectAll();
             Control rootComponent = null;
             if (this._designerHost != null)
             {
                 rootComponent = (Control) this._designerHost.RootComponent;
                 System.Design.NativeMethods.SendMessage(rootComponent.Handle, 11, 0, 0);
                 c.Focus();
                 System.Design.NativeMethods.SendMessage(rootComponent.Handle, 11, 1, 0);
             }
         }
         finally
         {
             if (this._miniToolStrip.Parent != null)
             {
                 this._miniToolStrip.Parent.ResumeLayout();
             }
         }
     }
 }