I am making a pascal code editor in Mono in MonoDevelop. I am using Mono.TextEditor as a code editor widget. However, I cannot find how to highlight a line in the widget.
After compilation, I collect line numbers where errors occur, and so I want to highlight them in red. I found
Mono.TextEditor.LineBackgroundMarker
which seems to relate to what I want to do, but I cannot find where and how to use it.
Another option I was looking into was ViBuilder, but I don't even know how to use that. I can think of two ways to solve this problem:
Simply make highlight
Mark a line as error, as default style includes:
{ "name": "Underline(Error)", "color":"invalid-red" }
which also seems to be a possible solution.
You can highlight lines in the text editor by adding markers to the underlying document. Use the TextDocument.AddMarker method, as follows:
TextEditor textEditor;
var marker = new Mono.TextEditor.LineBackgroundMarker();
int lineNumber = ...;
textEditor.Document.AddMarker(lineNumber, marker);
textEditor.QueueDraw();
Also have a look at the Mono.TextEditor.StyleTextMarker class. This class has already the properties "BackgroundColor" / "Color" that you are looking for. Underlining may have to be done manually (for example by inheriting from StyleTextMarker and overriding the Draw method).
Related
Without posting pages of C# code and markup, has anyone got a reason why this code
var link = _driver.FindElement(By.Id(field + "Field"));
var id = link.GetAttribute("id");
var text = link.Text;
given this markup
<a id="ForenameField" href="/MyUrl/MyFolder/MyId">3 errors</a>
Assigns an empty string to the text variable, but if I put a breakpoint on the second or third line and inspect the link variable, I can see the inner text of the element against the Text property on the inspector, it reads "3 errors", but the value of text is an empty string. It is not hidden, I can see the text if I add a watch or use quickview, any ideas?
Ok, it's my bad. Using jquery to toggle class on the div that contains the html in the question, meant that although users see the div appearing, the class that hides the div is still in the tag. A bit like this
<div class="hideThis showThis"><!-- my elements /--></div>
This makes it so that Selenium is right not give me a text value. It is strange however that the Visual studio debugger thinks that there should be a value. Visual Studio seems to go with what I can see, but Selenium is more pedantic about the hideThis class being there.
I go with the idea that if you can't see it you can't interact with it, so it is worth looking up the html graph from the element you expect to have a value to see if any class is present which would hide your element.
Feel free to recommend that I delete this rather obvious wisdom.
I know this was posted over a year ago, but I had this exact problem too and came across this thread. I was able to solve it by just waiting for the DOM to load--some elements aren't visible until the DOM is updated. So just putting Thread.Sleep(6000) or whatever after navigating to the page got it to work for me.
I have Rich TextBox to Edit XML Text
What i want how to color the XML Tags Names inside the RichTextBox
I want the tags names in RED or Green color.
Any Way to do that?
Work out what your desired regex is using this page. Once you have this you could use something like the following method to update the RichTextBox
public static void HighlightSyntax(RichTextBox richTextBox, Regex yourRegex, Color someColor)
{
richTextBox.BeginUpdate();
int selPos = richTextBox.SelectionStart;
richTextBox.SelectAll();
richTextBox.SelectionColor = normTextColor;
richTextBox.Select(selPos, 0);
// For each match from the regex, highlight the word.
foreach (Match keyWordMatch in yourRegex.Matches(richTextBox.Text))
{
richTextBox.Select(keyWordMatch.Index, keyWordMatch.Length);
richTextBox.SelectionColor = someColor;
richTextBox.Select(selPos, 0);
richTextBox.SelectionColor = normTextColor;
}
richTextBox.EndUpdate();
}
You could also adopt a timer to update this automatically after a set time.
I hope this helps.
Note. For large text files, and approach like this will be slow! In this case I would adopt Sinctilla.NET as a full syntax highlighter as stated in one of the answers below...
there are articles which explain or suggest possible approaches to syntax colouring, for example: How To Implement Syntax Highlighting In A WinForms Application
I think the best and easiest way is to use Scintilla.NET to handle that so you can focus on what really matters to you instead of reinventing the wheel again :)
MSDN created a simple C# function that formats the text content from a RichTextBox:
LINK
Using a simple regex find the location (start and end) of each tag and colorize it like below:
richtextbox1.Select(start, end-start);
richtextbox1.SelectionColor = Color.Green;
richtextbox1.Select(start, 0);
Check out scintilla, a nice source code editing component for Windows which supports Syntax Highlighting too. And there's a .NET wrapper for it called ScintillaNET.
I think for small syntax highlighting projects, roll your own! There are some examples of highlighting in a syntax editor already posted.
https://stackoverflow.com/a/13007641/1033686
https://stackoverflow.com/a/13007710/1033686
For larger projects that demand better highlighting, use Scintilla.NET (but be warned, it it a bit heavy and can be tricky to get working!)
http://scintillanet.codeplex.com/
For enterprise projects use a commercial product like actipro syntax editor.
http://www.actiprosoftware.com/products/controls/windowsforms/syntaxeditor?gclid=CI6rrqmglLMCFSfMtAodbE8AhA
I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (in C#): add a small CheckBox to ask if the user wants to use the first or second set of tools.But I'm still not able to change the icons on the ApplicationBar. I tried removing the old ones, first with ApplicationBar.MenuItems.Remove(Button1); and then with ApplicationBar.Buttons.Remove(Button1);
but neither worked. I tried changing the .IconUri property of the button, but that gave me a NullReferenceException.
I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:
firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
firstAppBarButton.Text = "New Text";
firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.
You can't refer to the application buttons by name. Try:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?
The syntax above gave me a compile error. With some additional research, I got this to work for me:
ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);
I am doing a website using asp.net C# and I would like to popup a small window with information as soon as mouse hover a particular word. I know that I have to use jquery but I don't know exactly how to do it.
Any suggestions please?
There are many plugins out there that will help you achieve what you are looking for. However it is also very possible to implement this functionality yourself. I wouldn't be surprised either if some of the plugins you come across also use similar code.
The following is my attempt to demystify tooltip/popup plugin behaviour.
You could wrap the desired word in a <span> element and give it a .hover class.
<div>
This is some text with a <span class="hover">special</span>
word that has hovercraft capabilities.
</div>
Your jQuery (ver 1.7+) would look something like this :
$(".hover").on('mouseenter',function(){
// The popup must be shown here (mouse is over element).
}).on('mouseleave',function(){
// The popup must be hidden here (mouse has left element).
});
I should add here that I am using a great and yet sometimes forgotten capability of jQuery called "chaining". The on() function actually returns the object that it was attached to. In this case $(".hover") - so if I want to call another function on that object I can just add it as another function at the end. Another example of this would be :
$("#myElement").text("An error has occured!").css("color","#FF0000");
That line of code would also at the text to #myElement and also turn the colour red.
With regard to your actual popup - I would suggest two things :
Have an element at the bottom of your markup (written last so highest index - or manually set the highest z-index)
You could also have the popup in a hidden element right next to the element that is supposed to trigger the popup.
What you're after sounds like a 'tool tip'.
The solutions using jQuery are somewhat involved - so I'll just direct you to external resources.
Possible solutions:
ToolTip Plugin for jQuery
Build a Better Tooltip with jQuery Awesomeness
I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (in C#): add a small CheckBox to ask if the user wants to use the first or second set of tools.But I'm still not able to change the icons on the ApplicationBar. I tried removing the old ones, first with ApplicationBar.MenuItems.Remove(Button1); and then with ApplicationBar.Buttons.Remove(Button1);
but neither worked. I tried changing the .IconUri property of the button, but that gave me a NullReferenceException.
I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:
firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
firstAppBarButton.Text = "New Text";
firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.
You can't refer to the application buttons by name. Try:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?
The syntax above gave me a compile error. With some additional research, I got this to work for me:
ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);