[C#] Drawing rects and text

So i’m messing around with drawing rectangles and text to the screen. The rects are pretty straightforward but the text is trickier.

Heres an example of what i’ve got so far:

private void DrawText(/*Text text*/) {
            float textx = Screen.Resolution.Width / 2f;
            float texty = Screen.Resolution.Height / 2f;

            DrawRect(.5f,.5f,.02f,.02f,250,50,50,200);

            BeginTextCommandDisplayText("STRING");
            AddTextComponentString("text1");
            SetTextScale(1f, .5f);
            SetTextCentre(true);
            EndTextCommandDisplayText(.5f, .5f);

            Text text = new Text("text2", new PointF(textx, texty), .5f);
            text.Alignment = Alignment.Center;
            text.Draw();
        }

Result from example code

So the text ends up being off by quite a bit. Is there a simpler way to draw text? Is there a good way to draw text relative to a rect? And what does the text scale relate to? Like if i have a rect with a height of 0.1, what what scale would go with that?

Anyone who has figured this stuff out and want to share, it would be appreciated, thanks!

DrawRect() always draws from the center x/y position you specify, then it extends width/2 and height/2 in all directions. Text however, is drawn/aligned from the very top left of the text string. So you’d have to draw it at the same coords of the rect, but then move it over by -(width/2) and `-(height/2) (the width/height of the rect) to get it to show up in the top left corner of the rect if I’m not mistaking.

The issue i still have is how to relate the size of the text to the size of a box. Like if i have a rect with height 0.1, how do i get text that matches that size? I can obviously test different values and see what works but i’m unsure how that would be affected by different resolutions. Sadly the text size/scale doesn’t use the same kind of scale that the rect uses it seems.