PropertyGrid look-and-feel appearance changed [duplicate] - winforms

I just upgraded some systems to Windows 10 Creators Update and I noticed that the windows forms PropertyGrid control changed its default visual style for headers and bar margins to dark gray, like so:
And as mostly happens with unexpected visual changes, users are not happy. Is there a way to revert back to the old default or maybe override the default style?

There's a bug in PropertyGrid:
The property PropertyGrid.LineColor has a DefaultValue attribute Set to SystemColors.InactiveBorder.
But the internal field lineColor is initialized with SystemColors.ControlDark.
This is bad, because the Windows Forms designer detects that the property has the same value as the DefaultValue attribute, and therefore it does not write the designer code for the PropertyGrid.LineColor property in InitializeComponent. So at runtime, the property is initialized to SystemColors.ControlDark.
As a quick hack, you can set the property after InitializeComponent:
InitializeComponent();
propertyGrid.LineColor = SystemColors.InactiveBorder;

We are reverting header color to InactiveBorder in the default windows theme in the next release of the .Net Framework, which most likely will be included in the Windows 10 Fall Creators Update. The reason this change was introduced, was that the foreground and background colors were not contrasting enough in one of the High Contrast themes, this is why we are reverting to the previously used color only in the default theme.
For your reference, internal work item number, that will be also mentioned in release notes for .Net Framework 4.7.1, is 407249.
Thank you, Tanya

This seems to be a "feature". From the .NET Framework 4.7 Release Notes:
Changed the background color of property grid lines to provide an 8:1 contrast ratio for high contrast themes.
So, I'd say, no, with Windows 10 Creators Update, there's no way to revert to the old style without recompiling (see this answer).
I complained here.
Update
I refined the PropertyGrid class like this:
sealed class LightPropertyGrid : PropertyGrid {
static readonly Color DefaultLineColor = (Color)
typeof(PropertyGrid)
.GetProperty(nameof(LineColor))
.GetCustomAttribute<DefaultValueAttribute>()
.Value;
public LightPropertyGrid() {
LineColor = DefaultLineColor;
}
}
I'm inferring the initial value for LineColor from the default value defined on the same property. Of course, you can simply assign LineColor = SystemColors.InactiveBorder.

Related

Changing the default setting of a WinForms control property

I seek to change the default setting of a .NET Windows Forms control's property, without creating a custom control inheriting from it.
What I want is, for example, to add a TextBox on my Form that already has the TextAlign property set to HorizontalAlignment.Right instead of HorizontalAlignment.Left. Even if only solution-wide, if achievable, I would love to know. This would save a lot of time for when one is working with a LOT of controls and needs to set their properties to specific, non-default, values.
Creating a custom control is just too overkill for this, and would clutter my solution with unnecessary things. I have also considered running a regex on the designer files solution-wide (to add the non-default values to such controls), but writing regex like that can (also) be time consuming/problematic.
Any ideas?
There is a way to do that. But you need to set the binding initially. Later on you can set in one go to all the controls of your choice. This might be not your exact answer but this is how we define styles like as in WPF
(1) Click the Application Property Bindings
(2) Define Binding
(3)Now for textbox you can set the initial default
(4) Now You can set the property binding of every textbox intially or you can code which will set the application settings at starup or on form load.
This will you help to change the default propety at once later on

How to change the default font of the form controls in Visual Studio IDE

I would like to set the default font of the form components from Microsoft Sans Serif to MS Outlook
I can change the font every time I put a new control on the form but its time consuming. I didn't find any help or options for it in the Visual Studio 2012.
How can I change the default font for any added control?
Many Controls you add to a Form, default to some of the Form's properties. That includes the Font of the Form as well as its BackColor. This comes handy if you want to use, say Consolas,10 for all Controls..
Here is MSDN on these 'ambient properties'..:
An ambient property is a property on a control that, if not set, is
retrieved from the parent control. If the control does not have a
parent and the property is not set, the control tries to find the
value of the ambient property through the Site property. If the
control is not sited, the site does not support ambient properties, or
the property is not set on the AmbientProperties object, the Control
uses its own default values. Some objects derived from the Control
class might set the property even if you do not. For example, the Form
class always sets the ForeColor and BackColor properties.
TextBoxes and some other Controls don't get the Backcolor, though.
Note: Changing the Form's font will change those 'inherited' Fonts of all Controls on the Form, including TextBoxes, Lists etc. Those properties you have set directly will not change, though.
So: If you want to use varying Fonts, get the Form's Font right first and try to avoid an uncontrolled mix of default and set values! (You can check which you have set in the From.Designer.cs file..)
I have the same question which bothers me very much, and I can not find the solution for months. Today I finally find a possible solution using my limited concepts on c#.
Back to the topic, just add the 2 lines below in the file "form1.designer.cs", which is in the installation directory of visual studio. My visual studio 2010 have the directory like this :
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\CSharp\Windows\1033\WindowsApplication.zip
using System.Drawing; ///this line on top of all
this.Font = new Font("Arial", 16); ///this line in the InitializeComponent()
There are some side effects because some properties rely on the font size, such as the form size will grow because of the Form's AutoScaleMode, default size of button/textbox would be not suitable as you know... But it is not a big issue. A nice programmer could solve this kind of issue by himself.
In this manner you could change anything, such as button/lable font, color... All depend on your imagination.
This is my first post. I hope it helps some guys like me.
The easiest way i found is find and replace feature.
Just double click an item lets say a command button then inside the code hit Ctrl +F to find "font". after you find which default or current font is in use, now broaden the Find to Find and Replace and now replace with your desired font.

