How do I set button font to Marlett - c#

I'm attempting to set a font of button to system's Marlett font. However, though I manually set the font-face, other font is used. Also, Marlett is not listed, when I use the font dialog to choose a font for that button.
Why is it so? What can I do to use Marlett font in .NET Windows Forms controls?

Though I do not know what code is behind the designer, I have always found that custom installed fonts do not show up in the designer. The good news is that the Font property is ambient so if you wanted all controls to have the same Font you would only have to set it at the Form. However, it seems like you just want one control to have the Font so let's do this:
ctrl.Font = new Font("Marlett", 8.5f);
which will set that control's Font to Marlett and a size of 8.5 for example.
If you wanted an entire set of controls to have the same Font, if they can be placed in a container like a Panel, then you would only have to set the Font of the Panel; because again, it's an ambient property.

button1.Font = new Font("Marlett",8, FontStyle.Regular);
put this code for your button name Button1 , where you want change ( in from constrcutor after iinitializecomponet or in form Load event )

It would seem that the designer by default wants to set the GdiCharSet to 0. This causes the Marlett font to fall back to another font.
If you change the GdiCharSet to 1 it will render normally.
Also note the changes it makes in the .designer.cs, this will also explain why it did work when you would set the font manually from code.

This is what finally worked for me.
ctrl.Font = new System.Drawing.Font("Marlett", 12f, FontStyle.Regular, GraphicsUnit.Point, ((byte)(1)));
The last ((byte)(1)) sets the GdiCharSet to 1, which #Paul noted in one of the other answers.

Related

How to fix TextBox height in C#

Hi, guys..
I'm working on a small project with C# language in Visual Studio 2010 for my own business (Not using WPF). So, In the designer, I normally added a TextBox from ToolBox to the Form and, then normally changed the name of the TextBox from Properties Box. After that, I wanted to change Font Name & Size (The default values for Font name and size are "Tahoma" & "8.75" respectively). So, when I changed the Font name to " Times New Roman", the size of the Font was small, So I decided to change it From the default value to "11.5". So, when I changed the Font size to required value, it got changed, but the TextBox height increased. So, How can I change the Font size for the TextBox to get bigger without any effect on the height property?, In other words, how to fix the TextBox height, when I changed the Font size to get bigger?..
Thank you so much for your interest, I hope I got the problem clearer..
(Note: I haven't used a code yet. Just from the Designer)
The TextBoxBase.AutoSize property determines whether the height of the TextBox will change to fit the the size of the font. If you set it to false, you can change the height to whatever you want regardless of the font size.
This property is not visible in the Properties window, so you will have to set it in code. If the name of your TextBox is textBox, then:
textBox.AutoSize = false;

Set the font in winforms designer to a Font object

I'm working on a project in Windows Forms and I want to use custom fonts for buttons etc.
I have a static class that contains the styles of fonts that I want. For example:
ParagraphFont = new Font(Properties.Resources.Font, 14.25F);
TitleFont = new Font(Properties.Resources.Font, 48, FontStyle.Bold);
I want to be able to apply the font to the form/user control through the designer, but I can't figure out how to do this.
I've tried setting the fonts of all the controls to these variables after the InitialiseComponent() method, but this seems long-winded and tedious to do to the multiple forms and controls that my project has
Is there a quicker way of doing this?
Edit: My question is different to the suggested duplicate. I don't need to set the default font of the project, I want to set the font of each control individually to a style variable. For example:
label.Font = ParagraphFont;
In the designer. This way, I can change the font used in ParagraphFont at any time

Design-time size of Label (Compact Framework)

I refer to the Visual Studio design view. When adding a label using the full .NET framework, System.Windows.Forms.Label controls have an AutoSize property set to True by default. If I drop a Label control onto a form, the default font is "Microsoft Sans Serif, 12pt, Regular" and the height of the control is 20. Change the font to (say) "Tahoma, 14pt, Bold" and the height automatically changes to 23. Fine.
But in the CF (Compact-Framework), Label controls do not have the AutoSize property. When I change the font as described above the height of the Label does not change (staying at 20) and some of the text is chopped off).
My question is: Short of opening a full .NET project and testing my font selection, is there a way to know what height to set my Label at design-time?
You can use the graphics object for to measure the height of the string, for example in Paint event or OnPaint method:
Graphics g = e.Graphics;
float lineHeight = g.MeasureString(this.Text, this.Font).Height;
it can be used in inherited label. for example you can override OnPaint method or somewhere else and do this, then it will run in design-time.
More resources:
Base on Font height in compact framework
Aslo you can take a look at Multi-Line Graphics.MeasureString on .Net CF that uses DrawText from coredll.dll.

