Currently when hovering over a url/link in a RichTextBox (WinForms) the cursor changes to a really low quality cursor without anti aliasing. I would like to use the default windows one, which looks way better, but I couldn't find any solutions... I only found a way to change the general hover cursor, but not when hovering over urls.
Thanks for all replies :)
This seems like a bug between RichTextBox and HiDPI support. The control properly renders text in HiDPI when HiDPI mode is enabled in the WinForms application, but it doesn't have the updated cursor.
Depending on the use case, you might consider using the WebBrowser control or something similar. It appears to support the higher resolution pointer cursor. It would work pretty well for viewing content, but for editing content, it might get a bit rough.
As a gross, hacky workaround, you might be able to add MouseMove event handlers to detect if the mouse is over a hyperlink or not and change the cursor for the whole control manually. This would involve the GetCharIndexFromPosition(Point) method passing in the Point from the MouseMove event args, then looking at the RTF Codes in the string from the Rtf property. If the CharIndex is the non-RTF string, you'd need to use the Text property, then determine if there's a URL there using some sort of Regex.
Related
I need the property called SelectionColor in the TextBox class, for a simple Syntax Highlighter - I can't use directly a RichTextBox - it causes too many problems, that's why I try to do this.
Is there any way to make that property available for a TextBox?
If it isn't possible, I'd try to write my own, but I need an idea on how to do it, basically how it works - is it based on drawing strings over the original text?
Thanks in advance.
Basically, using a TextBox for anything but plain text is a bad idea. First of all, you will eventually get a new feature to implement which is not present in TextBox and you will have to handle it manually. After some time you will implement a custom RichTextBox or something similar.
Second, it is relatively hard to even solve the problem you mentioned. Technically, you can override painting function (which you have to do if you want new functionality for TextBox). You can then let TextBox paint itself and paint the colored text above the image. But don't do it. You will get two (maybe more) problems:
Flicker of image. Once the original textbox has drawn itself, the image can be shown on screen (if you don't use double buffering).
Text alignment. It is hard to place colored text exactly above black text, plus you can run into problems with text rendering: you will need to clear area you're drawing in.
My code to display tooltip on mousehover is as follows
e.Node.ToolTipText = Convert.ToString(sb);
But this is displaying with the default color yellow. Can i change this to some other color. I did not find any property for that . If possible can any one give me an idea...
Thanks & Regards,
M.Dorababu.
The background color for a tool tip is a system color setting, you cannot reasonably change that setting. You can alter the appearance yourself by setting the ToolTip.DrawMode property. A good example of the Draw event handler you'll need is in the MSDN library topic for that event.
The next obstacle is definitely the harder one. The tooltip control that displays tips for nodes is built into the native Windows control, you cannot replace it. You'll have to give up on the TreeNode.ToolTipText property and store it elsewhere. Like the Tag property, or generate it on-the-fly.
Then you need to wire into the TreeView's MouseMove event and use its HitTest() method to find out where the mouse is located. Toggle a Timer's Enabled property when the mouse is moved. Use the Tick event to call the ToolTip.Show() method. And wire MouseLeave to turn everything off.
Quite possible, falls in the "when there's a will, there's a way" category.
There is no standard property for that. And for good reason: The colour of the tooltip is none of your business, it’s up to the user. If you really want to work against established practices and reduce the quality of your software for no reason other than to be different, then you’ll have to create your own tooltip component. Otherwise, you should stick with the default.
I'm new to WPF so I've got a problem:
I need to create a grid. This grid should contain a column with a kind of thumbnails.
When I move mouse over a thumbnail, there should appear a panel with a big image. This panel will cover all grid.
But this will make thumbnail think that mouse already has gone.
After mouse's gone, panel should dissappear. Mouse appears above thumb again, and panel appears. And again, and again. I don't know how to handle this.
Could anybody suggest any solution?
Sounds to me like you want to use IsHitTestVisible="False" on the image that pops up. This will make it ignore the popup when testing where the mouse is, so it will think your mouse is still over the thumbnail image. This should work on any UI element, except windows.
Use MouseEnter and MouseLeave:
http://www.hanselman.com/blog/MouseEnterAndMouseLeaveLoopsInWPF.aspx
There are two ways I can think of to do this, depending on what kind of functionality you're looking for.
If you want the larger image to appear in proximity to the mouse and the thumbnail, then you might want to take a look at using a Tooltip.
Otherwise as Aliostad mentioned above, you could use the MouseEnter and MouseLeave events to trigger the display of whatever content is needed.
I have a MSHTML-based control embedded in an application and the ContentEditable mode is used to edit documents inside it. The body of the HTML document initially contains the following lines:
<div></div>
<div id="signature"></div>
The caret is placed at the beginning of the document, that is inside the first DIV element. Now when user clicks with mouse inside the control in a place below the last line, the caret is moved into the second DIV element, as it's the closest one to the point where the user clicked.
I want to move the pointer to the end of the first DIV on the mouse click. Now I have the code to calculate the intended position of the caret as IMarkupPointer and IDisplayPointer. What I need to know is where to intercept the MSHTML event pipeline to do the actual caret move.
I've written code that implements IHTMLEditDesigner and moves the caret using IHTMLCaret.MoveCaretToPointer to the intended position. The problem is that no matter where I intercept the event (PreHandleEvent, PostHandleEvent or PostEditorEventNotify) the caret position is eventually reverted to the default one on single click (but it is not reverted if I hold the left mouse button pressed for a while or if I click with right mouse button).
Use jscript inside of the HTML that you load into the IE control. If you do not know HTML and jscript very well you will find this task very painful.
See these questions for my experience when I tried do so something like this.
Risk of using contentEditable in
IE
Why is ContentEditable
removing “ID” from div
I also had lots of other problem, including have to write resize logic in jscript to get the HTML editor to size along with the WinForm form and having to pass the default form/coontrol colours into the HTML editor so that it looked write then users changed colour schemes on Windows.
Even better just find a HTML editor and load it into the IE control, you will still have to code with standard window colours etc yourself.
There are also 3rd party winforms HTML editors you can use. If possible I think you should buy in a solution as ContentEditable is a lot harder in real life then it look.
A quick google found.
Writer by Lutz Roeder (of Reflector fame)
NetRix by netrixcomponent
Html Editor by Carl Nolan
HTML viewing and editing component for WinForms apps
Have you tried using a winforms timer with a timeout of 0?
When you get the mouse down event start the timer.
Then the MSHTML control will process the event
You will then go back to the windows message loop
All other messages in the message queue will then be process before the timer
Hopefully by now MSHTML has set the default caret position on single click
You can then move the caret position yourself when the timer fires
Have a look with Spy++ to see what events are being sent between the diffent windows in the MSHTML control to get other ideals. The MSHTML control is like no other winforms control and you have to go back to all the trick you used in the days of C and Win32 programming.
Maybe there are separate events for mouseDown mouseUp and mouseClick.
You intercept mouseClick but default behavior gets executed on mouseUp.
Have you tied setting the "focus" to the first div by finding the dom item for it, and calling the setFocus (or whatever it is called) dom method? The caret should move to where the fosus is.
(There are interfaces that MSHTML expose to find dom items and call methods on them. Sorry I don't recall the details of how to do this)
I believe you need to change the SelectStart property and leave the SelectionLength = 0. That will move the caret to a new position.
I don't like the default ToolTip behavior. First, I don't like that, after tooltip is shown for "AutoPopDelay" miliseconds, it disappears and don't appear anymore if you move the mouse over the control again. Second, I don't like that AutoPopDelay is limited to 5000 miliseconds.
I found one way to make tooltip always reappear on mouse move over control, even if it was shown for a time exceeding AutoPopDelay value: I call toolTip.Hide() in MouseLeave handler. This way tooltip will appear again on mouse over.
But I haven't found a simple way to make tooltip stay shown for longer time (longer than maximum 5000 miliseconds). If I call toolTip.Show() in MouseEnter handler, then toolTip is shown in not good position. I like the position in which it shows automatically :)
So, what can you suggest?
Use the Show method to control the length of time (it is not limited to 5000ms).
There is a signature for Show that does not require that you set the relative coordinates and there is one that will take the coordinates if you want to fine-tune things. In your case you will need to pass coordinates (if you don't like what it automatically gives you). I do not believe there to be an alternative...