Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 211455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:05:49+00:00 2026-05-11T18:05:49+00:00

I’d like to load a font from an external server and once is loaded

  • 0

I’d like to load a font from an external server and once is loaded (I guess that’s necessary) use it to create a few textfields.

I’m trying:

font_uri = new Uri("http://localhost/assets/fonts/wingding.ttf");
bf_helvetica = new FontFamily(font_uri, "bf_helvetica");

TextBlock test_tb = new TextBlock();
test_tb.Text = "This is a test";
test_tb.FontSize = 16;
test_tb.Foreground = Brushes.Red;
test_tb.FontFamily = bf_helvetica;
stage.Children.Add(test_tb);

But it creates the textblock with the default font.
Any ideas?

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:05:49+00:00Added an answer on May 11, 2026 at 6:05 pm

    If you can load it into a Stream, try using a PrivateFontCollection. Example code in my answer to another question.

    EDIT: See System.Net.WebRequest.GetRequestStream, load the URI into a Stream, then load that Stream into the PFC as mentioned in the linked code.

    Also, I’d save the file locally, and look for it there first, so you don’t have to download it every time you run the program.

    EDIT AGAIN: Sorry, not WebRequest.GetRequestStream, you want WebResponse.GetResponseStream(). Here’s some sample code to do exactly what you’re looking for.

    using System;
    using System.Drawing;
    using System.Drawing.Text;
    using System.IO;
    using System.Net;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    namespace RemoteFontTest
    {
        public partial class Form1 : Form
        {
            readonly PrivateFontCollection pfc = new PrivateFontCollection();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                WebRequest request = WebRequest.Create(@"http://somedomain.com/foo/blah/somefont.ttf");
                request.Credentials = CredentialCache.DefaultCredentials;
    
                WebResponse response = request.GetResponse();
    
                using (Stream fontStream = response.GetResponseStream())
                {
                    if (null == fontStream)
                    {
                        return;
                    }
    
                    int fontStreamLength = (int)fontStream.Length;
    
                    IntPtr data = Marshal.AllocCoTaskMem(fontStreamLength);
    
                    byte[] fontData = new byte[fontStreamLength];
                    fontStream.Read(fontData, 0, fontStreamLength);
    
                    Marshal.Copy(fontData, 0, data, fontStreamLength);
    
                    pfc.AddMemoryFont(data, fontStreamLength);
    
                    Marshal.FreeCoTaskMem(data);
                }
            }
    
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                using (SolidBrush brush = new SolidBrush(Color.Black))
                {
                    using (Font font = new Font(pfc.Families[0], 32, FontStyle.Regular, GraphicsUnit.Point))
                    {
                        e.Graphics.DrawString(font.Name, font, brush, 10, 10, StringFormat.GenericTypographic);
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the Inspectable metadata tag. In your case you'll want… May 12, 2026 at 12:55 am
  • Editorial Team
    Editorial Team added an answer UniObjects for .NET is free, and part of the UniData… May 12, 2026 at 12:55 am
  • Editorial Team
    Editorial Team added an answer I'm a bit perplexed by your code and why there… May 12, 2026 at 12:55 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.