LinkLabel no underline - Compact Framework - c#

I am developing a Windows CE app with Microsoft Compact Framework. I have to use a LinkLabel and it has to be white and no underline.
So in the designer, I modified font color by white and unchecked "underline" in the font dialog.
However, when I run the application, the font is still blue and underlined.
Is there a way to remove the underline of a LinkLabel and change its color?

You can use LinkBehavior:
Me.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;

It wont be visible in the designer at Design-Time but will be correct in Runtime.
Otherwise do it in Code (which should be the same as the designers code):
Font f = LinkLabel1.Font;
LinkLabel1.Font = New Font(f, f.Style && !FontStyle.Underline)

Related

Modern UI Metro Framework HTML label text color

I am trying to change the color of an html Metro Framework label but but it stays black. I tried through the VS property windows or using code:
lbl_errorMsg.ForeColor = Color.Red;
I searched for a bug in the framework (MetroModernUI v1.4.0) but did not find anything. Any clue?
if you are using Metro in WPF
You can use
lbl_errorMsg.Foreground = System.Windows.Media.Brushes.Red;

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.

Change RichTextBox Font keeping text color

I have a lot of formatted code snippets saved in an XML file.
On request I load them and set as Rtf in a RichTextBox:
string cscode = #"{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fprq1\fcharset0 Courier New;}{\f1\fnil\fcharset0..." etc.
rtb_cs.Rtf = cscode;
The code snippets are copy-pasted from the Visual Studio, so the text is colored differently.
Different Visual Studios are using different Fonts for the text.
Is there a way to change the Font but keep the colors?
I've tried to set the Font property of the RichTextBox, but this also resets the colors.
//This changes colors as well
rtb_cs.Font = new Font(FontFamily.GenericSansSerif, 10);
Take a look at LarsTech's solution here:
Changing font for richtextbox without losing formatting
It works for other settings too.

How do I set button font to Marlett

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.

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

Categories

Resources