-
Dec 11th, 2018, 09:49 AM
#1
Thread Starter
Frenzied Member
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:
If e.Graphics.MeasureString(ProductName, RegularFont).Width > 100 Then DrawRect.Height = 40 'how should i specifiy that the text should be wrapped Else DrawFormat.FormatFlags = StringFormatFlags.NoWrap DrawRect.Height = 20 End If 'Other values after product Name such as qty,rate should not be wrapped...
TIA
-
Dec 11th, 2018, 07:10 PM
#2
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.
-
Dec 12th, 2018, 02:27 PM
#3
Thread Starter
Frenzied Member
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:
For Each r As DataGridViewRow In Me.ItemsGrid.Rows DrawFormat.FormatFlags = StringFormatFlags.NoWrap DrawRect.Width = 100 ColId = Me.GetItemColNo("ProductName") ProductName = CStr(r.Cells(ColId).Value) If e.Graphics.MeasureString(ProductName, RegularFont).Width > 100 Then DrawRect.Height = 40 ' DrawFormat.FormatFlags = StringFormatFlags.NoWrap Else DrawFormat.FormatFlags = StringFormatFlags.NoWrap DrawRect.Height = 20 End If e.Graphics.DrawString(CStr(r.Cells(ColId).Value), RegularFont, Brushes.Black, DrawRect, DrawFormat) 'Drawing Quantity DrawRect.X += DrawRect.Width DrawRect.Width = 60 DrawFormat.Alignment = StringAlignment.Far ColId = Me.GetItemColNo("Qty") e.Graphics.DrawString(CStr(r.Cells(ColId).Value), RegularFont, Brushes.Black, DrawRect, DrawFormat) DrawRect.X += DrawRect.Width 'similarly drawing other elements Loop
-
Dec 12th, 2018, 02:54 PM
#4
Re: Remove StringFormatFlag while printing
DrawFormat.FormatFlags = 0?
-
Dec 12th, 2018, 05:38 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|