VS 2008 Equalize Size of Lines in RichtextBox-VBForums
Results 1 to 17 of 17

Thread: Equalize Size of Lines in RichtextBox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Unhappy 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.

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    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:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object,
    4.                               ByVal e As System.EventArgs) Handles Button1.Click
    5.  
    6.         Dim longest As Integer = Me.RichTextBox1.Lines.OrderByDescending(Function(s) s.Length)(0).Length
    7.  
    8.         For Each line In Me.RichTextBox1.Lines
    9.             Dim difference As Integer = longest - line.Length
    10.             Dim n As Integer
    11.             While n < difference
    12.                 If Not line.Length = longest Then
    13.                     ' Handle here
    14.                 End If
    15.                 n += 1
    16.             End While
    17.         Next
    18.  
    19.     End Sub
    20. End Class

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    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.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    8,915

    Re: Equalize Size of Lines in RichtextBox

    Take a look at MeasureString.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- SerialPort Answer

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein
    "They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety." Benjamin Franklin
    "It is not all that I know that is the problem, it is all I think I do that is."

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Equalize Size of Lines in RichtextBox

    Maybe you should of stated this to begin with

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    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!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by dunfiddlin View Post
    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

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by dbasnett View Post
    Take a look at MeasureString.
    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

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    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!

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by dunfiddlin View Post
    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.

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by hackerspk View Post
    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!

    Name:  a.png
Views: 162
Size:  18.5 KB
    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!

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by dunfiddlin View Post
    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!

    Name:  a.png
Views: 162
Size:  18.5 KB
    Ha Ha Ha. I am developing a much complex application. It is an open source RichTextEditor.
    Name:  main.png
Views: 217
Size:  97.1 KB

  13. #13
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    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!

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by dunfiddlin View Post
    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.

  15. #15
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    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!

  16. #16
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    4,948

    Re: Equalize Size of Lines in RichtextBox

    Impressive knowledge of Poetry dunfiddlin

  17. #17
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Equalize Size of Lines in RichtextBox

    Quote Originally Posted by ident View Post
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.