Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class frmSOTest1036 : Form
- {
- public frmSOTest1036()
- {
- InitializeComponent();
- this.ResizeRedraw = true;
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- Font font = new Font("Century Gothic", 18F, FontStyle.Bold, GraphicsUnit.Point);
- string demo = "[Emergency 123]";
- StringFormat fmtTrimmed = new StringFormat(StringFormat.GenericTypographic) {
- Alignment = StringAlignment.Near,
- LineAlignment = StringAlignment.Near,
- Trimming = StringTrimming.EllipsisCharacter,
- };
- StringFormat fmtNotTrimmed = new StringFormat(StringFormat.GenericTypographic) {
- Alignment = StringAlignment.Center,
- LineAlignment = StringAlignment.Near,
- };
- try {
- Rectangle boundsHeader = new Rectangle(10, 10, this.ClientSize.Width - 20, (int)font.GetHeight() + 8);
- SizeF textSize = e.Graphics.MeasureString(demo, font, boundsHeader.Size, fmtNotTrimmed);
- boundsHeader.Inflate(1, 1);
- e.Graphics.DrawRectangle(Pens.Blue, boundsHeader);
- float textCenterBounds = (boundsHeader.Width - textSize.Width) / 2;
- e.Graphics.DrawRectangle(Pens.Green, boundsHeader.X + textCenterBounds, boundsHeader.Y, textSize.Width, textSize.Height);
- e.Graphics.DrawString(demo, font, Brushes.Black, boundsHeader, fmtNotTrimmed);
- RectangleF boundsLeft = new RectangleF(boundsHeader.X, boundsHeader.Y, textCenterBounds, boundsHeader.Height);
- SizeF sizeLeft = e.Graphics.MeasureString(demo, font, boundsLeft.Size, fmtTrimmed);
- e.Graphics.DrawRectangle(Pens.Red, boundsLeft.X, boundsLeft.Y, boundsLeft.Width, textSize.Height);
- e.Graphics.DrawString(demo, font, Brushes.Black, boundsLeft, fmtTrimmed);
- }
- finally {
- font.Dispose();
- fmtTrimmed.Dispose();
- fmtNotTrimmed.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement