473,545 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Embedded font for button

Hello all,

I've added a font to my project and set it to "Embedded Resource".

I load the font into a global PrivateFontColl ection. (InitCustomFont -
shown below)

I then set the font of a label to be equal to the custom font
(SetCustomFont - shown below)

The font size changes but the family doesn't. If I write directly to
the form using Graphics.DrawSt ring the new font is displayed???

Does that mean I can't change the font of labels/buttons etc. to
resource fonts?

Gareth

private void InitCustomFont( )
{
// Load the resource
Stream fontStream =
this.GetType(). Assembly.GetMan ifestResourceSt ream("Graphyx.c ustom.ttf");

// Create a buffer to read into
byte[] fontData = new byte[fontStream.Leng th];

// Fetch the font program from the resource
fontStream.Read (fontData, 0, (int)fontStream .Length);

unsafe
{
fixed (byte* pFontData = fontData)
{

// Pass the font to the font collection
pfc.AddMemoryFo nt((System.IntP tr)pFontData,
(int)fontStream .Length);
}
}
// Close the resource stream
fontStream.Clos e();
}

private void SetCustomFont()
{
System.Drawing. Font fn;
FontFamily ff;

ff = pfc.Families[0];

fn = new Font(ff, 16, FontStyle.Regul ar);

//lblHelp.Font = new System.Drawing. Font("Courier New", 16.0f,
(FontStyle)2);
lblHelp.Font = fn;
}

Feb 8 '06 #1
0 6481

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
8072
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept could work in reverse, i.e. we have a cost model written in Excel that calculates the profitability of customer accounts based on several inputs and...
2
16183
by: Jim | last post by:
Working with VB.net under VS.Net 2003. Have a simple form with a Button1. I want to change the font on the button when the button is clicked. Is there a way to Dynamically change the Font for Button1 from regular to bold, change the size etc. This line of code: Button1.Font.Bold = True
7
2936
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
1
1859
by: Blasting Cap | last post by:
I am having trouble changing the font for a PushButton control in a datagrid button column. I have seen several posts refer to styles and simple changes to the HTML for font changes but most of those referred to a LinkButton type of control. But in cases where someone is using the PushButton there are no posted solutions. Whenever these...
1
5593
by: erictomlinson | last post by:
I'm dying here trying to figure this out for days. Here's the scenario: 1) External script.as file dynamically imported to loader.swf file that creates a textfield (createTextField) 2) Content for the text field should be provided by an XML file 3) Content styled by external css file 4) Fonts need to be embedded so as to apply anti-alias
6
2847
by: andrew.ames | last post by:
Hi I have a pretty basic windows application created in Visual Studio 2005 and VB.NET. I set my Form's font to Arial 8.25pt, so when i added a label and a button they automatically have a font of Arial and 8.25pt. Great.
1
1516
by: CMiner | last post by:
What I am trying to do is this: Let a user browse for font files that are not installed, select one, and show a sample of the font in a text box (That way the user can change the size, style, and text of the sample) I don't want to copy the font files to the Windows\Fonts\ folder. Tried that, causes a lot of issues with deleting the font file...
0
1556
by: =?Utf-8?B?Qm9iIFdhaXRl?= | last post by:
I have written a calculator emulator which uses an LCD font in VB.NET in VS2005. This application will be installed by means of an MSI file and I dont want the user to have to manually install the font. So I have made the font an embedded resource and, by adapting code from http://www.bobpowell.net/tipstricks.htm, I now have the font working...
4
1984
by: DamienS | last post by:
Hi, After many years of using html/css/asp etc for the first time I've had a requirement to use a custom font in a website. "That shouldn't be too hard" thought I, "that would be a pretty common thing to want to do, surely there's a million solutions to it". Anyway - jumping into Google I was surprised at what I found. As far as I can...
0
7409
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.