Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to access or generate TextStyle preview programmatically?

4 REPLIES 4
Reply
Message 1 of 5
varshaauti27
160 Views, 4 Replies

How to access or generate TextStyle preview programmatically?

Is there a way to preview a TextStyle in Civil 3D using C#.net?

varshaauti27_0-1734072574953.png

Any insights or suggestions would be greatly appreciated. Thank you!

Labels (5)
4 REPLIES 4
Message 2 of 5
hippe013
in reply to: varshaauti27

You can use the DrawString method of the System.Drawing.Graphics to draw onto a bitmap image from a given string, font, brush, and point. 

 

Here is a snippet of code from my repos with some unnecessary lines removed. 

 

Using bmp As New Bitmap(200, 40)
   Using g As Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)
      Dim size As SizeF = g.MeasureString(msg, font)
      g.Clear(Color.Magenta) 'Used to Create Transparency
      g.FillRectangle(brushWhite, 0, 0, size.Width + 6, size.Height + 4)
      g.DrawRectangle(blackPen, 1, 1, size.Width + 2, size.Height + 2)
      g.DrawString(msg, font, brushBlack, New PointF(2, 2))
   End Using
End Using

 

 

 

 

Message 3 of 5
varshaauti27
in reply to: hippe013

I'm looking for a method to preview different text styles. Instead of generating an image with specific text content, I want to explore and visualize various text styles.

 

varshaauti27_0-1734108070675.png

 

Message 4 of 5
hippe013
in reply to: varshaauti27

I am confused. What you have circled is an image displayed in a dialog box of the selected text style. The code that I posted could generate that image. So, with that said, I guess I am not sure what you mean when you say you want to explore and Visualize various text styles. So, what do you mean when you want to preview the text style? 

Message 5 of 5
varshaauti27
in reply to: hippe013

The sample code does not generate the same preview image as displayed in the TextStyle window.

Refer attached image for reference.

varshaauti27_0-1734126670583.png

 

However, I was able to replicate the correct preview image by following these steps:

  1. Opening a new drawing.
  2. Adding the required text.
  3. Assigning the desired text style.
  4. Using the CapturePreviewImage method of the Document class to capture the image.

While this approach works, I am seeking an alternative method that:

  • Does not require creating a new drawing.
  • Generates the exact preview image as shown in the TextStyle window.

Could you suggest any such alternatives or optimizations?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report