DrawText question

Hello everyone, English is not my native language, so I used translation tools, I hope you can understand

In the following code, how do I draw the character where the first blue line is?

I tried many times, but I couldn’t figure out the rules

[code]dim image as Picture = new Picture(Canvas1.Width, Canvas1.Height)
dim g as Graphics = image.Graphics
g.DrawingColor = Color.White
g.FillRectangle(0,0,image.Width,image.Height)

g.FontName = “??”
g.FontSize = (96 /72) * 30
g.DrawingColor = Color.Red
g.DrawText(“Test”, 0, g.FontAscent)

dim font_width as Double = g.TextWidth(“Test”)
g.DrawingColor = Color.Blue
g.DrawLine(0, g.FontAscent, font_width, g.FontAscent)
g.DrawLine(0, 0, font_width, 0)

g.DrawingColor = Color.Orange
g.DrawLine(0, g.TextHeight, font_width, g.TextHeight)

g.DrawLine(0, g.TextHeight - g.FontAscent, font_width, g.TextHeight - g.FontAscent)
Canvas1.Backdrop = image[/code]

its possible that the font contains higher chars like

[code]Var tx As New TextShape
tx.FontName = “Arial”
tx.FontSize = 24
tx.x=0
tx.y=0
tx.FillColor = Color.Red
tx.Value = “ABCDEFGHIJKLMNOPQRSTUVWXYZ!$%&/\()=?^y|qg*±#~” + Chr(34)
tx.VerticalAlignment = TextShape.Alignment.Top
tx.HorizontalAlignment = TextShape.Alignment.Left

g.DrawObject(tx)[/code]

Is this a question about how to draw in the menubar / toolbar area rather than the window itself?

[quote=492120:@Markus Rauch]its possible that the font contains higher chars like ÖÄÜ

[code]Var tx As New TextShape
tx.FontName = “Arial”
tx.FontSize = 24
tx.x=0
tx.y=0
tx.FillColor = Color.Red
tx.Value = “ABCDEFGHIJKLMNOPQRSTUVWXYZ!§$%&/\()=?´^°y|ÖÄÜqgß*±#~” + Chr(34)
tx.VerticalAlignment = TextShape.Alignment.Top
tx.HorizontalAlignment = TextShape.Alignment.Left

g.DrawObject(tx)[/code][/quote]

Thank you, but it seems that the problem has not been solved. Let me draw it in your way. The text is still quite far from the top. Oddly enough, I’m using c# to implement the same code, but it’s just not the same as xojo.

c# code

Bitmap image = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics g = Graphics.FromImage(image); Pen p = new Pen(Color.Black); g.DrawString("Test", new Font("Arial", 24), p.Brush, 0, 0); pictureBox1.Image = image;

xojo code

[code]dim image as Picture = new Picture(Canvas1.Width, Canvas1.Height)
dim g as Graphics = image.Graphics

Var tx As New TextShape
tx.FontName = “Arial”
tx.FontSize = 96 /72 * 24
tx.x=0
tx.y=0
tx.FillColor = Color.Black
tx.Value = “Test”
tx.VerticalAlignment = TextShape.Alignment.Top
tx.HorizontalAlignment = TextShape.Alignment.Left
g.DrawObject(tx)

Canvas1.Backdrop = image[/code]

60/5000
The display is completely different. For whatever reason, the characters drawn in c# have left margins and the top margins are shorter than in xojo. And c# looks a little thicker, right?

Hello, I used the translator, so I may not have communicated my question well. I don’t quite understand why xojo draws things differently from other languages for the same code.

check the font unit, i guess the c# unit was in points? then xojo should be tx.FontSize = 24
you can also change the fontunit in TextShape

your pictureBox1 in c# is without border? can you gave it a background color to see that inner start at left,top?