Lines
{
get { return lines.GetLines(); }
}
///
/// Gets colored text as HTML
///
/// For more flexibility you can use ExportToHTML class also
[Browsable(false)]
public string Html
{
get
{
var exporter = new ExportToHTML();
exporter.UseNbsp = false;
exporter.UseStyleTag = false;
exporter.UseBr = false;
return "" + exporter.GetHtml(this) + "
";
}
}
///
/// Gets colored text as RTF
///
/// For more flexibility you can use ExportToRTF class also
[Browsable(false)]
public string Rtf
{
get
{
var exporter = new ExportToRTF();
return exporter.GetRtf(this);
}
}
///
/// Text of current selection
///
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string SelectedText
{
get { return Selection.Text; }
set { InsertText(value); }
}
///
/// Start position of selection
///
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int SelectionStart
{
get { return Math.Min(PlaceToPosition(Selection.Start), PlaceToPosition(Selection.End)); }
set { Selection.Start = PositionToPlace(value); }
}
///
/// Length of selected text
///
[Browsable(false)]
[DefaultValue(0)]
public int SelectionLength
{
get { return Math.Abs(PlaceToPosition(Selection.Start) - PlaceToPosition(Selection.End)); }
set
{
if (value > 0)
Selection.End = PositionToPlace(SelectionStart + value);
}
}
///
/// Font
///
/// Use only monospaced font
[DefaultValue(typeof (Font), "Courier New, 9.75")]
public override Font Font
{
get { return BaseFont; }
set {
originalFont = (Font)value.Clone();
SetFont(value);
}
}
Font baseFont;
///
/// Font
///
/// Use only monospaced font
[DefaultValue(typeof(Font), "Courier New, 9.75")]
private Font BaseFont
{
get { return baseFont; }
set
{
baseFont = value;
}
}
private void SetFont(Font newFont)
{
BaseFont = newFont;
//check monospace font
SizeF sizeM = GetCharSize(BaseFont, 'M');
SizeF sizeDot = GetCharSize(BaseFont, '.');
if (sizeM != sizeDot)
BaseFont = new Font("Courier New", BaseFont.SizeInPoints, FontStyle.Regular, GraphicsUnit.Point);
//clac size
SizeF size = GetCharSize(BaseFont, 'M');
CharWidth = (int) Math.Round(size.Width*1f /*0.85*/) - 1 /*0*/;
CharHeight = lineInterval + (int) Math.Round(size.Height*1f /*0.9*/) - 1 /*0*/;
//
//if (wordWrap)
// RecalcWordWrap(0, Lines.Count - 1);
NeedRecalc(false, wordWrap);
//
Invalidate();
}
public new Size AutoScrollMinSize
{
set
{
if (scrollBars)
{
if (!base.AutoScroll)
base.AutoScroll = true;
Size newSize = value;
if (WordWrap && WordWrapMode != FastColoredTextBoxNS.WordWrapMode.Custom)
{
int maxWidth = GetMaxLineWordWrapedWidth();
newSize = new Size(Math.Min(newSize.Width, maxWidth), newSize.Height);
}
base.AutoScrollMinSize = newSize;
}
else
{
if (base.AutoScroll)
base.AutoScroll = false;
base.AutoScrollMinSize = new Size(0, 0);
VerticalScroll.Visible = false;
HorizontalScroll.Visible = false;
VerticalScroll.Maximum = Math.Max(0, value.Height - ClientSize.Height);
HorizontalScroll.Maximum = Math.Max(0, value.Width - ClientSize.Width);
localAutoScrollMinSize = value;
}
}
get
{
if (scrollBars)
return base.AutoScrollMinSize;
else
//return new Size(HorizontalScroll.Maximum, VerticalScroll.Maximum);
return localAutoScrollMinSize;
}
}
///
/// Indicates that IME is allowed (for CJK language entering)
///
[Browsable(false)]
public bool ImeAllowed
{
get
{
return ImeMode != ImeMode.Disable &&
ImeMode != ImeMode.Off &&
ImeMode != ImeMode.NoControl;
}
}
///
/// Is undo enabled?
///
[Browsable(false)]
public bool UndoEnabled
{
get { return lines.Manager.UndoEnabled; }
}
///
/// Is redo enabled?
///
[Browsable(false)]
public bool RedoEnabled
{
get { return lines.Manager.RedoEnabled; }
}
private int LeftIndentLine
{
get { return LeftIndent - minLeftIndent/2 - 3; }
}
///
/// Range of all text
///
[Browsable(false)]
public Range Range
{
get { return new Range(this, new Place(0, 0), new Place(lines[lines.Count - 1].Count, lines.Count - 1)); }
}
///
/// Color of selected area
///
[DefaultValue(typeof (Color), "Blue")]
[Description("Color of selected area.")]
public virtual Color SelectionColor
{
get { return selectionColor; }
set
{
selectionColor = value;
if (selectionColor.A == 255)
selectionColor = Color.FromArgb(60, selectionColor);
SelectionStyle = new SelectionStyle(new SolidBrush(selectionColor));
Invalidate();
}
}
public override Cursor Cursor
{
get { return base.Cursor; }
set
{
defaultCursor = value;
base.Cursor = value;
}
}
///
/// Reserved space for line number characters.
/// If smaller than needed (e. g. line count >= 10 and this value set to 1) this value will have no impact.
/// If you want to reserve space, e. g. for line numbers >= 10 or >= 100 than you can set this value to 2 or 3 or higher.
///
[DefaultValue(1)]
[Description(
"Reserved space for line number characters. If smaller than needed (e. g. line count >= 10 and " +
"this value set to 1) this value will have no impact. If you want to reserve space, e. g. for line " +
"numbers >= 10 or >= 100, than you can set this value to 2 or 3 or higher.")]
public int ReservedCountOfLineNumberChars
{
get { return reservedCountOfLineNumberChars; }
set
{
reservedCountOfLineNumberChars = value;
NeedRecalc();
Invalidate();
}
}
///
/// Occurs when mouse is moving over text and tooltip is needed
///
[Browsable(true)]
[Description("Occurs when mouse is moving over text and tooltip is needed.")]
public event EventHandler ToolTipNeeded;
///
/// Removes all hints
///
public void ClearHints()
{
if (Hints != null)
Hints.Clear();
}
///
/// Add and shows the hint
///
/// Linked range
/// Inner control
/// Scrolls textbox to the hint
/// Inlining. If True then hint will moves apart text
/// Docking. If True then hint will fill whole line
public virtual Hint AddHint(Range range, Control innerControl, bool scrollToHint, bool inline,
bool dock)
{
var hint = new Hint(range, innerControl, inline, dock);
Hints.Add(hint);
if (scrollToHint)
hint.DoVisible();
return hint;
}
///
/// Add and shows the hint
///
/// Linked range
/// Inner control
public Hint AddHint(Range range, Control innerControl)
{
return AddHint(range, innerControl, true, true, true);
}
///
/// Add and shows simple text hint
///
/// Linked range
/// Text of simple hint
/// Scrolls textbox to the hint
/// Inlining. If True then hint will moves apart text
/// Docking. If True then hint will fill whole line
public virtual Hint AddHint(Range range, string text, bool scrollToHint, bool inline, bool dock)
{
var hint = new Hint(range, text, inline, dock);
Hints.Add(hint);
if (scrollToHint)
hint.DoVisible();
return hint;
}
///
/// Add and shows simple text hint
///
/// Linked range
/// Text of simple hint
public Hint AddHint(Range range, string text)
{
return AddHint(range, text, true, true, true);
}
///
/// Occurs when user click on the hint
///
///
public virtual void OnHintClick(Hint hint)
{
if (HintClick != null)
HintClick(this, new HintClickEventArgs(hint));
}
private void timer3_Tick(object sender, EventArgs e)
{
timer3.Stop();
OnToolTip();
}
protected virtual void OnToolTip()
{
if (ToolTip == null)
return;
if (ToolTipNeeded == null)
return;
//get place under mouse
Place place = PointToPlace(lastMouseCoord);
//check distance
Point p = PlaceToPoint(place);
if (Math.Abs(p.X - lastMouseCoord.X) > CharWidth*2 ||
Math.Abs(p.Y - lastMouseCoord.Y) > CharHeight*2)
return;
//get word under mouse
var r = new Range(this, place, place);
string hoveredWord = r.GetFragment("[a-zA-Z]").Text;
//event handler
var ea = new ToolTipNeededEventArgs(place, hoveredWord);
ToolTipNeeded(this, ea);
if (ea.ToolTipText != null)
{
//show tooltip
ToolTip.ToolTipTitle = ea.ToolTipTitle;
ToolTip.ToolTipIcon = ea.ToolTipIcon;
//ToolTip.SetToolTip(this, ea.ToolTipText);
ToolTip.Show(ea.ToolTipText, this, new Point(lastMouseCoord.X, lastMouseCoord.Y + CharHeight));
}
}
///
/// Occurs when VisibleRange is changed
///
public virtual void OnVisibleRangeChanged()
{
needRecalcFoldingLines = true;
needRiseVisibleRangeChangedDelayed = true;
ResetTimer(timer);
if (VisibleRangeChanged != null)
VisibleRangeChanged(this, new EventArgs());
}
///
/// Invalidates the entire surface of the control and causes the control to be redrawn.
/// This method is thread safe and does not require Invoke.
///
public new void Invalidate()
{
if (InvokeRequired)
BeginInvoke(new MethodInvoker(Invalidate));
else
base.Invalidate();
}
protected virtual void OnCharSizeChanged()
{
VerticalScroll.SmallChange = charHeight;
VerticalScroll.LargeChange = 10*charHeight;
HorizontalScroll.SmallChange = CharWidth;
}
///
/// HintClick event.
/// It occurs if user click on the hint.
///
[Browsable(true)]
[Description("It occurs if user click on the hint.")]
public event EventHandler HintClick;
///
/// TextChanged event.
/// It occurs after insert, delete, clear, undo and redo operations.
///
[Browsable(true)]
[Description("It occurs after insert, delete, clear, undo and redo operations.")]
public new event EventHandler TextChanged;
///
/// Fake event for correct data binding
///
[Browsable(false)]
internal event EventHandler BindingTextChanged;
///
/// Occurs when user paste text from clipboard
///
[Description("Occurs when user paste text from clipboard")]
public event EventHandler Pasting;
///
/// TextChanging event.
/// It occurs before insert, delete, clear, undo and redo operations.
///
[Browsable(true)]
[Description("It occurs before insert, delete, clear, undo and redo operations.")]
public event EventHandler TextChanging;
///
/// SelectionChanged event.
/// It occurs after changing of selection.
///
[Browsable(true)]
[Description("It occurs after changing of selection.")]
public event EventHandler SelectionChanged;
///
/// VisibleRangeChanged event.
/// It occurs after changing of visible range.
///
[Browsable(true)]
[Description("It occurs after changing of visible range.")]
public event EventHandler VisibleRangeChanged;
///
/// TextChangedDelayed event.
/// It occurs after insert, delete, clear, undo and redo operations.
/// This event occurs with a delay relative to TextChanged, and fires only once.
///
[Browsable(true)]
[Description(
"It occurs after insert, delete, clear, undo and redo operations. This event occurs with a delay relative to TextChanged, and fires only once."
)]
public event EventHandler TextChangedDelayed;
///
/// SelectionChangedDelayed event.
/// It occurs after changing of selection.
/// This event occurs with a delay relative to SelectionChanged, and fires only once.
///
[Browsable(true)]
[Description(
"It occurs after changing of selection. This event occurs with a delay relative to SelectionChanged, and fires only once."
)]
public event EventHandler SelectionChangedDelayed;
///
/// VisibleRangeChangedDelayed event.
/// It occurs after changing of visible range.
/// This event occurs with a delay relative to VisibleRangeChanged, and fires only once.
///
[Browsable(true)]
[Description(
"It occurs after changing of visible range. This event occurs with a delay relative to VisibleRangeChanged, and fires only once."
)]
public event EventHandler VisibleRangeChangedDelayed;
///
/// It occurs when user click on VisualMarker.
///
[Browsable(true)]
[Description("It occurs when user click on VisualMarker.")]
public event EventHandler VisualMarkerClick;
///
/// It occurs when visible char is enetering (alphabetic, digit, punctuation, DEL, BACKSPACE)
///
/// Set Handle to True for cancel key
[Browsable(true)]
[Description("It occurs when visible char is enetering (alphabetic, digit, punctuation, DEL, BACKSPACE).")]
public event KeyPressEventHandler KeyPressing;
///
/// It occurs when visible char is enetered (alphabetic, digit, punctuation, DEL, BACKSPACE)
///
[Browsable(true)]
[Description("It occurs when visible char is enetered (alphabetic, digit, punctuation, DEL, BACKSPACE).")]
public event KeyPressEventHandler KeyPressed;
///
/// It occurs when calculates AutoIndent for new line
///
[Browsable(true)]
[Description("It occurs when calculates AutoIndent for new line.")]
public event EventHandler AutoIndentNeeded;
///
/// It occurs when line background is painting
///
[Browsable(true)]
[Description("It occurs when line background is painting.")]
public event EventHandler PaintLine;
///
/// Occurs when line was inserted/added
///
[Browsable(true)]
[Description("Occurs when line was inserted/added.")]
public event EventHandler LineInserted;
///
/// Occurs when line was removed
///
[Browsable(true)]
[Description("Occurs when line was removed.")]
public event EventHandler LineRemoved;
///
/// Occurs when current highlighted folding area is changed.
/// Current folding area see in StartFoldingLine and EndFoldingLine.
///
///
[Browsable(true)]
[Description("Occurs when current highlighted folding area is changed.")]
public event EventHandler FoldingHighlightChanged;
///
/// Occurs when undo/redo stack is changed
///
///
[Browsable(true)]
[Description("Occurs when undo/redo stack is changed.")]
public event EventHandler UndoRedoStateChanged;
///
/// Occurs when component was zoomed
///
[Browsable(true)]
[Description("Occurs when component was zoomed.")]
public event EventHandler ZoomChanged;
///
/// Occurs when user pressed key, that specified as CustomAction
///
[Browsable(true)]
[Description("Occurs when user pressed key, that specified as CustomAction.")]
public event EventHandler CustomAction;
///
/// Occurs when scroolbars are updated
///
[Browsable(true)]
[Description("Occurs when scroolbars are updated.")]
public event EventHandler ScrollbarsUpdated;
///
/// Occurs when custom wordwrap is needed
///
[Browsable(true)]
[Description("Occurs when custom wordwrap is needed.")]
public event EventHandler WordWrapNeeded;
///
/// Returns list of styles of given place
///
public List