本文整理汇总了C#中FastColoredTextBox.OnPaintLine方法的典型用法代码示例。如果您正苦于以下问题:C# FastColoredTextBox.OnPaintLine方法的具体用法?C# FastColoredTextBox.OnPaintLine怎么用?C# FastColoredTextBox.OnPaintLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FastColoredTextBox
的用法示例。
在下文中一共展示了FastColoredTextBox.OnPaintLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawLines
// returns the iLine of the last line we drew
internal static int DrawLines(PaintEventArgs e, FastColoredTextBox textbox, Pen servicePen)
{
Graphics graphics = e.Graphics;
Brush changedLineBrush = new SolidBrush(textbox.ChangedLineColor);
Brush currentLineBrush = new SolidBrush(Color.FromArgb(textbox.CurrentLineColor.A == 255 ? 50 : textbox.CurrentLineColor.A, textbox.CurrentLineColor));
//create dictionary of bookmarks
var bookmarksByLineIndex = new Dictionary<int, Bookmark>();
foreach (Bookmark item in textbox.Bookmarks)
{
bookmarksByLineIndex[item.LineIndex] = item;
}
int firstChar = (Math.Max(0, textbox.HorizontalScroll.Value - textbox.Paddings.Left)) / textbox.CharWidth; // when drawing a line start at this character
int lastChar = (textbox.HorizontalScroll.Value + textbox.ClientSize.Width) / textbox.CharWidth; // when drawing a line draw until this character
// x-coordinate of where we can start drawing
var x = textbox.LeftIndent + textbox.Paddings.Left - textbox.HorizontalScroll.Value;
if (x < textbox.LeftIndent)
firstChar++;
// y-coordinate to line index
int startLine = textbox.YtoLineIndex(textbox.VerticalScroll.Value);
int iLine; // remember the last iLine we drew
for (iLine = startLine; iLine < textbox.lines.Count; iLine++)
{
Line line = textbox.lines[iLine];
LineInfo lineInfo = textbox.LineInfos[iLine];
//
if (lineInfo.startY > textbox.VerticalScroll.Value + textbox.ClientSize.Height)
break; // out of the drawing range
if (lineInfo.startY + lineInfo.WordWrapStringsCount * textbox.CharHeight < textbox.VerticalScroll.Value)
continue; // skip
if (lineInfo.VisibleState == VisibleState.Hidden)
continue; // skip
int y = lineInfo.startY - textbox.VerticalScroll.Value;
//
graphics.SmoothingMode = SmoothingMode.None;
//draw line background
if (lineInfo.VisibleState == VisibleState.Visible)
{
if (line.BackgroundBrush != null)
{
var rect = new Rectangle(textbox.TextAreaRect.Left, y, textbox.TextAreaRect.Width,
textbox.CharHeight*lineInfo.WordWrapStringsCount);
graphics.FillRectangle(line.BackgroundBrush, rect);
}
}
//draw current line background
if (textbox.CurrentLineColor != Color.Transparent && iLine == textbox.Selection.Start.iLine)
{
if (textbox.Selection.IsEmpty)
{
graphics.FillRectangle(currentLineBrush,
new Rectangle(textbox.TextAreaRect.Left, y, textbox.TextAreaRect.Width,
textbox.CharHeight));
}
}
//draw changed line marker
if (textbox.ChangedLineColor != Color.Transparent && line.IsChanged)
{
graphics.FillRectangle(changedLineBrush,
new RectangleF(-10, y,
textbox.LeftIndent - FastColoredTextBox.MIN_LEFT_INDENT - 2 + 10,
textbox.CharHeight + 1));
}
//
graphics.SmoothingMode = SmoothingMode.AntiAlias;
//
//draw bookmark
if (bookmarksByLineIndex.ContainsKey(iLine))
{
bookmarksByLineIndex[iLine].Paint(graphics,
new Rectangle(textbox.LeftIndent, y, textbox.Width,
textbox.CharHeight*
lineInfo.WordWrapStringsCount));
}
//OnPaintLine event
if (lineInfo.VisibleState == VisibleState.Visible)
{
textbox.OnPaintLine(new PaintLineEventArgs(iLine,
new Rectangle(textbox.LeftIndent, y, textbox.Width,
textbox.CharHeight * lineInfo.WordWrapStringsCount),
e.Graphics, e.ClipRectangle));
}
//draw line number
if (textbox.ShowLineNumbers)
{
using (var lineNumberBrush = new SolidBrush(textbox.LineNumberColor))
{
graphics.DrawString((iLine + textbox.lineNumberStartValue).ToString(), textbox.Font, lineNumberBrush,
new RectangleF(-10, y, textbox.LeftIndent - FastColoredTextBox.MIN_LEFT_INDENT - 2 + 10, textbox.CharHeight),
new StringFormat(StringFormatFlags.DirectionRightToLeft));
}
}
//.........这里部分代码省略.........