-
Jun 18th, 2013, 12:02 AM
#1
Thread Starter
Lively Member
Equalize Size of Lines in RichtextBox
I want to make a poetry writing application. I want every verse of a poem to be equal in size. e.g
Some love good some love bad
We all want something we never had
This should look like this by adding white spaces or something else.
HTML Code:
Some love good some love bad
We all want something we never had
I can justify the text in Richtextbox but how to check the size biggest line in Richtextbox selection and then equalize all lines according to that line.
Any help please.
-
Jun 18th, 2013, 05:37 AM
#2
Re: Equalize Size of Lines in RichtextBox
Interesting One. One my brain is not fully working on but might give you a start.
Something like
vb Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim longest As Integer = Me.RichTextBox1.Lines.OrderByDescending(Function(s) s.Length)(0).Length
For Each line In Me.RichTextBox1.Lines
Dim difference As Integer = longest - line.Length
Dim n As Integer
While n < difference
If Not line.Length = longest Then
' Handle here
End If
n += 1
End While
Next
End Sub
End Class
-
Jun 18th, 2013, 05:47 AM
#3
Thread Starter
Lively Member
Re: Equalize Size of Lines in RichtextBox
Thanks. But I am afraid it is not the real game. We cannot go with line.Length feature. Because there are words which occupy more space then some. For example: Q occupy more space then i. And in Persian script ے occupy more space then ا . There we need any other feature.
-
Jun 18th, 2013, 06:00 AM
#4
Re: Equalize Size of Lines in RichtextBox
Take a look at MeasureString.
-
Jun 18th, 2013, 06:19 AM
#5
Re: Equalize Size of Lines in RichtextBox
Maybe you should of stated this to begin with
-
Jun 18th, 2013, 11:46 AM
#6
Re: Equalize Size of Lines in RichtextBox
I can justify the text in Richtextbox
Using what method?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 19th, 2013, 02:19 AM
#7
Thread Starter
Lively Member
Re: Equalize Size of Lines in RichtextBox
Originally Posted by dunfiddlin
Using what method?
I am using an extended richtextbox with some modification. Last year I posted its source here:
http://www.vbforums.com/showthread.p...-control-usage
-
Jun 19th, 2013, 03:30 AM
#8
Thread Starter
Lively Member
Re: Equalize Size of Lines in RichtextBox
Originally Posted by dbasnett
It is a pretty good one. I can now get the right measurement of lines. Following code give me the measurement of biggest line. Then only thing I left with to equal the size of each line. I think I can achieve this by increasing the size of white spaces while checking the measurement of current line at the same time. But now the problem is if I increase the size of white space then how can I measure the size of string again with multiple font sizes. Because in beginning we can set a specific font for our measurement.
Code:
For Each line In RichTextBox1.Lines
Dim textSize As Size = TextRenderer.MeasureText(line , RichTextBox1.Font)
If textSize.Width > biggest Then
biggest = textSize.Width
End If
count = count + 1
Next
-
Jun 19th, 2013, 05:19 PM
#9
Re: Equalize Size of Lines in RichtextBox
Would it not be easier just to change the width of the textbox to that of the longest line and justify?
By the way the extended RTB and VS 2010 don't get along unfortunately (the second time this week that I've run into problems with the older interop!) so I'm afraid I gave up on trying it.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 19th, 2013, 06:59 PM
#10
Thread Starter
Lively Member
Re: Equalize Size of Lines in RichtextBox
Originally Posted by dunfiddlin
Would it not be easier just to change the width of the textbox to that of the longest line and justify?
By the way the extended RTB and VS 2010 don't get along unfortunately (the second time this week that I've run into problems with the older interop!) so I'm afraid I gave up on trying it.
Unfortunately I cannot change the width RTB.
-
Jun 19th, 2013, 08:57 PM
#11
Re: Equalize Size of Lines in RichtextBox
Originally Posted by hackerspk
Unfortunately I cannot change the width RTB.
Of course you can, Malcolm! (Blimey that takes me back - old British cold remedy ad - ah, nostalgia's not what it used to be.)
Now where was I? Oh yeah. Use a borderless RTB on a white panel and you can change the width at will and nobody will ever know!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 20th, 2013, 05:17 AM
#12
Thread Starter
Lively Member
Re: Equalize Size of Lines in RichtextBox
Originally Posted by dunfiddlin
Of course you can, Malcolm! (Blimey that takes me back - old British cold remedy ad - ah, nostalgia's not what it used to be.)
Now where was I? Oh yeah. Use a borderless RTB on a white panel and you can change the width at will and nobody will ever know!
Ha Ha Ha. I am developing a much complex application. It is an open source RichTextEditor.
-
Jun 20th, 2013, 11:43 AM
#13
Re: Equalize Size of Lines in RichtextBox
Ok. But Then I don't really seee the logic of justifying for poetry anyway. Consider The Rose by E. E. Cummings, a poet who liked to play with the structure of words on the page as well as the actual words ....
the rose
is dying the
lips of an old man murder
the petals
hush
mysteriously invisible mourners move
with prose faces and sobbing,garments
The symbol of the rose
motionless
with grieving feet and
wings
mounts
against the margins of steep song
a stallion swetneess ,the
lips of an old man murder
the petals.
Would you really want to stretch out 'hush' to the length of 'with prose faces and sobbing,garments' or introduce spacing into ',the' where there quite deliberately isn't any? I can't pretend that I am familiar with Urdu or Persian poetry but I would imagine that there must be some for whom typographical correctness is as important as the actual words?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 20th, 2013, 11:53 AM
#14
Thread Starter
Lively Member
Re: Equalize Size of Lines in RichtextBox
Originally Posted by dunfiddlin
Ok. But Then I don't really seee the logic of justifying for poetry anyway. Consider The Rose by E. E. Cummings, a poet who liked to play with the structure of words on the page as well as the actual words ....
the rose
is dying the
lips of an old man murder
the petals
hush
mysteriously invisible mourners move
with prose faces and sobbing,garments
The symbol of the rose
motionless
with grieving feet and
wings
mounts
against the margins of steep song
a stallion swetneess ,the
lips of an old man murder
the petals.
Would you really want to stretch out 'hush' to the length of 'with prose faces and sobbing,garments' or introduce spacing into ',the' where there quite deliberately isn't any? I can't pretend that I am familiar with Urdu or Persian poetry but I would imagine that there must be some for whom typographical correctness is as important as the actual words?
I don't really know about English literature very well. But Urdu literature has a specific type of poetry named "Ghazal" http://en.wikipedia.org/wiki/Ghazal.
This type is very popular in sub continent. Ghazal demands this type of settings. This specific type of poetry you posted is called "Nazam". In this type no settings are required at all.
-
Jun 20th, 2013, 12:15 PM
#15
Re: Equalize Size of Lines in RichtextBox
Ah yes, I see. But there are variations even within that, including a two column text with a bridging column at the end or regularly throughout the poem which are going to be even more difficult.
I'm wondering whether we have a case here of where a servant can't serve two masters and an all-purpose text editor is always going to struggle with the disciplines of something like Ghazal. At the very least you do need a way to define margins as it clearly isn't a one size fits all canvas for this kind of work and I can't help feeling that the easiest way to do that is still to resize the textbox, preferably automatically when in Ghazal mode, as it were. Using a panel behind for this would also make it simpler to deal with right, centre and left, alignments.
Anyway, such are my thoughts. Do what you will with them.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 20th, 2013, 12:35 PM
#16
Re: Equalize Size of Lines in RichtextBox
Impressive knowledge of Poetry dunfiddlin
-
Jun 20th, 2013, 12:39 PM
#17
Re: Equalize Size of Lines in RichtextBox
Originally Posted by ident
Impressive knowledge of Poetry dunfiddlin
Ah well. I'm not a pretty face! No, wait ....
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Tags for this Thread
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
|