Hi
I am trying to draw text in a panel. I want the width of the panel to
be fixed but the height to be determined by the number of lines the
text needs to cover in the panel. I also want to be able to specify
the linespacing for the text.
I have looked at the StringFormat class, MSDN stating:
"Encapsulates text layout information (such as alignment and line
spacing)..."
However there appears to be no property for setting the Line Spacing
of the text, and I cannot work out how to wrap it...
Private Sub DrawText(ByVal e As PaintEventArgs)
Dim Text As String
Dim I As Integer
For I = 1 To 20
Text &= "Sample Text"
If I < 20 Then Text &= " "
Next
Dim TextSize As PointF
Dim StringFormat As New StringFormat
e.Graphics.DrawString(Text, Font, New SolidBrush(Color.Black),
0, 0, StringFormat.GenericTypographic)
End Sub
Any help would be appreciated!
Cheers
Blu. 5 4312
Hi,
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim strOut As String = "This is my really really long line of
text to print on the screen"
Dim sf As New StringFormat
e.Graphics.DrawString(strOut, Me.Font, Brushes.Black, _
RectangleF.op_Implicit(Panel1.ClientRectangle), sf)
End Sub
Ken
-----------------
"BluDog" <ne**@nospam.bludog.net> wrote in message
news:0g********************************@4ax.com: Hi
I am trying to draw text in a panel. I want the width of the panel to be fixed but the height to be determined by the number of lines the text needs to cover in the panel. I also want to be able to specify the linespacing for the text.
I have looked at the StringFormat class, MSDN stating:
"Encapsulates text layout information (such as alignment and line spacing)..."
However there appears to be no property for setting the Line Spacing of the text, and I cannot work out how to wrap it...
Private Sub DrawText(ByVal e As PaintEventArgs)
Dim Text As String Dim I As Integer For I = 1 To 20 Text &= "Sample Text" If I < 20 Then Text &= " " Next
Dim TextSize As PointF Dim StringFormat As New StringFormat
e.Graphics.DrawString(Text, Font, New SolidBrush(Color.Black), 0, 0, StringFormat.GenericTypographic)
End Sub
Any help would be appreciated!
Cheers
Blu.
--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus ( http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.0 - Release Date: 6/12/2004 "Encapsulates text layout information (such as alignment and line spacing)..."
However there appears to be no property for setting the Line Spacing of the text, and I cannot work out how to wrap it...
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim strOut As String = "This is my really really long line of text to print on the screen" Dim sf As New StringFormat
e.Graphics.DrawString(strOut, Me.Font, Brushes.Black, _ RectangleF.op_Implicit(Panel1.ClientRectangle), sf)
End Sub
Ken, thanks for this, it is pretty much where I am, however it is not
a solution to the line spacing problem.
Cheers
Tom
u need this:
dim g as graphics
dim path as ne graphicpath
path.AddString()
set world transform
dim rectBound as rectanglaF= path.GetBound()
dim aptDist() as PointF= new point(0,0), .....}
g.transform= new Matrix(rectbound,aptDist))
then fill path
g.Fillapth(new solidbrush(colour,path)
or u can do path.AddString.
u can get help from msdn from microsoft's website.
regards
BluDog wrote: Hi
I am trying to draw text in a panel. I want the width of the panel to be fixed but the height to be determined by the number of lines the text needs to cover in the panel. I also want to be able to specify the linespacing for the text.
I have looked at the StringFormat class, MSDN stating:
"Encapsulates text layout information (such as alignment and line spacing)..."
However there appears to be no property for setting the Line Spacing of the text, and I cannot work out how to wrap it...
Private Sub DrawText(ByVal e As PaintEventArgs)
Dim Text As String Dim I As Integer For I = 1 To 20 Text &= "Sample Text" If I < 20 Then Text &= " " Next
Dim TextSize As PointF Dim StringFormat As New StringFormat
e.Graphics.DrawString(Text, Font, New SolidBrush(Color.Black), 0, 0, StringFormat.GenericTypographic)
End Sub
Any help would be appreciated!
Cheers
Blu.
BluDog wrote: However there appears to be no property for setting the Line Spacing of the text, and I cannot work out how to wrap it...
e.Graphics.DrawString(Text, Font, New SolidBrush(Color.Black), 0, 0, StringFormat.GenericTypographic)
dim ls as integer = LineHeight ' define the value as you wish
dim Lines() as string = split(Text,vbcrlf)
dim Y as integer = StartTop ' define the value as you wish
for i as integer = 0 to ubound(Lines)
e.Graphics.DrawString(Lines(i), Font, New SolidBrush(Color.Black),
0,Y, StringFormat.GenericTypographic)
y+=LineHeight
next
Hilbert
Thanks for your suggestion, the problem is there are no Line Feeds in
the string necessarily, therefore you cannot split it up in that
way... however i have tweeked it to find sensible line breaks and wrap
it manually:
Private LineHeight As Integer = 21
Private Format As StringFormat = StringFormat.GenericTypographic
Private SampleFont As Font = Font
Private Sub DrawText(SampleText as string, e As PaintEventArgs)
'Get the size of the panel the text is to be printed into
Dim PanelSize As New SizeF(SamplePanel.Width,
SamplePanel.Height)
'Split the text into an array of string
Dim Words() As String = SampleText.Split(" ")
'Loop through lines
Dim LineCount As Integer
Dim Line, TestLine As String
For Word As Integer = 0 To Words.Length - 1
TestLine = (Line & " " & Words(Word)).Trim
If e.Graphics.MeasureString(TestLine, SampleFont, New
PointF(3, 0), Format).Width > PanelSize.Width Then
e.Graphics.DrawString(Line, SampleFont, Brushes.Black,
3, LineCount * LineHeight, Format)
Line = ""
LineCount += 1
Word -= 1
ElseIf Word = Words.Length - 1 Then
e.Graphics.DrawString(TestLine, SampleFont,
Brushes.Black, 3, LineCount * LineHeight, Format)
LineCount += 1
Else
Line = TestLine
End If
Next
End Sub
Cheers
Blu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eric Lindsay |
last post by:
I've seen a page using display, and especially display table that did
some neat things with boxes, but basically it only worked with Mozilla
browsers. Fell over fairly badly with Opera and Safari...
|
by: David Lindgren |
last post by:
Hello!
I am using a thirdparty gridcontrol which has a bug in it. It consists of
that when setting a column to be right aligned it doesn't work as it should.
The column gets rightaligned, but...
|
by: Pam Ammond |
last post by:
I need the code to update the database when Save is clicked and a text field
has changed. This should be very easy since I used Microsoft's wizards for
the OleDBAdapter and OleDBConnection, and...
|
by: Arif Çimen |
last post by:
Hi to everybody,
I have chnged a button text in design mode. But After compiling and
executing the program
the text of the button do not change to new value.
Any Ideas?
Thaks for helps.
|
by: Lance Geeck |
last post by:
I have a simple form where I am using a dataset called Client. On the data
entry screen, there are name, address, city state and zip.
I have the fields bound to the dataset field. (Properties...
|
by: F. Michael Miller |
last post by:
I'd like to copy the listing of a directory (& sub directories) to a text
file in vb.net.
I'm looking for teh equivilant of the DOS command dir /s >
TargetFile.txt.
Thanks!
|
by: Andrew McKendrick |
last post by:
Hi,
I've noticed a bug in VB.NET (latest .NET Framework)...
- I have a TabControl on a form with several tabs.
- Each tab contains text boxes that are bound to fields in a data source...
|
by: mehdi_mousavi |
last post by:
Hi folks,
Consider a text containing 200 characters (more or less) including
and/or excluding the CR/LF within. I would like to compute the height
of this text whenever it's width is limited by X...
|
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= |
last post by:
Hello,
I know I sound like a one-note Johnny on this but I'm still looking for a
solution. I need to display characters coming in from a serial port or a
socket. I also need to be able to type...
|
by: JamesOo |
last post by:
I have the code below, but I need to make it searchable in query table,
below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |