Mimicing Tcl/Tk's Font "OnMouseEnter" behavior in a C# application - c#

I was looking at a program my friend sent me that was written in Tcl/Tk. It has a rich-formatting multi-line text box with different colors and fonts, and for certain blocks of text the application window reacts to users hovering over different text elements. He says this is implemented by specifying a "OnMouseEnter" callback event when creating a new font. This seems like a cool and elegant approach, and I wanted to do something similar in a C# app I wrote. At the moment the three ways I can think to do this are: (a) work out the mapping from X-Y mouse coords to text (maybe there is an easy function for this?) (b) make each distinct text block a child control with its own callback functions (which is very ugly and would require me to do my own text wrapping) or (c) make it a webpage control and have javascript "call" C# via WebBrowser.Navigating. Any suggestions as to the best way to implement this kind of functionality would be welcome.

Most textbox control have X-Y coord to text block translation function calls. You can hook the entire mouse move event for the textbox and see what's beneath the mouse.
This might be ugly code but at least it would work.

Related

C# WinForms 4-sate checkbox

Using VS2013, C#.NET 4.5, and WinForms. Migrating to WPF is not an option at this point.
The standard checkbox control handles 2-state and 3-state modes, but I need a 4-state checkbox. I can't find a 4-state checkbox library on the net anywhere, so I'm assuming I'll have to make one (if y'all know of one, that'd be great).
I have a set of four PNGs as draft images of the checkbox appearance, and I have played around with just painting those on a button and having the button_click event cycle through which image is displayed and update the data value. This doesn't seem to scale the image with the button well, though, and it feels kludgy to load static bitmaps instead of vector drawing the images so they're always to scale.
Is there a way to inherit from the checkbox control itself and add a fourth state?
If so, where do I go to override how the states are drawn? I need to do it "correctly" so that if the form is Scaled, the checkbox doesn't end up looking all bitmap-nasty.
I'm not even sure what keywords to use to search for how to do the actual drawing.
Background:
I'd generally consider this to be a nasty UI choice, but I'm making a program that saves, loads, and displays a "World of Darkness" character sheet of any arbitrary system, and the WoD games use a 4-state injury that's represented on the sheet by an empty box, a box with one slash across it, a box with an X across it, or a box with a 4-stroke asterix across it (optionally, a filled box).
For the moment I'm going with matching the original with high fidelity; later, as an option, I'll let the user switch to radio buttons to support my own preference.
This is my first real exploration of GUI programming beyond the basics, so I'm not sure quite how to proceed.
EDIT: I'm delving into a UserControl now, and my own draw methods. What fun. Found an MSDN tutorial on User-Drawn Controls, seems like a good starting place.

How to accept text input in UserControl / ScrollableControl?

I've created a canvas like control that draws images, shapes and text. Right now text can be added to the drawing surface only programmatically. But I would like to implement a more WYSIWYG-like text input method. So the basic idea is to capture keystrokes inside my ScrollableControl implementation.
This seems to be a trivial task - just override OnKeyDown method, right? Not quite :( This basically means that I'd have to manually handle all possible key combinations with SHIFT or ALT (for non-english alphabets).
So the question is: is there an easy way to do it? Note that not only text input is required, but also backspace, enter, cursor movement and all that stuff. I feel I'm missing something and manual input handling through OnKeyDown is not exactly the best solution.
Depending on how you want the text input to work, you can probably do it by adding a borderless textbox to your control and focusing it when the user starts typing.

Inject/simulate WPF routed mouse click events

I have some straight WPF 3.5 controls handling left mouse clicks that I need to use within a Surface app (SDK 1.0). The problem I am facing is that do not work by default. I am thinking of wrapping each control in a SurfaceContentControl and translating ContactTouchDown or ContactTapGesture events to corresponding MouseDown events.
The problem boils down to - how to "inject" or simulate arbitrary routed mouse events? I have tried InputManager.Current.ProcessInput() but didn't get very far. Any help is appreciated.
Try to use AutomationPeer classes. For example ButtonAutomationPeer is for Button. The code below initiates a click.
ButtonAutomationPeer peer = new ButtonAutomationPeer(button);
IInvokeProvider provider = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);
provider.Invoke();
evpo's idea is an interesting one (though if you're working with custom controls, they rarely come with AutomationPeer classes).
You can't simply 'inject' mouse input by sending WM_MOUSE* events to your app... WPF would indeed process the message but when it goes to figure out the position of mouse for that event, it will query the actual mouse API instead of trying what you stick in the WM.
So really all you can do is tell windows to move the actual mouse cursor and act as though the button is being clicked/released. Some code you can use for that is in http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx
That said, while you can technically do this, it sucks... you've got an expensive multitouch device but are 1) showing a mouse cursor on it 2) limiting arbitrary parts of it to being used 'single touch' (and only one of those arbitrary parts at a time and 3) coming up with an arbitrary method of determining which finger you will treat as the mouse-controlling one

How can I wrap text from one text control to another?

I'm attempting to create a program in C# that would allow dynamic wrapping across rich text box controls. For example, I begin typing in one available control, as soon as a horizontal scrollbar would appear and the rich text box wraps to the next line, it would instead create a new rich text box control underneath and place my cursor there. This method would also need to support moving text back and forth between controls in the case of deleting/changing existing text.
Why you ask? My church requires a program that will allow easily pasting text and it automatically going across as many slides as needed which supports different fonts, sizes, weights, colors, and undo and redo. All this would need to be done on the fly so the user does not need to use some sort of preview mode to go back and forth to accomplish what they're trying to do.
I assume this is for something like order of service, or words to hymns? The solution for that is to use the scrollbar or the PgDn button. In a Web Browser.
I agree with Chris Ballard. Really, this doesn't look like the right way to solve your problem.

RichTextBox control, making non-URLs hyperlinks?

In a richtextbox I see there's DetectURLs and an event to go along with that...
Is there a way to set up a word or series of words to act as a hyperlink even though they are not a hyperlink? My specific use is that I'm writing a ticker program that will scroll information across the bottom of the screen, I would like for some information to be clickable without putting the long, messy URL of the target. Anyway I can do this?
Links with arbitrary text in a RichTextBox
http://www.codeproject.com/Articles/9196/Links-with-arbitrary-text-in-a-RichTextBox

Categories

Resources