Opt In (Do Not Edit Here)

Aug 31, 2011

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:



About The Author :

Freelancer and IT Engineer
Softwares Developed by Mayur Dighe ImmortalDotNet.WordPress.com

0 comments :

All Rights Reserved. 2014 Copyright SIMPLITONA

Powered By Blogger | Published By Gooyaabi Templates Designed By : BloggerMotion

Top