Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I thinks this way is work , please you try.</p> <pre><code>List&lt;RectangleF&gt; rects = new List&lt;RectangleF&gt;(); private void Form1_Paint(object sender, PaintEventArgs e) { ////////////////////Not Set baseLine //baseline e.Graphics.DrawLine(Pens.Red , new Point(100,200),new Point(800,200)); //words Point point = new Point(100,100); e.Graphics.DrawString("hello world", new Font("Times", 30), Brushes.Black, point); RectangleF rectangleF = new RectangleF(point, e.Graphics.MeasureString("hello world", new Font("Times", 30))); e.Graphics.DrawRectangle(Pens.Green,rectangleF.X ,rectangleF.Y , rectangleF.Width , rectangleF.Height); rects.Add(rectangleF); point = new Point(400, 100); e.Graphics.DrawString("hello world", new Font("Arial", 40), Brushes.Black, point); rectangleF = new RectangleF(point, e.Graphics.MeasureString("hello world", new Font("Arial", 40))); e.Graphics.DrawRectangle(Pens.Green, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); rects.Add(rectangleF); point = new Point(800, 100); e.Graphics.DrawString("hello world", new Font("Courier", 20), Brushes.Black, point); rectangleF = new RectangleF(point, e.Graphics.MeasureString("hello world", new Font("Courier", 20))); e.Graphics.DrawRectangle(Pens.Green, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); rects.Add(rectangleF); ///////////////////SetBaseLine///////////////////////////// var maxHeight = GetMaxHeight(); /////////////////// //baseLine e.Graphics.DrawLine(Pens.Pink, new Point(100, (int) (400 + maxHeight / 2)), new Point(800, (int) (400 + maxHeight / 2))); StringFormat stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; //words point = new Point(100, 400); rectangleF = new RectangleF(point, e.Graphics.MeasureString("hello world", new Font("Times", 30))); e.Graphics.DrawString("hello world", new Font("Times", 30), Brushes.Black, new RectangleF(rectangleF.X ,rectangleF.Y , rectangleF.Width , maxHeight) , stringFormat); e.Graphics.DrawRectangle(Pens.Green, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); rects.Add(rectangleF); point = new Point(400, 400); rectangleF = new RectangleF(point, e.Graphics.MeasureString("hello world", new Font("Arial", 40))); e.Graphics.DrawString("hello world", new Font("Arial", 40), Brushes.Black, new RectangleF(rectangleF.X, rectangleF.Y, rectangleF.Width, maxHeight), stringFormat); e.Graphics.DrawRectangle(Pens.Green, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); rects.Add(rectangleF); point = new Point(800, 400); rectangleF = new RectangleF(point, e.Graphics.MeasureString("hello world", new Font("Courier", 20))); e.Graphics.DrawString("hello world", new Font("Courier", 20), Brushes.Black, new RectangleF(rectangleF.X, rectangleF.Y, rectangleF.Width, maxHeight), stringFormat); e.Graphics.DrawRectangle(Pens.Green, rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height); rects.Add(rectangleF); } private float GetMaxHeight() { float temp = 0; foreach (RectangleF rectangleF in rects) if (rectangleF.Height &gt; temp) temp = rectangleF.Height; return temp; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload