Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Mindcracker MVP Summit 2012
Search :       Advanced Search »
Home » GDI+ and Graphics » The FormatFlags Property in GDI+

The FormatFlags Property in GDI+

In this article I will explain about the FormatFlags Property in GDI+.

Author Rank :
Page Views : 1795
Downloads : 16
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
FormatFlagPropertyGDI+.zip
 
 
Mindcracker MVP Summit 2012
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


The FormatFlags property is useful when an application needs to draw text strings in different layouts- such as drawing vertical text. FormatFlags takes a value of the StringFormatFlags enumeration. Table 5.11 describes the members of the StringFormatFlags enumeration.

Note: An application can apply more than one StringFormatFlags member by using bitwise combinations.

As Listing 5.11 shows, our sample code draws two strings. One string is drawn from right to left, and the other is vertical. Using FormatFlags is pretty simple. An application creates a StringFormat object in the DrawString method. Note that an application can use more than one instance of FormatFlags for the same StringFormat object.

TABLE 5.11: StringFormatFlags members

Member

Description

DirectionRightToLeft

Draws text right to left in a given rectangle using the DrawString method.

DirectionVertical

Draws vertical text in a given rectangle using the DrawString method. The default alignment is left (use the Alignment property to change the text alignment).

DisplayFormatControl

Causes control characters such as the paragraph mark to be shown in the output with a representative glyph.

FitBlackBox

Specifies that no part of any glyph will overhang the bounding rectangle.

LineLimit

Specifies that only complete lines will be laid out in the formatting rectangle.

MeasureTrailingSpaces

By default, the boundary rectangle returned by the MeaureString method excludes any space at the end of each line. Set this flag to include that space in the measurement.

NoClip

By default, clipping is on, which means that any text outside of the formatting rectangle is not displayed. NoClip disable clipping.

NoFontFallback

By default, if the specified font is not found, an alternative font will be used. NoFontFallback disables that option and displays an open square for the missing character(s).

NoWrap

By default, wrapping is on. NoWrap disable wrapping.

LISTING 5.11: Using FormatFlags to format string text

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Public Class Form1

    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

        'Create graphics object
        Dim g As Graphics = Me.CreateGraphics()

        'Create a rectangle
        Dim rect As New Rectangle(50, 50, 350, 250)

        'Create two StringFormat objects
        Dim strFormat1 As New StringFormat()
        Dim strFormat2 As New StringFormat()

        'Set format flags of StringFormat object
        'with direction right to left
        strFormat1.FormatFlags = StringFormatFlags.DirectionRightToLeft

        'Set direction vertical
        strFormat2.FormatFlags = StringFormatFlags.DirectionVertical
 
        'Set alignment
        strFormat2.Alignment = StringAlignment.Far

        'Draw rectangle
        g.DrawRectangle(New Pen(Color.Blue), rect)
        Dim str As String = "Horizontal Text: This is horizontal" & "text inside a rectangle"

        'Draw strings
        g.DrawString(str, New Font("Verdana", 10, FontStyle.Bold), New SolidBrush(Color.Green), rect, strFormat1)
        g.DrawString("Vertical: Text String", New Font("Arial", 14), New SolidBrush(Color.Red), rect, strFormat2)

        'Dispose of GDI+ objects
        g.Dispose()
    End Sub
End Class

Figure 5.16 shows the output from Listing 5.11. One text string is drawn from right to left (aligned right) in the drawing rectangle, and the other text string is drawn vertically on the left-hand side. An application can even use Alignment, Trimming, and other properties to align and trim text.

Note: Using the Alignment property will remove the effect of StringFormatFlags.DirectionRightToLeft;

Figure 5.16.gif

FIGURE 5.16: Using FormatFlags to draw vertical and right-to-left text

Conclusion


Hope the article would have helped you in understanding the FormatFlags Property in GDI+. Read other articles on GDI+ on the website.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Dinesh Beniwal
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.