drawstring

gdi+ - Graphics.MeasureString either too wide or too narrow

删除回忆录丶 提交于 2021-02-10 14:34:07
问题 I'm using the System.Drawing library in C# to measure a string's size: SizeF size = gfx.MeasureString("Hello", myFont); However, this returns a size with a bit of spacing around the text. Here's the text rendered with a red bounding box that represents the size MeasureString returned. The TopLeft corner of both the box and the text is exactly the same point. I stumbled upon this question on Stack Overflow that recommended using StringFormat.GenericTypographic to remove the spacing. So I

How to draw unicode string using C# graphics.DrawString

佐手、 提交于 2020-06-12 06:24:09
问题 I'm trying to send khmer script(unicode) string to printer using PrintDocument provided by the .NET framework. Unfortunately it seems to me that the Graphics.DrawString() does not render khmer script correctly. Platform: Windows 7 Ultimate IDE: VS 2010 Ultimate Here is the sample code: void printDoc_PrintPage(object sender, PrintPageEventArgs e) { var font = new Font("Khmer UI", 12); var text = "សួស្តី"; // "Hello" e.Graphics.DrawString(text, font, Brushes.Black, 100, 100); } 回答1: mann, I

How to color individual characters and maintain proper spacing / kerning / alignment?

孤街浪徒 提交于 2020-01-21 15:28:40
问题 I want to use Graphics.DrawString to draw characters using individual colors. The problem is that each time I call DrawString, I have to know where to position it (either using a Point or a Rectangle) relative to the other characters. This is almost possible when taking into account the kerning and wrapping that happens when you use DrawString in a rectangle with a StringFormat. The StringFormat is important to specify alignment, wrapping, trimming, etc. Ideally I'd be able to tell DrawString

Popping up a TextBox on mouse click over a PictureBox for adding custom note to picture

隐身守侯 提交于 2020-01-14 04:24:05
问题 In my C# winforms application, I have a picturebox which some bitmap images can be loaded into it. What I want to do is if user clicks somewhere within picturebox, at the mouse location a small textbox will be appeared and user can add a custom text (note) to the picture. I know how to write a string into a bitmap file, but I couldnt find a way to POP UP a textbox at mouse location, and automaticly add the text to the image when user wrote something and hit enter key. How this textbox and its

Drawing “transparent” text via C# Graphics, but in a way that it turns the drawn text to be “missing” so it's transparent in the resulting image

纵然是瞬间 提交于 2020-01-05 02:52:25
问题 I am looking to draw a string on a DC (Graphics - I am using C#) - but I want the drawn text to be "deleted" from the image so that what's left is essentially a cut-out of the text. If I was to DrawString with a transparent brush obviously nothing would have happened. Is there a way of drawing something like that, or do I need to use 2 DCs and BitBlt with some combination of NOTs or XOR or whatever (I did similar things years ago, but was wondering if there's an easiery way)? 回答1: You could

Drawing “transparent” text via C# Graphics, but in a way that it turns the drawn text to be “missing” so it's transparent in the resulting image

*爱你&永不变心* 提交于 2020-01-05 02:52:06
问题 I am looking to draw a string on a DC (Graphics - I am using C#) - but I want the drawn text to be "deleted" from the image so that what's left is essentially a cut-out of the text. If I was to DrawString with a transparent brush obviously nothing would have happened. Is there a way of drawing something like that, or do I need to use 2 DCs and BitBlt with some combination of NOTs or XOR or whatever (I did similar things years ago, but was wondering if there's an easiery way)? 回答1: You could

Determining the number of lines in a text string?

爷,独闯天下 提交于 2020-01-03 17:22:21
问题 As part of a printing class, I want to be able to print long strings over multiple pages, but I don't know how to calculate the height of the entire string, which I will determine by first counting the number of lines in my string. I know I can count the number of line breaks, but I am also using word-wrap, so line breaks will be added whenever a line goes on past the width of the page. So I suppose I could count the number of line breaks, and figure out the width of each line, and figure out

Graphics.DrawString() vs TextRenderer.DrawText()

一世执手 提交于 2020-01-02 03:03:38
问题 I am confused about these two methods. My understanding is that Graphics.DrawString() uses GDI+ and is a graphics-based implementation, while TextRenderer.DrawString() uses GDI and allows a large range of fonts and supports unicode. My issue is when I attempt to print decimal-based numbers as percentages to a printer. My research leads me to believe that TextRenderer is a better way to go. However, MSDN advises, "The DrawText methods of TextRenderer are not supported for printing. You should

Graphics.DrawString() vs TextRenderer.DrawText()

我只是一个虾纸丫 提交于 2020-01-02 03:03:12
问题 I am confused about these two methods. My understanding is that Graphics.DrawString() uses GDI+ and is a graphics-based implementation, while TextRenderer.DrawString() uses GDI and allows a large range of fonts and supports unicode. My issue is when I attempt to print decimal-based numbers as percentages to a printer. My research leads me to believe that TextRenderer is a better way to go. However, MSDN advises, "The DrawText methods of TextRenderer are not supported for printing. You should

tooltip text erases panel drawing in java

痞子三分冷 提交于 2019-12-24 00:59:54
问题 I have a JPanel on which some drawing is performed using paintComponent method and after that when ever a user clicks on the JPanel a string is drawn (or any drawing) on it and as the user moves mouse over the JPanel it shows the coordinates in the tooltip of the JPanel . 1) The problem is that when the tooltip comes over the drawn string it erases it but this tooltiptext has no erasing effect on the drawing part which I performed in paintComponent method. I am not able to understand that why