# Assigning style to text

**URL:** https://forum.alternetsoft.com/t/assigning-style-to-text/510
**Category:** AlterNET Studio Support
**Created:** [August 27, 2025, 10:26pm UTC](https://forum.alternetsoft.com/t/assigning-style-to-text/510 "2025-08-27T22:26:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sirokai](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/s/606060/32.png) [@Sirokai](https://forum.alternetsoft.com/u/Sirokai)
#### Post date: [August 27, 2025, 10:26pm UTC](https://forum.alternetsoft.com/t/assigning-style-to-text/510/1 "2025-08-27T22:26:36Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [August 28, 2025, 6:19am UTC](https://forum.alternetsoft.com/t/assigning-style-to-text/510/2 "2025-08-28T06:19:28Z")

</div>

We have an example of custom line styles usage in this demo:  
`AlternetStudio\Demo\Editor\QuickStarts\LineStyles\ `

Here is the snippet:

```cs
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);

```

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [August 28, 2025, 6:44am UTC](https://forum.alternetsoft.com/t/assigning-style-to-text/510/3 "2025-08-28T06:44:29Z")

</div>

There are also LineStyles.SetLineStyle methods which supports line index and IRange:

```cs
/// <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:

```cs
                Source.LineStyles.SetLineStyle(
                    new Alternet.Common.Range(
                        executionPos.StartColumn - 1,
                        executionPos.StartLine - 1,
                        executionPos.EndColumn,
                        executionPos.EndLine - 1),
                    1,
                    traceLineStyleIndex);

``
```
