Drawstring?
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
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
i just want to split the line that has more then 70 length of text
anyone?
Thanks
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 all
problem is that it split almost every word :(fnt = 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
i just want to split the line that has more then 70 length of text
anyone?
Thanks
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
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:

I did a bit of searching and found this function that may help point you in the right direction:
Code: Select all
Hope it helps private 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);
}
}

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
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?
also tried:
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 all
if i use this
Dim 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)
Code: Select all
it seems it cut off the string from the bottom lol 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)
also tried:
Code: Select all
but it seems it shows 2 lines of string but one of the strings on the previous line don't show the completed string :( 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)
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
Where or on what are you drawing these strings. Can you show us a picture or something?
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
just to print a page
Edit:
We have finally found the solution
we played with the code and come up with this
Thanks for the support ;)
Edit:
We have finally found the solution
we played with the code and come up with this
Code: Select all
and seems it did the trickreplaceDesc = 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)
Thanks for the support ;)
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023