Page 1 of 1
Drawstring?
Posted: Fri Jan 13, 2017 12:24 pm
by Dummy1912
Hello,
after a long search i didn't found any solution
can somebody helpme to split the long text to show at 2 lines
only when its to large
Code: Select allfnt = New Font("Arial", 7)
Dim descSize As SizeF = e.Graphics.MeasureString(tr(i).trDescr, fnt)
Dim replaceDesc As String
replaceDesc = tr(i).trDescr
replaceDesc = Strings.Replace(replaceDesc, " ", vbCrLf) 'example from google
If replaceDesc.Length > 70 Then
e.Graphics.DrawString(replaceDesc , fnt, Brushes.Black, (sSize.Width * 26 + sPoint.X) - (strSize.Width + sSize.Width * 26) / 80, (sSize.Height / 5 + sPoint.Y + 200), SF)
Else
e.Graphics.DrawString(tr(i).trDescr, fnt, Brushes.Black, (sSize.Width * 26 + sPoint.X) - (strSize.Width + sSize.Width * 26) / 80, (sSize.Height / 5 + sPoint.Y + 200), SF)
End If
problem is that it split almost every word :(
i just want to split the line that has more then 70 length of text
anyone?
Thanks
Re: Drawstring?
Posted: Fri Jan 13, 2017 2:44 pm
by CodenStuff
I found this annoying to do when using drawstring myself in the past and I'm still not sure how to do it in a fool proof way.
I did a bit of searching and found this function that may help point you in the right direction:
Code: Select allprivate void panel1_Paint(object sender, PaintEventArgs e)
{
string header2 = "This is a much, much longer Header";
string description = "This is a description of the header.";
RectangleF header2Rect = new RectangleF();
using (Font useFont = new Font("Gotham Medium", 28, FontStyle.Bold))
{
header2Rect.Location = new Point(30, 105);
header2Rect.Size = new Size(600, ((int)e.Graphics.MeasureString(header2, useFont, 600, StringFormat.GenericTypographic).Height));
e.Graphics.DrawString(header2, useFont, Brushes.Black, header2Rect);
}
RectangleF descrRect = new RectangleF();
using (Font useFont = new Font("Gotham Medium", 28, FontStyle.Italic))
{
descrRect.Location = new Point(30, (int)header2Rect.Bottom);
descrRect.Size = new Size(600, ((int)e.Graphics.MeasureString(description, useFont, 600, StringFormat.GenericTypographic).Height));
e.Graphics.DrawString(description.ToLower(), useFont, SystemBrushes.WindowText, descrRect);
}
}
Hope it helps
Re: Drawstring?
Posted: Fri Jan 13, 2017 3:43 pm
by Dummy1912
yea i found this also
but didn't worked what i needed :(
i didn't get it at the location i wanted my text to show
or didn't cut the text or even showed it completed.
sad to say i also find it annoying
Edit:
i did try this and seems it cut the text but don't show the completed string :( at the second line
any ideas?
Code: Select allDim descSize As SizeF = e.Graphics.MeasureString(tr(i).trDescr, fnt)
Dim Rectf As RectangleF = New Rectangle(sSize.Width * 25.2 + sPoint.X - sSize.Width / 2, sSize.Height / 5 + sPoint.Y + 200, descSize.Width / 2, sSize.Height)
e.Graphics.DrawString(tr(i).trDescr, fnt, Brushes.Black, Rectf, SF)
if i use this
Code: Select all Dim Rectf As RectangleF = New Rectangle(sSize.Width * 25.2 + sPoint.X - sSize.Width / 2, sSize.Height / 5 + sPoint.Y + 200, descSize.Width / 2, descSize.Height / 2)
it seems it cut off the string from the bottom lol
also tried:
Code: Select all Dim Rectf As RectangleF = New Rectangle(sSize.Width * 25.2 + sPoint.X - sSize.Width / 2, sSize.Height / 5 + sPoint.Y + 200, descSize.Width - sPoint.X, sSize.Height)
but it seems it shows 2 lines of string but one of the strings on the previous line don't show the completed string :(
Re: Drawstring?
Posted: Sat Jan 14, 2017 11:59 am
by CodenStuff
Where or on what are you drawing these strings. Can you show us a picture or something?
Re: Drawstring?
Posted: Sat Jan 14, 2017 3:05 pm
by Dummy1912
just to print a page
Edit:
We have finally found the solution
we played with the code and come up with this
Code: Select allreplaceDesc = Strings.Replace(replaceDesc, vbNewLine, " ")
Dim Rectf As RectangleF = New Rectangle(sSize.Width * 25.2 + sPoint.X - sSize.Width / 2, sSize.Height / 5 + sPoint.Y + 200, descSize.Width - sPoint.X - 95, sSize.Height + 5)
e.Graphics.DrawString(replaceDesc, fnt, Brushes.Black, Rectf, SF)
and seems it did the trick
Thanks for the support ;)