Designer automatically re-sizes form when certain properties are set

I am facing an issue where a WinForms form is being automatically re-sized every time the designer is opened.
This only appears to happen with a certain setup, however it can easily be replicated with the following steps...
Create a new project in visual studio
The default form size is 300 x 300, but whatever you set it to make a note
Set the FormBorderStyle property to FixedSingle
Set the ShowIcon property to false
Set the ControlBox property to false
Save the changes
Close the designer
Re-open the designer and you will notice the form has shrunk by 4 pixels (both width and height)
The problem I have with this is that when it happens it does not resize any of the controls (i.e. the ones set with anchors), so this means I end up with controls that overlap the form edge and everything needs to be manually readjusted every time I open the designer which is a pain.
So the question is: Why is this happening, and what can I do to stop it happening?
I am currently using Visual Studio 2012 Professional, and John Willemse has confirmed via comments that this issue is also present in Visual Studio 2010 Professional.
I see it, this should be a bug in any VS version. It is caused by the ShowIcon property, the designer doesn't handle it correctly when you set it to False. At issue is a bit of code in the Form class that looks like this:
FormBorderStyle borderStyle = FormBorderStyle;
if (!ShowIcon &&
(borderStyle == FormBorderStyle.Sizable ||
borderStyle == FormBorderStyle.Fixed3D ||
borderStyle == FormBorderStyle.FixedSingle))
{
cp.ExStyle |= NativeMethods.WS_EX_DLGMODALFRAME;
}
In other words, when ShowIcon is False then it uses a different border style from WS_BORDER, it uses the one of a modal dialog. Which has different borders on older Windows versions, they are fatter. Not exactly sure what inspired this code, probably has something to do with Windows 98.
Problem is, the Size property is a calculated value, the Winforms designer only stores the ClientSize property. So when ShowIcon is False then it should redo this calculation, it doesn't.
You can report the bug at connect.microsoft.com but the odds that Microsoft is going to fix it are exceedingly low so it would probably be a waste of your time. There is a very simple workaround for it, instead of setting ShowIcon to False in the Properties window, do it in the constructor instead. Like this:
public Form1() {
InitializeComponent();
this.ShowIcon = false;
}

Is there any ways to change color of label in RTC?

In the form, I would like to set the color of text in Label. Actually I can set it in Classic by using Label property called "FORECOLOR". but unfortunately in RTC doesn't change the color.
Are there any ways to do so in RTC ?
Thanks in Advance,
Makara
In the RTC the color options have been reduced. Essentially this is due to the change of "paradigm" in Forms vs Pages.
In Pages, controls have lost the ForeColor property, but gained the Style property. Essentially this changes the way NAV looks at data (knowing what the intention of the data is, rather than hard coding a color -- this allows new clients, such as the Web Client, to display it in it's own way if appropriate).
The style property can be set in the following ways (MSDN);
None (No colour)
Strong (Bold)
Attention (Red)
Favourable (Bold + Green)
Un-favourable (Bold + Italic + Red)
These 'styles' can be turned on and off using the Boolean StyleExpr property. This can be a variable to dynamically switch plain black, and the selected Style.
If you're using the transformation tool, the form property Forecolor is ignored and not translated to the Page's Style property. Properties in Forms and Pages are set independent of each other.
As for other colors, it's not possible out of the box. You could develop a Client Control add-in to create a custom control with colors however it seems a little bit of overkill. It'd have to be installed on all PC's that use NAV. I'd recommend just using the Style option :)

Winforms Checkbox : CheckState property Indeterminate renders differently

In C# environment, setting a checkbox's CheckState property to Indeterminate displays a "green square" inside the checkbox.
In VB environment, this displays as a "grayed out check" (which is less intuitive, even for "dummy" users).
How do i make Indeterminate state look like a "green square" in VB.NET ?
Btw, i am using VS2008, Winforms 2.0.
(Btw2: I tried to create two tags CheckState Indeterminate, which is more appropriate to my question, but disallowed by StackOverflow due to points!)
You need to enable XP visual styles for your application to get the green square. Try this in your Main function before calling Application.Run(...):
Application.EnableVisualStyles();

Resources