Hi,
I would like to change the highlight color that is used to mark found strings in the text editor because the readability is not always good:
Is this possible at all?
Best Regards
Karol
Hi,
I would like to change the highlight color that is used to mark found strings in the text editor because the readability is not always good:
Is this possible at all?
Best Regards
Karol
We released Alternet.Studio 10.0.2 and added the SearchResultsHighlightForeground
property to visual themes. This allows you to specify the foreground color for search highlights.
Also there is âSearchResultsHighlightBackgroundâ property. This allows you to specify the background color for search highlights.
For accessing theme properties, you can use
LightVisualTheme.Instance
, DarkVisualTheme.Instance
or VisualStudioCodeTheme.Instance
properties.
And the colors of the selected text are used to show the found text after you press Search button
Thanks,
but we are using 9.5.
Best Regards
in v9.5 everything is the same except that SearchResultsHighlightForeground
is absent
Oh, sorry. I misinterpreted your first answer.
But still no success here. What am I doing wrong here?
sntxEdit.VisualThemeType = VisualThemeType.Custom;
var dvt = new DarkVisualTheme();
dvt.Colors.SearchResultsHighlightBackground = Color.Pink;
sntxEdit.VisualTheme = dvt;
Best Regards
Here is an example:
static Form1()
{
var c = DarkVisualTheme.Instance.Colors;
c.SearchResultsHighlightBackground = Color.Pink;
c.SearchResultsHighlightForeground = Color.Green;
InvokeProtectedMethod(DarkVisualTheme.Instance, "InitializeStyles");
}
public static object? InvokeProtectedMethod(object target, string methodName, params object[] args)
{
if (target == null)
throw new ArgumentNullException(nameof(target));
if (string.IsNullOrWhiteSpace(methodName))
throw new ArgumentException("Method name cannot be null or empty.", nameof(methodName));
var type = target.GetType();
var argTypes = Array.ConvertAll(args, a => a?.GetType() ?? typeof(object));
MethodInfo? method = null;
var flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy
| BindingFlags.Public | BindingFlags.Static;
// Walk up the inheritance chain to find the method
while (type != null)
{
method = type.GetMethod(
methodName,
flags,
binder: null,
types: argTypes,
modifiers: null);
if (method != null)
break;
type = type.BaseType;
}
if (method == null)
throw new MissingMethodException($"Method '{methodName}' not found in type hierarchy.");
return method.Invoke(target, args);
}
In the new version we do have StandardVisualTheme.ResetStyles()
which can be used instead of InvokeProtectedMethod
call.
Alternative way to set colors for some style:
var style = DarkVisualTheme.Instance.LexStyles
.FindLexStyle(StringConsts.SearchResultInternalName);
if (style != null)
{
style.BackColor = Color.Red;
style.ForeColor = Color.Yellow;
}
Also we have VisualTheme sample where custom theme is demonstrated. Basically you can do like there. Custom theme declaration:
public class CustomVisualTheme : StandardVisualTheme
{
public CustomVisualTheme()
: base("MyCustomTheme")
{
}
protected override VisualThemeColors GetColors()
{
var colors = DarkVisualTheme.Instance.Colors.Clone();
colors.Reswords = System.Drawing.Color.Red;
colors.WindowBackground = System.Drawing.Color.FromArgb(40, 40, 40);
return colors;
}
}
Custom theme assignment:
syntaxEdit1.VisualTheme = new CustomVisualTheme();
syntaxEdit1.VisualThemeType = VisualThemeType.Custom;
Thank you very much!
I tried the first two solutions and both worked.
I decided for the lean, second one.