| |

VerySource

 Forgot password?
 Register
Search
View: 587|Reply: 3

Master help, how to control the shape and size of the font?

[Copy link]

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-2-15 10:00:01
| Show all posts |Read mode
How to use the Draw method to control the size and shape of the word, let it automatically fill a rectangle I give.
Reply

Use magic Report

0

Threads

15

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-19 07:15:01
| Show all posts
private void button1_Click (object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics ();
            SizeF MyFontSize = SizeF.Empty;
            Rectangle MyRect = new Rectangle (0, 0, 200, 100);
            Font MyFont = new Font ("Arial", 100);

            string str = "Where to write qweqwewqewqeqwe?";
            MyFontSize = g.MeasureString ("String to draw ...", MyFont);


            while (MyFontSize.Width> MyRect.Width ||

            MyFontSize.Height> MyRect.Height)
            {

                MyFont = new Font ("Arial", (MyFont.Size-.01F));


                MyFontSize = g.MeasureString (str, MyFont);
            }
           
            g.DrawRectangle (Pens.Black, 0,0, MyFontSize.Width, MyFontSize.Height);
            
            g.DrawString (str, MyFont, Brushes.Black, new PointF (0, 0));

        }
Fill a rectangle completely.
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

 Author| Post time: 2020-5-17 08:15:02
| Show all posts
starsport

Your method is just to reduce the unit length

What if you want to fill a 100 * 200 random rectangle?
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

 Author| Post time: 2020-5-17 21:00:02
| Show all posts
I mean write only one word, so that the height and width of the word just fill a rectangle given at random
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list