Displaying Windows Form as a String

For Displaying Windows Form as a STRING we need to override the On Paint () Method as follows…
  • Namespace Required:         using System.Drawing.Drawing2D;
  • First declare a new Object of GraphicsPath.
             
              GraphicsPath shape = new GraphicsPath();
  •           
  • To add String to ‘shape’ we required…
      • string s                    :        The System.String to add
      • FontFamily family     :        Name of the font with which the Text is drawn
      • int style                    :        FontStyle enumeration represents style about the                                                  text (bold, italic, and so on). This must be cast as an integer
      • float emSize             :        height of square box that bounds the character
      • Point origin                     :        Represents the point where the text starts
      • StringFormat format        :        Specifies text formatting information

       
  • After this we need reset the Region Path of Current Windows Forms to be displayed.
Code Sample:
          protected override void  OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
             GraphicsPath shape = new GraphicsPath();

             shape.AddString(“Immortal”, new FontFamily(“Microsoft Sans Serif”),
                                      2, 50.2F, new Point(0, 0), StringFormat.GenericTypographic);
                       
            this.Region = new System.Drawing.Region(shape);
        }


Intended Result:




Regards,
Mayur Dighe
http://ImmortalDotNet.blogspot.com
http://MayurDighe.wordpress.com