How can I change the font in a DataGrid?

I am using:
dg.ForeColor = System.Drawing.Color.Black;
dg.BackColor = System.Drawing.Color.Beige;
to set the background and foreground color of a DataGrid. How can I change the font to say Calibri or any others using the built-in methods.
If this is a web application, the DataGrid class already provides a Font property that you can set to
a font of your choosing. You can set it either from the designer or in your source code, just as you've set the BackColor and ForeColor properties.
However, as I mentioned in a comment, you should be very careful about setting controls to use a font that the user might not have installed on their computer. I recommend checking a list of web-safe fonts.
You can change the font with this code
dg.Font=new Font(string familyName,int size);

How to make text/labels smooth?

Does anyone know how to make labels, or text, smoother? At the moment they look quite jagged. As I want to make the label dynamic, I can't just insert the text from Photoshop.
You'll have to dynamically generate images representing your text if you want to anti-alias it. Here is an example on msdn: http://msdn.microsoft.com/en-us/library/a619zh6z.aspx
EDIT: Editing per comment below.
The link describes using the OnPaint event of your control to use a different TextRenderingHint. If you're wanting something a little more re-useable what you can do is create a Custom Label class that extends the Label class, and use this in your forms:
public partial class CustomLabel : Label
{
private TextRenderingHint _hint = TextRenderingHint.SystemDefault;
public TextRenderingHint TextRenderingHint
{
get { return this._hint; }
set { this._hint = value; }
}
protected override void OnPaint(PaintEventArgs pe)
{
pe.Graphics.TextRenderingHint = TextRenderingHint;
base.OnPaint(pe);
}
}
Add a new Custom Control called CustomLabel (or whatever you want to call it) and use the code above. Rebuild your project and you should then see the CustomLabel control appear in your toolbox at the top, under the "MyProject Components" category. In the properties pane for this custom label you'll see the new TextRenderingHint property. Set this to "AntiAlias." Add another label to your form and compare how they look.
If you want to default it to AntiAlias simply change the default value of the private variable.
Are you referring to ClearType? Then ClearType has to be enabled in Windows, and you must use a modern font, such as Tahoma or Segoe UI, not MS Sans Serif.
Update
You posted an example of the problem. I magnified it to 400 %. Clearly ClearType subpixel antialiasing is enabled. Personally I do not think the text looks jagged. If you want higer quality on-screen text you could buy a screen with a higher physical resolution (pixels per inch), and then draw the text at a (correspondingly) larger size. Then the text will have the same size on your screen, but will look much more smooth.
You could also give up on ClearType and use some other font-smoothing algorithm, but that is far from trivial, because ClearType is the font-smoothing system on Windows.
Update 2
If you are running Windows 7, you can fine-tune ClearType. Just open the start menu, write "ClearType" and start the guide. I think there are guides for Vista and XP too, but perhaps not installed by default, but available as PowerToys or something like that...
Make sure you have ClearType enabled.
Install MacType program, it smoothes your Windows font like MacOS, I don't know why Microsoft don't fix its Windows smoothness font?
If Microsoft fixed its fonts, I don't need to install third party app to such things like that which is fundamental for Windows.

Categories

Resources