Mnemonics in ComboBox control - winforms

I have inherited a ComboBox control mainly to create a different visual look. However, this behaviour where the ampersand is being turned into a shortcut (letter after is underlined) in the text field of the control has me stumped. I know this feature exists on Label controls and it can be turned off but here? How can I turn it off?

I have found the culprit. I've used Graphics.DrawString for drawing items and TextRenderer.DrawText for textbox portion of control. The former by default doesn't draw mnemonics and the latter one does. In both methods this feature can be turned on or off.

Related

wpf textbox errortemplates in a Managed Addin Framework Addin

I've created a textbox style to contain a validation.errortemplate for use in a UserControl class. If the UserControl is loaded in the normal, non-MAF way, I can see the validation rule kicking in and getting visual feedback (thick red border, a circular bang to the right of the textbox, and an error message-in-a-tooltip) -- everything works the way I expect it to.
However... if I load that same UserControl in as an AddIn, I lose the visuals. (I do see the error tooltip behaving correctly, so I know my validation rule is firing; I just don't see the border and bang symbol.
My AddIn, by the way, is based on MSDN's example for an 'addin-which-provides-a-usercontrol.'
I know a few of the limitations of an AddIn (e.g., video won't play in an AddIn UserControl); is this another limitation, or am I screwing up?
Thanks in advance!
[Update -- I removed the error template from my UserControl.Resources -- as I suspected, in the non-MAF version, this causes the validation failure to result in the 'standard,' thin red border around the textbox. However, no such red border shows up in the MAF version. Ergo, the TextBox.Style seems to have been ruled out as the culprit.]
Got it working by enclosing the fields I want to validate within an AdornerDecorator tag... go figure :-)

WPF slider behaving like combobox

I need a control where user can pick only one option. Combobox is fine, radiobuttons are ok, but for some purpose I think about another crazy, but interesting solution.
There should be a slider control on a window and three possible positions of this sliding thing. I know this can be easily accomplished by setting slider's Minimum and Maximum plus TickFrequency and IsSnapToTickEnabled properties.
Now, is there a way how to add labels on left/right edge and center of slider showing user options within the slider? Or is it neccessary place labels/textblock below?
Last, though the most important thing is, how to associate integer slider positions with string options? I thought about switch, but this is wpf - there is "more wpf" solution, isn't it?
Just drag slider's rider to it's position and by binding set class string property to appropriate value.
Every control within WPF can have its visuals completely modified to suit your needs. This was/is the beauty of WPF over WinForms.
Can your slider have a TextBlock within it? Absolutely. Style as you desire and be on your way. A great article can be found via MSDN Magazine which outlines the approach to customizing WPF controls.
With regard to the integer values, use an IVauleConverter to translate the values to whatever you prefer.

How to achieve a transparent BackColor on an original WinForms control?

I'm about to lose my mind here.
Why won't the checkbox control blend with what's behind it?
The question applies to all WinForms controls, but I'm using this as an example.
A picture is worth a thousand words:
And a few more words:
What's behind the CheckBox are colored PictureBoxes and a Button.
The CheckBox's BackColor is set to Transparent. But somehow it decides that that means it should share the BackColor of the containing Form (is that its idea of the illusion of transparency?).
Is this not possible in WinForms? I could swear I did this before.
UPDATE:
I just tried this:
On that form, set the CheckBox's BackColor to Transparent, then change the BackColor of the containing Form to some other color, and the CheckBox will match that BackColor. What the.......?
This is a side effect of controls being Windows windows. A window is responsible for drawing itself, the OnPaintBackground and OnPaint methods take care of that.
This rendering model doesn't support transparency well. There is support for true transparency by using layered windows. That's implemented by the video adapter, Windows uses it hardware overlay feature. But that only works for toplevel windows, not child windows. Note the Form.Opacity and Form.TransparencyKey properties.
There's partial support for transparency through a trick. A control can fake it by asking the parent window to draw itself first inside the control window. That produces the background pixels, it can then draw on top of that. Setting the BackColor property to Color.Transparent enables this trick for controls that support this. All of the ButtonBase derived classes do. But not controls that are wrappers for native Windows controls.
"Asking the parent window" is where the flaw in this trick becomes visible in your screen shot. You are seeing the form pixels. Stacking effects don't work, it never considers any intermediary window in the Z-order, only the parent. This is fixable but very ugly, there's a KB article that show the code.
Also notable is that WPF doesn't have this restriction. Controls are not windows, they render by painting themselves on top of the parent. Layers of paint. Transparency is now trivial, just don't paint.
Bob Powell has written an excellent article about transparent controls. Check it out:
https://web.archive.org/web/20141227200000/http://bobpowell.net/transcontrols.aspx
Can you set the backcolor of the checkbox manually to the color you want? (The value in the picturebox behind it)
'Transparent' may mean something different from what you want to MS.
Also, try changing the zorder of the pictureboxes (bring to front) and see if that changes the checkbox's underlying color.

Winform TabControl style

I'm once again turning to you since I can't find an answer anywhere else. I have a TabControl, but I want to get rid of the ugly orange bar on top of the selected tabs. I would also like to make the tab text BOLD when selected and NORMAL when not.
Is there any easy way to achieve that goal ? I don't want to use the Appearance Buttons or Flat Buttons.
Thanks for your help !
This appearance is controlled by the Visual Styles theme selected in your operating system. In general, users do not appreciate any program that ignores their theme settings, especially when they paid money for a custom one. But you can get what you want, you'll have to set the DrawMode property to OwnerDrawFixed and implement a handler for the DrawItem event. There's a good example to get you started in the MSDN Library article for this event. Just change the font assignment in that sample code.

How can I prevent the VS WPF designer putting margins on every object from the toolbox

When I drag a control from the toolbox on to the Visual Studio 2008 WPF design surface, it sets a margin based on where I dropped it and a default size.
Is there any way to prevent VS setting those? When I drop a control on a stackpanel I want it to flow in to the existing controls in the panel.
Thanks!
I've never found a way to prevent this. I just type the XAML instead.
EDIT:
I wrote the above nearly three years ago. In the meantime, it would appear that the design-time experience has gotten a lot better.
While the designer still adds hard-coded margins if you drag-and-drop, there are ways to remove those margins without having to do it by hand.
Here's a link to an article that illustrates how to use design tools in Visual Studio 2010 to lay out a form without having to type any XAML. (Despite the title, it's about WPF.)
The first part of the article shows hard-coded pixels, but I've linked to the second part that shows how to lay out the controls without that hard coding.
Layout Techniques for Windows Form Developers
When I drop a control into a stackpanel, it doesn't add margins, it "flows" in with the rest.
The controls you drop onto the design surface have a margin by default because that's how it knows where it's placed. What I typically do is create a grid and set it's margin where I want it, then create columns and rows to put controls into. I drop in my other controls which will add margins which are usually not what I want. After I have all my controls into my grid, reasonably placed, I switch to XAML view and either remove the margin completely (which causes a control like a button to fill the entire space), or make the margin something like 5, which puts some nice padding around the control.
Bottom line...and this is especially true with Silverlight development, you must get used to manipulating the XAML directly. It's the only way you'll get the layout exactly where you want it. This is my opinion and most everybody in my shop who does WPF/silverlight development.
Unfortunately there does not appear to be a means to do this.
The default size is set as a result of you manipulating the size of your control is the designer. When you increase the width and/or height of a control the designer is interpreting your actions as a request to make the control that specified width and/or height.
A similar situation is encountered with the margins. As you alter the position of your control within the designer, it modifies properties to achieve the layout you've created. In the case of most containers the simplest solution is to modify margins in order to achieve the desired position, as you've already pointed out the simples solution is not always the most desired.
Personally I prefer to only use the XAML editor and only occasionally take a peak at the WPF Designer when I want to see the current layout. I also tend to favor using the Grid to layout most of my windows/controls as it provides the greatest flexibility not only for sizing and positioning, but for other tasks/features such as animations, transforms, etc.

Resources