Drawing text confusion.  
Author Message
Foolios





PostPosted: Visual C# General, Drawing text confusion. Top

private Font arialBold24 =
new Font("Arial", 24, FontStyle.Bold);

g.DrawString(arialBold24.Name, arialBold24,
Brushes.Blue, arialStart,0);

I see that g.DrawString is drawing text and I believe the text will be read as arial since that's the font's name. But my book doesn't have an example of how you would draw text that you specifically wanted to be drawn to the screen. How would you take g.DrawString(arialBold24.Name, arialBold24,
Brushes.Blue, arialStart,0);
to do that
Would it be something like g.DrawString("print this to screen", arialBold24,
Brushes.Blue, arialStart,0);

EDIT:
Well whatdya know, that's exactly right, hehe... OK, I still have a question though...
In my book it shows that I would need the following line to allow the form to handle events but if I take this Application.Run line out of the form load event handler, it still seems to work right. I don't understand why this is so and what it's purpose might have been.

private void Form1_Load(object sender, EventArgs e)
{
Application.Run( new Text() );

}

}

EDIT:
Ok, here's some practice I am doing that I am having problems with.

private Font myFont = new Font("Arial", 24, FontStyle.Bold);
int w = (int)g.MeasureString ("A big car", myFont).Width;
g.DrawString("A big car", myFont,
                              Brushes.Blue, 20, 20);
     g.DrawString(Form.ToString(w));

What I want to do is print the width of "A big car" to the screen. I am thinking I have to convert w to a string but I am having problems with the conversion. Thanks in advance for any assistance.

EDIT:
Ok, I think I have this further along but I am not getting a sensible result.
I've added:
 String h = w.ToString();
     g.DrawString(h, myFont, Brushes.Red, 50, 50);

But when I run the program the number 151 gets printed to the screen. I was thinking the result of the width of the leters in "A big car" would be 9. What happened

EDIT:
Ok, I've tried it this way too:
g.DrawString(w.ToString(), myFont, Brushes.Red, 50, 50);

I still get 151 as an answer drawn on the form. I just don't understand why I am getting this number instead of 9.


Visual C#3  
 
 
Markku Behm





PostPosted: Visual C# General, Drawing text confusion. Top

Hi

That width value is pixels in the screen.

Yours Markku


 
 
Foolios





PostPosted: Visual C# General, Drawing text confusion. Top

Thank you sooo much for clearing that up for me!