PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 Remove StringFormatFlag while printing-VBForums
Results 1 to 5 of 5

Thread: Remove StringFormatFlag while printing

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,133

    Remove StringFormatFlag while printing

    Hello..
    I am printing an Invoice using PrintDocument.
    Basically what i want to do is , if e.Graphics.MeasureString(productname).width is >100 then it should be wrapped, else the text should not be wrapped

    I am using the following code, plz suggest me how should i remove the NoWrap StringFormatFlag

    vb Code:
    1. If e.Graphics.MeasureString(ProductName, RegularFont).Width > 100 Then
    2.     DrawRect.Height = 40
    3.    'how should i specifiy that the text should be wrapped
    4.  
    5. Else
    6.      DrawFormat.FormatFlags = StringFormatFlags.NoWrap
    7.      DrawRect.Height = 20
    8. End If
    9.  
    10. 'Other values after product Name such as qty,rate should not be wrapped...

    TIA

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,947

    Re: Remove StringFormatFlag while printing

    You don't have to do anything. Wrapping is the default if you specify a Rectangle when calling DrawString. In fact, I'm not sure that there's any point to what you're doing at all. If you just specify a Rectangle that is 100 wide and the maximum height you want to display text in then the text will be drawn on one line if it's not too wide and wrapped if it is. You would only need to specify NoWrap if you want the text to be clipped if it gets too wide for the area you want to draw it in.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,133

    Re: Remove StringFormatFlag while printing

    Sorry I should i have given the full information.

    Actually my code is in an For Loop, so say if the first item fits within 100 width, then its drawn using NoWrap, simultaneously other elements viz. qty and rate and drawn with NoWrap flag,

    now for second item whose product name width is greater than 100 , is also been drawn with NoWrap flag which is set in the first iteration. In this case i wish to remove the NoWrap flag

    vb Code:
    1. For Each r As DataGridViewRow In Me.ItemsGrid.Rows
    2.             DrawFormat.FormatFlags = StringFormatFlags.NoWrap
    3.          
    4.            DrawRect.Width = 100
    5.  
    6.             ColId = Me.GetItemColNo("ProductName")
    7.             ProductName = CStr(r.Cells(ColId).Value)
    8.  
    9.             If e.Graphics.MeasureString(ProductName, RegularFont).Width > 100 Then
    10.                 DrawRect.Height = 40
    11.                 '   DrawFormat.FormatFlags = StringFormatFlags.NoWrap
    12.             Else
    13.                 DrawFormat.FormatFlags = StringFormatFlags.NoWrap
    14.                 DrawRect.Height = 20
    15.             End If
    16.             e.Graphics.DrawString(CStr(r.Cells(ColId).Value), RegularFont, Brushes.Black, DrawRect, DrawFormat)
    17.          
    18.  
    19.            'Drawing Quantity
    20.             DrawRect.X += DrawRect.Width
    21.  
    22.             DrawRect.Width = 60
    23.             DrawFormat.Alignment = StringAlignment.Far
    24.             ColId = Me.GetItemColNo("Qty")
    25.             e.Graphics.DrawString(CStr(r.Cells(ColId).Value), RegularFont, Brushes.Black, DrawRect, DrawFormat)
    26.             DrawRect.X += DrawRect.Width
    27.  
    28. 'similarly drawing other elements
    29.  
    30. Loop

  4. #4
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    785

    Re: Remove StringFormatFlag while printing

    DrawFormat.FormatFlags = 0?

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,947

    Re: Remove StringFormatFlag while printing

    You don't have to remove anything. The documentation for the StringFormatFlags enumeration has a code example that shows creating one StringFormat object with common property values and then creating a second StringFormat from that, then setting different property values on each. You would just do the same. Create two StringFormat objects with the same property values otherwise, then set the FormatFlags on one of them to NoWrap. Choose which one to use in each case with an If...Else statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width