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

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.

Related

Visual Studio breaks Visual Inheritance

I have made a FormBase, from which I inherit a FomBaseList and a FormBaseDetail.
All other forms in the project are derived from FormBaseList or FormBaseDetail.
Now it seems that VS has huge problems with that, and my biggest problem is that VS keeps writing property values from the Ancestor form into the designer.cs from the child form.
for example, in FormBaseList I have this property/value :
this.gttDXGridView1.OptionsView.ShowAutoFilterRow = true;
I expect that in a derived form, for example FormClientList, there is no mention for this value in the designer.cs, because it should fetch the value from its parent. In other words, just plain simple basic OOP.
And I also expect that when I change the property in FormClientList to
this.gttDXGridView1.OptionsView.ShowAutoFilterRow = false;
that this is seen as an override from the baseclass.
However, VS keeps overwriting the property in FormClientList.Designer.cs with the value found in FormBaseList.Designer.cs.
This breaks the rules of OOP in my opinion, other tools that support Visual Inheritance like Delphi for example do this correct.
How can I stop VS from doing this ?
The properties are changed using the designer.
All controls are DevExpress controls, or derived from a DevExpress control.
Another example, which works just opposite so its very strange.
For example put a Button on the BaseForm and give it an image.
The button with the image appears on all derived forms.
Now change the image on the button of the BaseForm.
You would expect the image to change on all derived forms also, but that does not happen.
I discovered that again VS has written the property value of the button in all derived designer.cs files, and this time it does not overwrites them.
I created a ticket about this at the DevExpress forum, and they where able to reproduce it.
It is now passed on to their developers.
https://www.devexpress.com/Support/Center/Question/Details/T692940/devexpress-controls-break-visual-inheritance-in-visual-studio
It also seems I was not the first to report a similar problem.
https://www.devexpress.com/Support/Center/Question/Details/T692244/imageoptions-are-serialized-in-a-successor-when-visual-inheritance-is-in-effect

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

Strange Overlay Icons Visual Studio

I downloaded a project off codeproject and was messing around with it (I am more an asp.net developer) when I noticed these overlay icons...the lock one on the label is really interesting as when I right click the control is unlocked yet all the properties are grayed out. When I add a new label I do not have that lock icon when I select it. What is this? Also what is the double boxes icon (the other 8 that are highlighted)?
The Winforms designer observes standard .NET accessibility keywords. The Modifiers keyword for a control is what counts here. That sets the access keyword for the member variable. The default for a C# project is private, for a VB.NET project it is Friend. VB.NET is more friendly about it.
That matters when you derive a form from a base form, Project + Add New Item, Windows Forms node, Inherited Form item template. The derived form will have the controls of the base form but they cannot be changed if their Modifiers property is Private. The designer makes it obvious by displaying the lock icon. And by displaying the properties of the control in gray text.
Normally this means that the controls are defined in the base control and so you cannot change them in the derived control (so they are all locked).

WPF Popup permanently displays in Visual Studio design-time

I’ve met strange behaviour for WPF design-time in Visual Studio 2010: after an instance of the Popup class was created, and I switched the code tab in Visual Studio to a different file, the Popup still remains on the screen!
I have a piece of code, which allows to reproduce this, but I am not sure if I should paste it here (it's not so short), so maybe I'll just give a link to it: here.
For unknown reasons beyond mere mortals' comprehension, Microsoft has decided this is the default behavior of the Popup class in WPF. You have to implement the "hiding" logic yourself. I suggest handling the Window.LocationChanged, Window.Activated and Window.Deactivated events of the Window containing the Popup and close it yourself.
Edit: To clarify myself, the Window events you need to handle are the events of the window that contains the Popup's PlacementTarget element. Usually when you create a popup, you set it relative to some element contained in an application's Window (similar to how the tooltips work). If this is your case, then my solution is correct, but I forgot to mention this point about the PlacementTarget.
In your code behind; you can simple check this boolean:
DesignerProperties.GetIsInDesignMode(this);
"this" represent the object containing the popup. For example the Window.
If true you can say:
myPopUp.IsOpen = false;
For Store Apps/WinRT:
Windows.ApplicationModel.DesignMode.DesignModeEnabled

Wpf- How does the textbox in visual studio collapse regions and how can I implement this in my text editor?

I need someone to point me in the right direction.
What would I need to do to collapse a region of text in a textbox?
I do not need to know how to allow a user to define regions, just how to collapse a region once you have the index and length of that region. I also want to, like visual studio does, leave a visual reminder of collapsed regions that you can click to expand them.
Visual Studio uses its own text editor control, not WPF's built in TextBox. Visual Studio's built-in text editor has many advanced features related to code editing but is not available separately from Visual Studio.
There are many open-source and componentware text editor controls available for WPF that include region collapsing. I suggest you download AvalonEdit or any of the text editor controls listed in this answer to see how it is done, and either reuse the control you downloaded or roll your own using similar techniques.
The technique most text editors use for region collapsing is to include a "outline hidden" flag in the data structure maintained for every line in addtion to an "is outline start" flag, an "outline end" pointer, and a "nesting level". By keeping these up to date and having the display templates honor them by drawing the proper icons/buttons and/or hiding the line, you can get the effect you need quite easily. Obviously this relies on your text editor's data structure tracking and displaying each line independently, which requires additional logic for selection, navigation, etc that is not included in WPF.

Resources