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

回眸只為那壹抹淺笑 提交于 2020-02-02 06:39:26

问题


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?


回答1:


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..)




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/26636268/how-to-change-the-default-font-of-the-form-controls-in-visual-studio-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!