Anyone knows how to code a Color Syntax?
So i have this empty function that runs 24/7 since it started can anyone make a script that highlights every word that contains "pause" and "test" to the rgb color 0,0,255? im trying to make a code editor
Im using WinForm (i know my mistake but i cant reverse it)
.Net framework 4.7.2
Function:
private void ColorizeText()
{
}
8 Replies
ok but... what is the object that contains the text, a rich text box?
yes its a richtextbox
its called "ScriptingPane"
private void ColorizeText()
{
ScriptingPane.Text = "idk"; //Yes its a Richtextbox
}
WinForms, WPF or something else?
winforms
That displays RTF-formatted text. Use RTF to color the text as you wish. See for example http://www.pindari.com/rtf1.html, or any other google result for e.g. "rtf text color"
ok
but i need it as a c# script because it needs to constantly update
im trying to make a code editor but its hard to code the color syntax
Surely you only need to reformat the text when it changes?
ok
I also haave this old script where i tryed to script a color scheme but it failed badly:
private Color GetTokenColor(string token)
{
if (token.TrimStart().StartsWith(":"))
return Color.Red; // Color for labels
if (IsCommand(token, "echo", "pause", "time", "ping", "cls"))
return Color.FromArgb(0, 183, 255); // Command color
if (IsCommand(token, "cd", "dir", "rename", "ren", "replace", "xcopy", "del", "move", "rmdir"))
return Color.FromArgb(13, 112, 0); // File system command color
if (IsBracket(token))
return Color.FromArgb(30, 255, 0); // Bracket color
if (IsCommand(token, "powershell", "dxdiag", "chkdsk", "diskpart", "mrt", "explorer", "eventvwr", "taskschd", "taskmgr", "mmc", "bcdedit"))
return Color.FromArgb(68, 0, 255); // Special command color
if (IsCommand(token, "call", "goto", "errorlevel", "com1", "com2", "com3", "com4", "com", "ipconfig", "cacls", "icacls"))
return Color.FromArgb(0, 17, 255); // Another command color
return ScriptingPane.ForeColor; // Default color
}
private bool IsBracket(string token) =>
token.Contains("(") token.Contains(")") token.Contains("[") token.Contains("]") token.Contains("{") || token.Contains("}");
private bool IsCommand(string token, params string[] commands)
{
foreach (var command in commands)
{
if (token.Equals(command, StringComparison.OrdinalIgnoreCase))
return true;
}
return false;
}
}
}