C# WinForms 4-sate checkbox - c#

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.

Related

WPF Scrollable Timeline Control

I'm trying to build a timeline-like control for a project, but I have limited experience with WPF, and don't really know where to start. The requirements are fairly simple: I have an ObservableCollection of objects that have a timestamp property, and I need to be able to select one or more of them and drag them back and forth on a "timeline". All of the objects will be rendered the same size since there's no concept of a start/end time. Here is a mockup of what I'm trying to build:
I've spent hours searching for examples or tutorials, but when I search for "timeline" controls most of the results address a completely different problem:
Rather than going with the classic override of the Thumb control, I threw together a quick framework based off your mockup:
ZIP: http://www.mediafire.com/file/fidg8ea88ofoki4/TimelineFramework.zip
VirusTotal: https://www.virustotal.com/en/url/7579b365749d07eb743643ab118de71c7dd09cb03df7a8b28fbf3cec816ff4cc/analysis/1484802709/ and https://www.virustotal.com/en/file/4899aa96234e1e69c4e935f7d692e46789d8b4b7a5afd4c354937ed921986b20/analysis/1484802463/
It's pretty basic in terms of WPF as it's mostly C# with little XAML, so you can probably figure it out real fast and then be on your way to adapting it for your specific needs.
In the demo app, it looks like this:
The blue bands are draggable, with the thick center line representing their true placement and the faded side blue making for a bigger grip to click on. Hovering over a band shows its placement in the Tooltip. Of course, you can restyle and adjust all the visuals to your needs.

Custom Text Box Component / Element (Not a Control)

I am in need of a class that mimics a TextBox control but is not a Control, but instead a custom drawn component or element.
Creating one feels like re-inventing the wheel since I see them everywhere. For example, in any modern web browser the text boxes are not controls. Most Winforms controls, especially ToolStrip controls such as ToolStripTextBox, have elements which behave like text boxes (but are not Controls).
I assume that Microsoft doesn't reinvent the wheel for each control they make it. But most likely their code is proprietary and not public.
Does any one know of an open source solution for this? I am experienced with GDI+ drawing but a text field is not a trivial task when you consider caret positioning, selection, and inserting text.
Any pointers on how to go about writing the code myself would be appreciated, such as how to calculate the character at a given point. Should I create a lookup table for the measured width of each possible character? Or loop through MeasureString to take into account formatting space?
You may find the code you need inside this article/project. http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
Why must it not be a Control? If you're using Windows Forms, it is far more likely that you really want a control.
Common cases where this type of question might come up are Grid editing. Instead of a non-control TextBox, what normally happens is that the grid displays simple text in the grid until the user focuses on that grid. At that point a temporary, real TextBox is inserted for editing. Leaving that cell throws the TextBox away and the possibly-changed text is now displayed by the Grid.
I assume your situation is similar. If not, please explain your goals.

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.

Paint on top of a UI element WPF

I am making a project that draw Numbers in multicolored random dots. If you type in a 1,000,000 the scree will slowly paint with 1M dots that look like the number. I'm migrating to WPF and wanted known if there is an easy wat to pain on top of a text block as that will save a lot of hit testing for me.
Adorners are designed to do exactly that. They allow you to render controls, drawings, or anything you like on a separate layer that is always on top of other controls.

GDI+: Alternatives to DrawReversible for visual selection indicators?

I've searched around for an alternative way of drawing selection indicators for visual objects (like selected edges, lines etc.) without the use of ControlPaint.DrawReversibleFrame and related XOR methods. The reasons are unwanted XOR-ing "artifacts", reversibility not applying to bitmaps, no control of the actual visual look and slowness.
On the other hand I want to avoid having to repaint the whole scene (map actually) if a user decides he wants to deselect an object or two, because the repaint could be quite expensive.
So the only alternative I can see is implementing some basic drawing logic directly on a Bitmap, but with storing the previous contents of the pixels before they change. Then (in theory) I would be able to reapply old contents of, say, an selected edge rectangle if the user chooses to deselect that edge.
My question is whether you think this is a good idea or do you see some other alternatives to my problem (within the GDI+)?
Thanks in advance
If the selection indicator is just drawn on the top of the unselected object, you can use two bitmaps, draw all the unselected objects on the background one and the selection indicators on the other, and paint them both on screen.
Else, you can do the same, except that you render the selected objects instead of just indicators.
Only store the rectangles "of interest" in an off screen buffer. And repaint when the focus is lost. . . Or if you can redraw just the portion as it appears normally based on in memory data you should be fine. Otherwise it seems that you have the gist of it.

Categories

Resources