public TabPageEx(string name) : base() { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } this.editBox = new RichEditEx(); if (this.editBox == null) { throw new OutOfMemoryException(); } this.Text = name; this.Name = name; this.Padding = new Padding(0, 2, 2, 2); this.DoubleBuffered = true; this.UseVisualStyleBackColor = true; this.Controls.Add(this.editBox); this.editBox.TextMargin = new Padding(5); this.editBox.BorderStyle = BorderStyle.FixedSingle; this.editBox.Dock = DockStyle.Fill; this.editBox.Name = String.Format("{0}_EditBox", this.Text); this.editBox.WordWrap = false; this.editBox.TabIndex = 0; this.editBox.IsDirtyChanged += new EventHandler(this.OnEditBoxIsDirtyChanged); this.editBox.MouseDown += new MouseEventHandler(this.OnEditBoxMouseDown); }
private void PerformPaste(string label, RichEditEx editBox, IDataObject dataObject) { try { Debug.Assert(!String.IsNullOrEmpty(label)); if (dataObject == null) { Debug.WriteLine("PerformPaste(): Invalid data object!"); return; } if (this.tabEditView.TabPages.Count == 0) { this.PerformNew(); editBox = this.tabEditView.ActiveEditBox; } if (editBox == null) { Debug.WriteLine("PerformPaste(): Invalid drop target!"); return; } if (editBox != null) { // NOTE: At the moment, there is no proper way to change current cursor // to e.g. hourglass while data dropping takes places. // Move to current end of text. int offset = editBox.MoveEnd(); // Add another new line if necessary. if (offset > 0 && editBox.Text[offset - 1] != '\n') { editBox.AppendText(Environment.NewLine); editBox.MoveEnd(); } // Add label if required. if (this.UsePasteLabel) { // Ensure a gap to the leading text, if necessary. if (editBox.TextLength > 0) { editBox.AppendText(Environment.NewLine); editBox.MoveEnd(); } // Use date/time if required. if (this.UsePasteLabelDate) { label += String.Format(" ({0})", DateTime.Now.ToString("s")); } // Append label text including format. editBox.SelectionFont = this.GetLabelFont(editBox.Font); editBox.AppendText(label); // Move to new end of text. editBox.MoveEnd(); // Add more line feeds. editBox.SelectionFont = editBox.Font; editBox.AppendText(String.Format("{0}{0}", Environment.NewLine)); // Move to current end of text. editBox.MoveEnd(); } if (dataObject.GetDataPresent(DataFormats.Rtf)) { editBox.SelectedRtf = (string)dataObject.GetData(DataFormats.Rtf); } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { string helper = String.Empty; foreach (string current in (string[])dataObject.GetData(DataFormats.FileDrop)) { helper += String.Format("{0}{1}", current, Environment.NewLine); } editBox.AppendText(helper); } else if (dataObject.GetDataPresent(DataFormats.UnicodeText)) { editBox.AppendText((string)dataObject.GetData(DataFormats.UnicodeText)); } else if (dataObject.GetDataPresent(DataFormats.Text)) { editBox.AppendText((string)dataObject.GetData(DataFormats.Text)); } else if (!editBox.PasteSpecial(dataObject)) { Color color = editBox.SelectionColor; editBox.SelectionColor = Color.Red; editBox.AppendText("Could not paste data from the Clipboard!"); editBox.SelectionColor = color; } // Add another new line if necessary. if (editBox.TextLength > 0 && editBox.Text[editBox.TextLength - 1] != '\n') { editBox.MoveEnd(); editBox.AppendText(Environment.NewLine); } editBox.MoveEnd(); editBox.Invalidate(true); } } catch (Exception exception) { Debug.WriteLine(exception); } this.UpdateControlState(); }