Hi I thought this would be an easy one, but I’m stumped. If I know the position of certain text, how do I manually set the style to that range?
We have an example of custom line styles usage in this demo:
AlternetStudio\Demo\Editor\QuickStarts\LineStyles\
Here is the snippet:
var customImageIndex = syntaxEdit1.Gutter.AddImage(
this.GetType().Assembly,
"LineStyles.Resources.gear16green.png",
"LineStyles.Resources.gear32green.png");
IEditLineStyle traceLineStyle = new EditLineStyle
{
BackColor = Color.Black,
ForeColor = Color.FromArgb(255, 241, 129),
Options = LineStyleOptions.BeyondEol | LineStyleOptions.InvertColors,
ImageIndex = customImageIndex,
};
edit.LineStyles.Add(traceLineStyle);
int traceLineStyleIndex = edit.LineStyles.Count - 1;
edit.Source.LineStyles.ToggleLineStyle(edit.Position.Y, 1, traceLineStyleIndex);
There are also LineStyles.SetLineStyle methods which supports line index and IRange:
/// <summary>
/// Sets given line style to the specified line.
/// </summary>
/// <param name="line">Index of the text line.</param>
/// <param name="priority">Priority of the line style. This parameter is useful only for line styles having image indexes.</param>
/// <param name="style">Index of the line style.</param>
void SetLineStyle(int line, int priority, int style)
/// <summary>
/// Sets given line style to the specified line.
/// </summary>
/// <param name="range">Range where line style is defined.</param>
/// <param name="priority">Priority of the line style. This parameter is useful only for line styles having image indexes.</param>
/// <param name="style">Index of the line style.</param>
void SetLineStyle(IRange range, int priority, int style)
Usage example:
Source.LineStyles.SetLineStyle(
new Alternet.Common.Range(
executionPos.StartColumn - 1,
executionPos.StartLine - 1,
executionPos.EndColumn,
executionPos.EndLine - 1),
1,
traceLineStyleIndex);
``