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 7028003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:19:43+00:00 2026-05-28T00:19:43+00:00

In a C# forms project, I can write the following code to get something

  • 0

In a C# forms project, I can write the following code to get something like what I want, but it seems that there are two different “worlds” that I am trying to fuse.

FormattedText text = new FormattedText(textBox1.Text, CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight, new Typeface("Tahoma"), 20, System.Windows.Media.Brushes.Black);
text.MaxTextWidth = 480;
text.MaxTextHeight = 480;
DrawingVisual d = new DrawingVisual();
DrawingContext d1 = d.RenderOpen();
d1.DrawText(text, new System.Windows.Point(0, 0));
d1.Close();
RenderTargetBitmap bmp = new RenderTargetBitmap(480, 480, 120, 96, PixelFormats.Pbgra32);
bmp.Render(d);
System.Windows.Controls.Image I=new System.Windows.Controls.Image();
I.Source = bmp;

Gets me a Windows.Media.ImageSource. I want to migrate the whole thing to use the System.Drawing namespace.

Since I basically had to import WPF libraries to make the above code work, and what I am looking to do is so basic, how can I do it in Windows Forms, preferably in a non-cludgy way.

Note: All I really want to do is draw text on a bitmap in a way that allows line wrapping, and then manipulate it as a bitmap. If there is a simpler way of doing that (in Windows Forms) that would work just as well, if not better.

  • 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-28T00:19:44+00:00Added an answer on May 28, 2026 at 12:19 am

    Yes, that’s WPF code, an entirely different world. The System.Drawing version ought to resemble something like this:

    var bmp = new Bitmap(480, 480);
    using (var gr = Graphics.FromImage(bmp)) {
        gr.Clear(Color.White);
        TextRenderer.DrawText(gr, textBox1.Text, this.Font, 
            new Rectangle(0, 0, bmp.Width, bmp.Height), 
            Color.Black, Color.White,
            TextFormatFlags.WordBreak | TextFormatFlags.Left);
    }
    if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
    pictureBox1.Image = bmp;
    

    I guessed at a picture box on the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a project there are a number of forms that are processed
I'd like to write a small JavaScript (framework) that can chain functions with all
I have a WinForm project that contains a form called MainUI. You can see
I have a Windows Forms project in Visual Studio that reads configuration files from
I have a VB.NET Windows Forms project that at one point paints text directly
I have a C# Windows Forms project open with some C# code in it.
I'm working on a visual studio 2005 vb.net windows forms project that's been around
I have a treeview control in a Windows Forms project that has checkboxes turned
I wrote the following code in python to solve problem 15 from Project Euler
In the following code, the asp does not enter the action listener (Button1_Click). Can

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.