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

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.