Reputation: 657
What is wrong in my code
Dim privateFonts As New System.Drawing.Text.PrivateFontCollection()
privateFonts.AddFontFile("C:\Documents and Settings\somefont.ttf")
Dim font As New System.Drawing.Font(privateFonts.Families(0), 12)
LBL_Test.Font = font
I have error on line: LBL_Test.Font = font
LBL_test is standard label like that:
<asp:Label ID="LBL_Test" runat="server" Text="Label"></asp:Label>
Upvotes: 1
Views: 631
Reputation: 32212
Since you're in a web page, you can't use a Font
object like you'd do in WinForms or WPF, and indeed the documentation shows that the Font
property is readonly:
Public Overridable ReadOnly Property Font As FontInfo
Instead, you're working with CSS and HTML styling, so you can style it using those sorts of properties, for example:
LBL_Test.Font.Name = "Verdana"
LBL_Test.Font.Bold = true
To do this sort of styling, you're often better off adding a CSS class and using stylesheets to do the styling, eg:
LBL_Test.CssClass = "MyClass"
Or in your markup:
<asp:Label ID="LBL_Test" CssClass="MyClass" runat="server" Text="Label"></asp:Label>
and then in a stylesheet:
.MyClass {
font-family: Verdana;
font-weight: bold
}
etc.
Having said all that, it looks like you want to use some sort of custom font. In order to do that, you'll either need to have it installed on the computer the browser is running on, or instead use a web font:
@font-face {
font-family: "MyCustomFont";
src: url("http://your-server/somefont.ttf");
}
.MyClass {
font-family: "MyCustomFont"
}
Upvotes: 2