Page 1 of 2 12 LastLast
Results 1 to 40 of 57

Thread: [RESOLVED] Justifying text

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Resolved [RESOLVED] Justifying text

    Hi,
    Over many days I've trolled through as many pages of FAQ as I thought relevant but haven't found a definitive answer as yet.

    It's the question of text justification within a Label. We currently have the 'Text Alignment' options of: -
    Left: Top, Middle or bottom. Likewise for Right and Centre. What we don't seem to have anywhere is an option for 'Justified' Text.

    The argument in most of the answers to similar questions is that it's not possible because it's controlled by the font. Like many others I'm using Microsoft's Visual Studio, in my case, the Express 2012 version. Microsoft also market the very successful 'Word' word processor, this product can select exactly the same set of widely available fonts, yet it can also use justified text with those same fonts, seemingly with ease, certainly with a single button click, and has been able to do so since the very first version.

    This being so, and I don't believe there'll be many who disagree with the paragraph above, I would've thought that an option would be possible in VB.NET to select justified text, or if not to select it, then at least produce it by an inbuilt function. Sadly I'm still looking without success.

    At one time, while I was still using version 2005, I started to build a subroutine to justify text, I've mapped out a 'look-up-list' for the widths of each keyboard character, and measured the widths of the several 'spacer' characters but this was very time consuming and I only did it for one specific font. By the time I'd done that at the time, the task of working out a algorithm to pack-out the individual spaces between words became too daunting, and, in view of my opinion stated above, it was shelved for a while in the expectation that such a function would become available soon and here I am several years further on asking the question. "How do we get justified text in a Label on a form" ?

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Justifying text

    I'd say that a Label isn't designed for the sort of text that you'd justify, but rather short descriptions to place next to input controls, and so on. If you have a large block of text to render then you should probably be using a different sort of control. Does a TextBox have a justify option? Placing one of those in a read-only mode is my usual method to display large blocks of text, on the few occasions I've needed to do so in WinForms.

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    I'd say that a Label isn't designed for the sort of text that you'd justify
    Yep your problem is the control your trying to use;

    Use a Textbox, set it to flat, set the back colour to the same as your form, set the border to nothing, and set enabled = false.

    Then it wont look like you using a Textbox BUT you will be able to left / right or centre justify the text.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Justifying text

    as already noted, the label is the wrong type of control: there is no need for justified text in a label.

    Justified text is used for readability of large quantities of text (as well as the serifs), and requires correct text block widths to work correctly. As such, most controls are not used for this type of application.

    I would think the RichTextBox would be the control to use if you need justified text (I'm not sure a TextBox has justified text as an option, as it's an input control, primarily).
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Justifying text

    I'm not sure a TextBox can justify text either, but an RTB should be able to. Make it flat, read-only and it should look just like a label, and you'll even get the added benefit of scrollbars if you need them.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by Evil_Giraffe View Post
    I'd say that a Label isn't designed for the sort of text that you'd justify, but rather short descriptions to place next to input controls, and so on. If you have a large block of text to render then you should probably be using a different sort of control. Does a TextBox have a justify option? Placing one of those in a read-only mode is my usual method to display large blocks of text, on the few occasions I've needed to do so in WinForms.
    Quote Originally Posted by NeedSomeAnswers View Post
    Yep your problem is the control your trying to use;

    Use a Textbox, set it to flat, set the back colour to the same as your form, set the border to nothing, and set enabled = false.

    Then it wont look like you using a Textbox BUT you will be able to left / right or centre justify the text.
    Thanks guys, I take the point about using a TextBox, but the problem still remains, in fact with a TextBox we get even less choice of Text Alignment, just Left, Right and Centre as NeedSomeAnswers says.

    That still doesn't answer the question though, just changes it from a label to a textbox. I know we can select from these three options, but I would like to be able to use 'Justify'. i.e. Have Both edges aligned.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  7. #7
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Justifying text

    Have you checked the RTB's options as tg suggested?

  8. #8

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by Evil_Giraffe View Post
    Have you checked the RTB's options as tg suggested?
    Yes, I've been trying RTB I've taken longer than you might expect because I get bogged down with trivial details... As in this case with the RTB, neither the Forecolor nor BackColor appear as selected. I've compromised on that, but as I say it wasted time.

    I think I've carefully looked at all the RTB properties as listed, and they seems to have no 'Text Alignment' options at all !!
    Neither do they allow me to use Pixel as a Font Unit, it seems to insist on Point which is a bit of a nuisance because I wish to be able to resize the form and the font size by the same factor, and as far as I can tell 'Point' isn't linear.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    take a look at this Extending RichTextbox

    In the article the guys specifically extends it to allow Justification.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  10. #10
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Justifying text

    Huh... I coulda sworn it did... a search showed that wasn't the case... BUT... I did find this in our codebank - http://www.vbforums.com/showthread.p...in-RichTextBox may it be of some use.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Justifying text

    Ungh... I came across that one too, but for some reason I thought we were looking for a VB6 solution here, so I skipped over it. I haven't had any coffee yet, can I blame that? Ignore my previous link too then, as it's a VB6 solution.

    what was I thinking?

    bleh.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by techgnome View Post
    Ungh... I came across that one too, but for some reason I thought we were looking for a VB6 solution here, so I skipped over it. I haven't had any coffee yet, can I blame that? Ignore my previous link too then, as it's a VB6 solution.

    what was I thinking?

    bleh.


    -tg
    Now he tells me !!!




    Actually, I'd seen it was for VB6 and was about to ask...

    Can it not be reworked for VB.NET ?

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  13. #13
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Justifying text

    WEll ,the one NSA dug up (which I meant to quote) is for .NET... so his is likely closer to what you want than what I posted.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by Poppa Mintin View Post
    I think I've carefully looked at all the RTB properties as listed, and they seems to have no 'Text Alignment' options at all !!
    Neither do they allow me to use Pixel as a Font Unit, it seems to insist on Point which is a bit of a nuisance because I wish to be able to resize the form and the font size by the same factor, and as far as I can tell 'Point' isn't linear.
    Poppa.
    I've done a little work on this and for anyone that may be interested: -

    I'm trying to code up a project which I thought I'd completed some time ago, with the idea of making the forms, which have to be printed out, adjustable in size so that they will display fully on a machine with a smaller screen.
    So, my basic premise is to read-in the height of the screen, divide it by the height of the original form height (subtract 10%) and use the result as a factor for adjusting the form size.

    When it comes to resizing text on resizeable forms (previously to enlarge them) I've always used 'Pixel' for the Font Size Unit, in the belief that a size of (say) 15 pixels would be 15 pixels high from the top of (Say) an upper case T, to the bottom of characters with descenders, (e.g. j or g). So I've figured that a factor of (Say) 0.75 would resize a character of 20 pixels high to one of 15 pixels high.

    This doesn't work when the font's Unit parameter is 'Read only' and set to 'Point'. But I've found that multiplying by the Factor Squared seems to give about the right result, with Arial Narrow anyway.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  15. #15

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by techgnome View Post
    WEll ,the one NSA dug up (which I meant to quote) is for .NET... so his is likely closer to what you want than what I posted.

    -tg
    That's true, but I know virtually nothing about C#.NET

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  16. #16
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Justifying text

    Quote Originally Posted by Poppa Mintin View Post
    That's true, but I know virtually nothing about C#.NET

    Poppa.
    You should really know about code converters.
    Here is an online one: http://converter.telerik.com/

  17. #17

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Thanks TnTinMN, I tried your suggestion... and I now have the VB version of that C code... discovering how to use it is my next task, but after spending the evening in the bar, I think it would be wisest to wait until the morning... Thanks for your help, I'm going to put that URL on my Bookmarks Bar. I thought I'd tried that before but since it's an on-line converter I don't believe I could've.

    Thanks again.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  18. #18

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    I just took a quick look at adding the first of those two 'Converted' codes into my project and it's absolutely full of error messages... In several cases the automatic correction facility suggested 'Change this into that' and I followed it's advice...

    That still left a good few errors in the list such as these: -

    Type 'System.Windows.Forms.DataFormats' has no constructors.
    There are several instancies of the option of: -
    [Generate Field stub] for : -'EM_GETPARAFORMAT', 'Collection', 'StringAlignment' in...
    or: -
    [Generate Method stub] for : -'EM_GETPARAFORMAT', 'Collection', 'StringAlignment' in...
    or: -
    [Generate Property stub] for : -'EM_GETPARAFORMAT', 'Collection', 'StringAlignment' in...

    I also get: -
    'cbSize' Is not a member of 'System.Windows.Forms.DataFormats'. (Despite this having no constructors)
    'dwMask' Is not a member of 'System.Windows.Forms.DataFormats'. (Ditto)
    'wAlignment' Is not a member of 'System.Windows.Forms.DataFormats'. (Ditto)
    'Left' Is not a member of 'System.Windows.Forms.ToolBarTextAlignment'. (Ditto)
    'Message' Is a type and cannot be used as an expression.

    Some of these occur more than once and I have no idea what choices to make or what to do about them.

    Maybe I should've left it till morning
    Although I doubt I'll understand it any better then.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  19. #19
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Justifying text

    I don't know what you did, but try again. I copied the code from NSA's link and made sure that it converted properly before I posted a link to that converter. The converted code works as advertised.

  20. #20
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    try this -

    Code:
    Imports System
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    <Serializable()> _
    Public Class AdvRichTextBox
        Inherits RichTextBox
    
        Enum TextAlign
            Left = 1
            Right = 2
            Center = 3
            Justify = 4
        End Enum
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
        ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
        ByVal msg As Integer, ByVal wParam As Integer, ByVal lp As PARAFORMAT) As Integer
        End Function
    
    
        <StructLayout(LayoutKind.Sequential)> _
        Private Structure PARAFORMAT
            Public cbSize As Integer
            Public dwMask As UInteger
            Public wNumbering As Short
            Public wReserved As Short
            Public dxStartIndent As Integer
            Public dxRightIndent As Integer
            Public dxOffset As Integer
            Public wAlignment As Short
            Public cTabCount As Short
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
            Public rgxTabs() As Integer
    
            ' PARAFORMAT2 from here onwards.
            Public dySpaceBefore As Int32
            Public dySpaceAfter As Int32
            Public dyLineSpacing As Int32
            Public sStyle As Short
            Public bLineSpacingRule As Byte
            Public bOutlineLevel As Byte
            Public wShadingWeight As Short
            Public wShadingStyle As Short
            Public wNumberingStart As Short
            Public wNumberingStyle As Short
            Public wNumberingTab As Short
            Public wBorderSpace As Short
            Public wBorderWidth As Short
            Public wBorders As Short
        End Structure
    
        Private updating As Int32 = 0
        Private oldEventMask As Int32 = 0
    
        'Constants from the Platform SDK.
        Private Const EM_SETEVENTMASK As Integer = 1073
        Private Const EM_GETPARAFORMAT As Integer = 1085
        Private Const EM_SETPARAFORMAT As Integer = 1095
        Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
        Private Const WM_SETREDRAW As Integer = 11
        Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
        Private Const PFM_ALIGNMENT As Integer = 8
        Private Const SCF_SELECTION As Integer = 1
    
        Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
    
            MyBase.OnHandleCreated(e)
    
            'Enable support for justification.
            SendMessage(New HandleRef(Me, Handle), _
                         EM_SETTYPOGRAPHYOPTIONS, _
                         TO_ADVANCEDTYPOGRAPHY, _
                         TO_ADVANCEDTYPOGRAPHY)
        End Sub
    
        Public Overloads Property SelectionAlignment() As TextAlign
    
            Get
    
                Dim fmt As PARAFORMAT = New PARAFORMAT()
                fmt.cbSize = Marshal.SizeOf(fmt)
    
                ' Get the alignment.
                SendMessage(New HandleRef(Me, Handle), _
                             EM_GETPARAFORMAT, _
                             SCF_SELECTION, fmt)
    
                ' Default to Left align.
                If ((fmt.dwMask & PFM_ALIGNMENT) = 0) Then
                    Return TextAlign.Left
                End If
                If fmt.wAlignment = 1 Then
                    Return TextAlign.Left
                ElseIf fmt.wAlignment = 2 Then
                    Return TextAlign.Right
                ElseIf fmt.wAlignment = 3 Then
                    Return TextAlign.Center
                ElseIf fmt.wAlignment Then
                    Return TextAlign.Justify
                End If
            End Get
            Set(ByVal value As TextAlign)
    
                Dim fmt As PARAFORMAT = New PARAFORMAT()
                fmt.cbSize = Marshal.SizeOf(fmt)
                fmt.dwMask = PFM_ALIGNMENT
                fmt.wAlignment = CShort(value)
    
                ' Set the alignment.
                SendMessage(New HandleRef(Me, Handle), _
                            EM_SETPARAFORMAT, _
                            SCF_SELECTION, fmt)
            End Set
        End Property
    End Class
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  21. #21

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by TnTinMN View Post
    I don't know what you did, but try again. I copied the code from NSA's link and made sure that it converted properly before I posted a link to that converter. The converted code works as advertised.
    Thanks TnTinMN, I think when I tried it last night I placed the whole thing right at the end of my code with the inevitable result.

    I'll try again later.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  22. #22
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    Here is the fully converted code -

    Code:
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    ''' <summary>
    ''' Represents a standard <see cref="RichTextBox"/> with some
    ''' minor added functionality.
    ''' </summary>
    ''' <remarks>
    ''' AdvRichTextBox provides methods to maintain performance
    ''' while it is being updated. Additional formatting features
    ''' have also been added.
    ''' </remarks>
    Public Class AdvRichTextBox
        Inherits RichTextBox
        ''' <summary>
        ''' Maintains performance while updating.
        ''' </summary>
        ''' <remarks>
        ''' <para>
        ''' It is recommended to call this method before doing
        ''' any major updates that you do not wish the user to
        ''' see. Remember to call EndUpdate when you are finished
        ''' with the update. Nested calls are supported.
        ''' </para>
        ''' <para>
        ''' Calling this method will prevent redrawing. It will
        ''' also setup the event mask of the underlying richedit
        ''' control so that no events are sent.
        ''' </para>
        ''' </remarks>
        Public Sub BeginUpdate()
            ' Deal with nested calls.
            updating += 1
    
            If updating > 1 Then
                Return
            End If
    
            ' Prevent the control from raising any events.
            oldEventMask = SendMessage(New HandleRef(Me, Handle), EM_SETEVENTMASK, 0, 0)
    
            ' Prevent the control from redrawing itself.
            SendMessage(New HandleRef(Me, Handle), WM_SETREDRAW, 0, 0)
        End Sub
    
        ''' <summary>
        ''' Resumes drawing and event handling.
        ''' </summary>
        ''' <remarks>
        ''' This method should be called every time a call is made
        ''' made to BeginUpdate. It resets the event mask to it's
        ''' original value and enables redrawing of the control.
        ''' </remarks>
        Public Sub EndUpdate()
            ' Deal with nested calls.
            updating -= 1
    
            If updating > 0 Then
                Return
            End If
    
            ' Allow the control to redraw itself.
            SendMessage(New HandleRef(Me, Handle), WM_SETREDRAW, 1, 0)
    
            ' Allow the control to raise event messages.
            SendMessage(New HandleRef(Me, Handle), EM_SETEVENTMASK, 0, oldEventMask)
        End Sub
    
        ''' <summary>
        ''' Gets or sets the alignment to apply to the current
        ''' selection or insertion point.
        ''' </summary>
        ''' <remarks>
        ''' Replaces the SelectionAlignment from
        ''' <see cref="RichTextBox"/>.
        ''' </remarks>
        Public Shadows Property SelectionAlignment() As TextAlign
            Get
                Dim fmt As New PARAFORMAT()
                fmt.cbSize = Marshal.SizeOf(fmt)
    
                ' Get the alignment.
                SendMessage(New HandleRef(Me, Handle), EM_GETPARAFORMAT, SCF_SELECTION, fmt)
    
                ' Default to Left align.
                If (fmt.dwMask And PFM_ALIGNMENT) = 0 Then
                    Return TextAlign.Left
                End If
    
                Return CType(fmt.wAlignment, TextAlign)
            End Get
    
            Set(value As TextAlign)
                Dim fmt As New PARAFORMAT()
                fmt.cbSize = Marshal.SizeOf(fmt)
                fmt.dwMask = PFM_ALIGNMENT
                fmt.wAlignment = CShort(value)
    
                ' Set the alignment.
                SendMessage(New HandleRef(Me, Handle), EM_SETPARAFORMAT, SCF_SELECTION, fmt)
            End Set
        End Property
    
        ''' <summary>
        ''' This member overrides
        ''' <see cref="Control"/>.OnHandleCreated.
        ''' </summary>
        Protected Overrides Sub OnHandleCreated(e As EventArgs)
            MyBase.OnHandleCreated(e)
    
            ' Enable support for justification.
            SendMessage(New HandleRef(Me, Handle), EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY)
        End Sub
    
        Private updating As Integer = 0
        Private oldEventMask As Integer = 0
    
        ' Constants from the Platform SDK.
        Private Const EM_SETEVENTMASK As Integer = 1073
        Private Const EM_GETPARAFORMAT As Integer = 1085
        Private Const EM_SETPARAFORMAT As Integer = 1095
        Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
        Private Const WM_SETREDRAW As Integer = 11
        Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
        Private Const PFM_ALIGNMENT As Integer = 8
        Private Const SCF_SELECTION As Integer = 1
    
        ' It makes no difference if we use PARAFORMAT or
        ' PARAFORMAT2 here, so I have opted for PARAFORMAT2.
        <StructLayout(LayoutKind.Sequential)> _
        Private Structure PARAFORMAT
            Public cbSize As Integer
            Public dwMask As UInteger
            Public wNumbering As Short
            Public wReserved As Short
            Public dxStartIndent As Integer
            Public dxRightIndent As Integer
            Public dxOffset As Integer
            Public wAlignment As Short
            Public cTabCount As Short
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
            Public rgxTabs As Integer()
    
            ' PARAFORMAT2 from here onwards.
            Public dySpaceBefore As Integer
            Public dySpaceAfter As Integer
            Public dyLineSpacing As Integer
            Public sStyle As Short
            Public bLineSpacingRule As Byte
            Public bOutlineLevel As Byte
            Public wShadingWeight As Short
            Public wShadingStyle As Short
            Public wNumberingStart As Short
            Public wNumberingStyle As Short
            Public wNumberingTab As Short
            Public wBorderSpace As Short
            Public wBorderWidth As Short
            Public wBorders As Short
        End Structure
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, lParam As Integer) As Integer
        End Function
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lp As PARAFORMAT) As Integer
        End Function
    End Class
    
    ''' <summary>
    ''' Specifies how text in a <see cref="AdvRichTextBox"/> is
    ''' horizontally aligned.
    ''' </summary>
    Public Enum TextAlign
        ''' <summary>
        ''' The text is aligned to the left.
        ''' </summary>
        Left = 1
    
        ''' <summary>
        ''' The text is aligned to the right.
        ''' </summary>
        Right = 2
    
        ''' <summary>
        ''' The text is aligned in the center.
        ''' </summary>
        Center = 3
    
        ''' <summary>
        ''' The text is justified.
        ''' </summary>
        Justify = 4
    End Enum
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  23. #23

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by NeedSomeAnswers View Post
    try this -

    Public Overloads Property SelectionAlignment() As TextAlign

    Get...

    End Get

    Thanks NeedSomeAnswers, I'm trying your code, and will shortly try to work out how to use it...

    I've placed the whole thing 'as is' before the first line of my code (Public Class Form1), in a test piece I've set up for the purpose. I hope that's right, at least that hasn't thrown up any errors.

    Now... Everything looks ok except, under the 'End Get' in the above section of code there's a green (I think the technical name for it is) Wriggly Line.

    It gives me the warning, rather than an error,

    "Property 'Selection Alignment' doesn't return a value on all code paths.
    Are you missing a 'Return' statement ?"

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  24. #24
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    hmm that is strange as it clearly does have a return value -

    Code:
    Return CType(fmt.wAlignment, TextAlign)
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  25. #25
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Justifying text

    Seems like he might still be using the code from post 20, instead of 22. Post 20 didn't have a case for if none of the If ElseIf cases were met.
    Last edited by passel; Dec 18th, 2014 at 11:26 AM.

  26. #26
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    Aha yes that makes sense, the code in post 20 is incomplete, use the Post 22 code, thanks Passel !
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  27. #27

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by passel View Post
    Seems like he might still be using the code from post 20, instead of 22. Post 20 didn't have a case for if none of the If ElseIf cases were met.
    Hi, Yes you're right Passel, I believe post 22 arrived whilst I was typing up my post 23, there's only 5 minutes between 'em. I just tried the new version and I have no problems... I still have to work out how to use it though but that's half the fun of coding.

    Thanks guys.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  28. #28

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Some questions for NeedSomeAnswers.

    I have your code in my Form1.vb. All of it is above Public Class Form1. I trust that's correct ?

    Now I have to create an instance of the class, but where do I do that ? In fact, How do I do that ? I've been trying to work out what part of that code I have to use and indeed how to use it.

    Once I have that sorted out, I hope to use it in my project, but only in Form2.
    So, do I have to place it all Form2 ?
    And as a general question in regard to that, if I wanted to use it on several Forms in a project is it all accessible from Form1 ?

    Poppa.

    Oh, yes one more question... My RTB is inside a TLP is that going to cause me a problem ?

    Pop.
    Last edited by Poppa Mintin; Dec 18th, 2014 at 05:07 PM. Reason: Extra question...
    Along with the sunshine there has to be a little rain sometime.

  29. #29
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Justifying text

    I think I would just select under the Project menu in the IDE "Add Class...", and name the file "AdvRichTextBox.vb", and paste the code in there.
    Then, in Form2, where you need it, in the declarations area, do something like
    Private JustifiableTextBox as New AdvRichTextBox

    But then again, perhaps NSA means it to be build as a new control, so you can get it from the toolbox in the IDE and place it where you need it.

    I tried it out the first way, creating a class module.
    Then in my form1, I declared an instance, and added it to a flow panel that was already on that form. Entered some text, then aligned it.
    It looks like you have to select the text to align, but I didn't look at it in detail. When I selected all, and set the SelectionAlignment, it did justify the text.
    Code:
      Private justifiableTextBox As AdvRichTextBox = New AdvRichTextBox
    
    'in the form_load event
         flpChars.Controls.Add(justifiableTextBox)
        justifiableTextBox.Text = "This is a test to see if the text that is selected will be justified if we choose to."
        justifiableTextBox.SelectAll()
        justifiableTextBox.SelectionAlignment = TextAlign.Justify
        justifiableTextBox.SelectionLength = 0
    Last edited by passel; Dec 18th, 2014 at 07:08 PM.

  30. #30
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    I think I would just select under the Project menu in the IDE "Add Class...", and name the file "AdvRichTextBox.vb", and paste the code in there.
    Then, in Form2, where you need it, in the declarations area, do something like
    Private JustifiableTextBox as New AdvRichTextBox
    But then again, perhaps NSA means it to be build as a new control, so you can get it from the toolbox in the IDE and place it where you need it.
    Either way works, but i was thinking of your first method.

    Poppa - Yes dont add it to your existing Form code, you need a new class (right click on your project file in the solution explorer, add - Class - Then rename it AdvRichTextBox.vb - and copy over any existing code with the code posted in #22.

    Then Follow Passels code in #29 in the first instance.

    You could create as a Control so you could drop it on a form as design time, but there is no real need.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  31. #31

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Thanks guys, I'm getting there...

    Ok I still have problems, I tried to add the code as a new class, but it wouldn't accept all of it as it stands. All the code between 'Public Class AdvRichTextBox' and 'End Class' is ok, (yeah, I know, pretty obvious) but that leaves me wondering what to do with these three parts...
    vb.net Code:
    1. Imports System.Windows.Forms
    2. Imports System.Runtime.InteropServices
    3.  
    4. ''' <summary>
    5. ''' Represents a standard <see cref="RichTextBox"/> with some
    6. ''' minor added functionality.
    7. ''' </summary>
    8. ''' <remarks>
    9. ''' AdvRichTextBox provides methods to maintain performance
    10. ''' while it is being updated. Additional formatting features
    11. ''' have also been added.
    12. ''' </remarks>
    13. '''
    and
    vb.net Code:
    1. ''' <summary>
    2. ''' Specifies how text in a <see cref="AdvRichTextBox"/> is
    3. ''' horizontally aligned.
    4. ''' </summary>
    5. '''
    They look more like C# to me anyway, and to me they look like comments rather than functional code. But I'm sure
    vb.net Code:
    1. Public Enum TextAlign
    2.     ''' <summary>
    3.     ''' The text is aligned to the left.
    4.     ''' </summary>
    5.     Left = 1
    6.  
    7.     ''' <summary>
    8.     ''' The text is aligned to the right.
    9.     ''' </summary>
    10.     Right = 2
    11.  
    12.     ''' <summary>
    13.     ''' The text is aligned in the center.
    14.     ''' </summary>
    15.     Center = 3
    16.  
    17.     ''' <summary>
    18.     ''' The text is justified.
    19.     ''' </summary>
    20.     Justify = 4
    21.  
    22. End Enum
    is required.

    Passel, I can't figure out what ' flpChars.Controls.Add(justifiableTextBox) ' is ? The four line after that are ok, and yes they're in... Oh! you say 'Form Load' Event... that's not the Form Load Method ! I'll look at that...


    (After breakfast)

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  32. #32
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    The Stuff in Green is just comments, and will not cause you any errors. You can get rid if you want or not its up to you!

    What errors do you get still with your new class? and can you post the whole class as you have it now?

    Passel, I can't figure out what ' flpChars.Controls.Add(justifiableTextBox)
    flpChars is a flow panel, Passel did say in his earlier post, add a Flow panel to your form and rename it 'flpChars', then Passels code will add the extended Richtextbox to the Flow Panel.

    h! you say 'Form Load' Event... that's not the Form Load Method !
    Oh i would say what you think of as the Form Load method IS the Form Load Event!

    Events run after an Action, so something happens like a user clicks on a button, and the click event runs. When the Form Loads the Form Load Event runs.

    You can tell an Event in VB.Net as they have the Handles key word at then end - e.g. -

    Code:
    Private Sub SearchDialog_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  33. #33

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by NeedSomeAnswers View Post
    flpChars is a flow panel, Passel did say in his earlier post, add a Flow panel to your form and rename it 'flpChars', then Passels code will add the extended Richtextbox to the Flow Panel.

    Oh I would say what you think of as the Form Load method IS the Form Load Event!
    Ah... I don't know how I missed that, thanks.

    And yes, I took that the be what he meant, but only noticed the word 'Event' as I was writing.

    I've had a problem with the Form1.vb[design] in my trial project, but I've started a replacement test so now I can get back to trying it all out again.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  34. #34

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Quote Originally Posted by NeedSomeAnswers View Post
    What errors do you get still with your new class? and can you post the whole class as you have it now?
    Here is the code I have for ' AdvRichTextBox ' directly from the tab ' AdvRichTextBox.vb* ': -

    vb.net Code:
    1. Public Class AdvRichTextBox
    2.     Inherits RichTextBox
    3.    
    4.     Public Sub BeginUpdate()
    5.         ' Deal with nested calls.
    6.         updating += 1
    7.  
    8.         If updating > 1 Then
    9.             Return
    10.         End If
    11.  
    12.         ' Prevent the control from raising any events.
    13.         oldEventMask = SendMessage(New HandleRef(Me, Handle), EM_SETEVENTMASK, 0, 0)
    14.  
    15.         ' Prevent the control from redrawing itself.
    16.         SendMessage(New HandleRef(Me, Handle), WM_SETREDRAW, 0, 0)
    17.     End Sub
    18.  
    19.     Public Sub EndUpdate()
    20.         ' Deal with nested calls.
    21.         updating -= 1
    22.  
    23.         If updating > 0 Then
    24.             Return
    25.         End If
    26.  
    27.         ' Allow the control to redraw itself.
    28.         SendMessage(New HandleRef(Me, Handle), WM_SETREDRAW, 1, 0)
    29.  
    30.         ' Allow the control to raise event messages.
    31.         SendMessage(New HandleRef(Me, Handle), EM_SETEVENTMASK, 0, oldEventMask)
    32.     End Sub
    33.  
    34.     Public Shadows Property SelectionAlignment() As TextAlign
    35.         Get
    36.             Dim fmt As New PARAFORMAT()
    37.             fmt.cbSize = Marshal.SizeOf(fmt)
    38.  
    39.             ' Get the alignment.
    40.             SendMessage(New HandleRef(Me, Handle), EM_GETPARAFORMAT, SCF_SELECTION, fmt)
    41.  
    42.             ' Default to Left align.
    43.             If (fmt.dwMask And PFM_ALIGNMENT) = 0 Then
    44.                 Return TextAlign.Left
    45.             End If
    46.  
    47.             Return CType(fmt.wAlignment, TextAlign)
    48.         End Get
    49.  
    50.         Set(value As TextAlign)
    51.             Dim fmt As New PARAFORMAT()
    52.             fmt.cbSize = Marshal.SizeOf(fmt)
    53.             fmt.dwMask = PFM_ALIGNMENT
    54.             fmt.wAlignment = CShort(value)
    55.  
    56.             ' Set the alignment.
    57.             SendMessage(New HandleRef(Me, Handle), EM_SETPARAFORMAT, SCF_SELECTION, fmt)
    58.         End Set
    59.     End Property
    60.  
    61.     Protected Overrides Sub OnHandleCreated(e As EventArgs)
    62.         MyBase.OnHandleCreated(e)
    63.  
    64.         ' Enable support for justification.
    65.         SendMessage(New HandleRef(Me, Handle), EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY)
    66.     End Sub
    67.  
    68.     Private updating As Integer = 0
    69.     Private oldEventMask As Integer = 0
    70.  
    71.     ' Constants from the Platform SDK.
    72.     Private Const EM_SETEVENTMASK As Integer = 1073
    73.     Private Const EM_GETPARAFORMAT As Integer = 1085
    74.     Private Const EM_SETPARAFORMAT As Integer = 1095
    75.     Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
    76.     Private Const WM_SETREDRAW As Integer = 11
    77.     Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
    78.     Private Const PFM_ALIGNMENT As Integer = 8
    79.     Private Const SCF_SELECTION As Integer = 1
    80.  
    81.     ' It makes no difference if we use PARAFORMAT or
    82.     ' PARAFORMAT2 here, so I have opted for PARAFORMAT2.
    83.     <StructLayout(LayoutKind.Sequential)> _
    84.     Private Structure PARAFORMAT
    85.         Public cbSize As Integer
    86.         Public dwMask As UInteger
    87.         Public wNumbering As Short
    88.         Public wReserved As Short
    89.         Public dxStartIndent As Integer
    90.         Public dxRightIndent As Integer
    91.         Public dxOffset As Integer
    92.         Public wAlignment As Short
    93.         Public cTabCount As Short
    94.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
    95.         Public rgxTabs As Integer()
    96.  
    97.         ' PARAFORMAT2 from here onwards.
    98.         Public dySpaceBefore As Integer
    99.         Public dySpaceAfter As Integer
    100.         Public dyLineSpacing As Integer
    101.         Public sStyle As Short
    102.         Public bLineSpacingRule As Byte
    103.         Public bOutlineLevel As Byte
    104.         Public wShadingWeight As Short
    105.         Public wShadingStyle As Short
    106.         Public wNumberingStart As Short
    107.         Public wNumberingStyle As Short
    108.         Public wNumberingTab As Short
    109.         Public wBorderSpace As Short
    110.         Public wBorderWidth As Short
    111.         Public wBorders As Short
    112.     End Structure
    113.  
    114.     <DllImport("user32", CharSet:=CharSet.Auto)> _
    115.     Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, lParam As Integer) As Integer
    116.     End Function
    117.  
    118.     <DllImport("user32", CharSet:=CharSet.Auto)> _
    119.     Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lp As PARAFORMAT) As Integer
    120.     End Function
    121.  
    122. End Class

    There are far more errors listed this time... 19 Errors it says, and 2 warnings ! In my previous project there was only the one, it didn't like the final 'End Function'. This time I removed 'all the green stuff' including the 'stuff' between < > even though it wasn't actually green, maybe that's the problem ?

    I still don't know where to put the ' Public Enum TextAlign ' I'm sure that's part of what's supposed to be there.

    Poppa.

    I'm in a hotel in Portugal, and my purchased internet connection expired just as I clicked to 'Preview' this reply, so I've had to re-do the lot ! Typical !


    Pop
    Along with the sunshine there has to be a little rain sometime.

  35. #35
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    I'm in a hotel in Portugal
    Its alright for some

    Here is the code I have for ' AdvRichTextBox ' directly from the tab ' AdvRichTextBox.vb* ': -
    have you got -

    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices

    at the very top of your form ?

    To be honest i am surprised, i can load the code form post #22 into a new class and it works fine for me!

    I have stripped all the comments out, so try this code - Delete everything you currently have in your class and paste this in AS IS instead and let me know how that goes !

    If u still get errors, can you post a couple of them so we can see what they are?

    Code:
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    Public Class AdvRichTextBox
        Inherits RichTextBox
       
        Public Sub BeginUpdate()
            ' Deal with nested calls.
            updating += 1
    
            If updating > 1 Then
                Return
            End If
    
            ' Prevent the control from raising any events.
            oldEventMask = SendMessage(New HandleRef(Me, Handle), EM_SETEVENTMASK, 0, 0)
    
            ' Prevent the control from redrawing itself.
            SendMessage(New HandleRef(Me, Handle), WM_SETREDRAW, 0, 0)
        End Sub
    
        Public Sub EndUpdate()
            ' Deal with nested calls.
            updating -= 1
    
            If updating > 0 Then
                Return
            End If
    
            ' Allow the control to redraw itself.
            SendMessage(New HandleRef(Me, Handle), WM_SETREDRAW, 1, 0)
    
            ' Allow the control to raise event messages.
            SendMessage(New HandleRef(Me, Handle), EM_SETEVENTMASK, 0, oldEventMask)
        End Sub
    
        Public Shadows Property SelectionAlignment() As TextAlign
            Get
                Dim fmt As New PARAFORMAT()
                fmt.cbSize = Marshal.SizeOf(fmt)
    
                ' Get the alignment.
                SendMessage(New HandleRef(Me, Handle), EM_GETPARAFORMAT, SCF_SELECTION, fmt)
    
                ' Default to Left align.
                If (fmt.dwMask And PFM_ALIGNMENT) = 0 Then
                    Return TextAlign.Left
                End If
    
                Return CType(fmt.wAlignment, TextAlign)
            End Get
    
            Set(value As TextAlign)
                Dim fmt As New PARAFORMAT()
                fmt.cbSize = Marshal.SizeOf(fmt)
                fmt.dwMask = PFM_ALIGNMENT
                fmt.wAlignment = CShort(value)
    
                ' Set the alignment.
                SendMessage(New HandleRef(Me, Handle), EM_SETPARAFORMAT, SCF_SELECTION, fmt)
            End Set
        End Property
    
        Protected Overrides Sub OnHandleCreated(e As EventArgs)
            MyBase.OnHandleCreated(e)
    
            ' Enable support for justification.
            SendMessage(New HandleRef(Me, Handle), EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY)
        End Sub
    
        Private updating As Integer = 0
        Private oldEventMask As Integer = 0
    
        ' Constants from the Platform SDK.
        Private Const EM_SETEVENTMASK As Integer = 1073
        Private Const EM_GETPARAFORMAT As Integer = 1085
        Private Const EM_SETPARAFORMAT As Integer = 1095
        Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = 1226
        Private Const WM_SETREDRAW As Integer = 11
        Private Const TO_ADVANCEDTYPOGRAPHY As Integer = 1
        Private Const PFM_ALIGNMENT As Integer = 8
        Private Const SCF_SELECTION As Integer = 1
    
        ' It makes no difference if we use PARAFORMAT or
        ' PARAFORMAT2 here, so I have opted for PARAFORMAT2.
        <StructLayout(LayoutKind.Sequential)> _
        Private Structure PARAFORMAT
            Public cbSize As Integer
            Public dwMask As UInteger
            Public wNumbering As Short
            Public wReserved As Short
            Public dxStartIndent As Integer
            Public dxRightIndent As Integer
            Public dxOffset As Integer
            Public wAlignment As Short
            Public cTabCount As Short
            <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
            Public rgxTabs As Integer()
    
            ' PARAFORMAT2 from here onwards.
            Public dySpaceBefore As Integer
            Public dySpaceAfter As Integer
            Public dyLineSpacing As Integer
            Public sStyle As Short
            Public bLineSpacingRule As Byte
            Public bOutlineLevel As Byte
            Public wShadingWeight As Short
            Public wShadingStyle As Short
            Public wNumberingStart As Short
            Public wNumberingStyle As Short
            Public wNumberingTab As Short
            Public wBorderSpace As Short
            Public wBorderWidth As Short
            Public wBorders As Short
        End Structure
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, lParam As Integer) As Integer
        End Function
    
        <DllImport("user32", CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lp As PARAFORMAT) As Integer
        End Function
    End Class
    
    Public Enum TextAlign  
        Left = 1
        Right = 2
        Center = 3
        Justify = 4
    End Enum
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  36. #36

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    ok... now we're cooking. First I added the...

    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices

    at the top of the form, then I added the 'Enum' at the end and looked at the errors list again, this time there were only 4 occurrences of the same error, it didn't like ' TextAlign ' after a good long search I couldn't find where it should be declared, I thought it might be the 'Enum' coding... So, I deleted the whole of my code and replaced it with the code from your latest post, checked the errors list again and all's well.

    So, now I might stand a chance when I get back to the rest of the exercise...

    Thanks yet again...

    I'll keep you posted.

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  37. #37
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Justifying text

    Sorry for all the issues.
    Perhaps NSA and I were not explaining everything in great enough detail, not understanding how new this must be to you. After doing this a while you can forget explaining things to the nth degree for tasks that have become something you do without having to think about it.
    Some of the issues make me wonder just what version of .Net you're using, I typically use VS 2010 Pro.
    And, secondly, I wonder if you put the class code in the main form originally, and now deleted the code, but are trying to put the class in a class module, that in some of the VB auto-generated code files some remnant of info about the class in the previous location is causing an issue.
    I'm not saying that is a problem, its just the struggling has to make me wonder.
    So, in the interest of hopefully being fully clear of a full example process, I'll start a new project and detail the steps taken.

    Also, the only reason I added the AdvRichTextbox to a flow panel is because you mentioned adding it to a TLP, so my adding it to a Flow panel was suppose to be analogous, since I already had the flow panel on a form for another project, I just added the AdvRichTextBox class to that project. I assumed you would replace that line with adding it to your TLP.

    Here is a fairly minimal test project
    1. Starting a new project (Windows Forms Application), and naming it TestAdvRichTextBox, and letting the IDE "Create a directory for solution".
    2. When the IDE is ready (created and showing the Form's design window), select Project from the menu at the top of the IDE and select "Add Class...".
    3. Change the name of the file from "Class1.vb" to "AdvRichTextBox.vb" and hit the "Add" button.
    4. Delete all the lines generated (3 lines, Public Class AdvRichTextBox, blank line, End Class) in the Class module edit window that appears.
    5. Paste in the complete code from post #22 into the module.
    6. Return to the "Form1.vb [Design]" window and double click on the form to generate the Form's Class template ("Form1.vb") with Form1_Load event handler snippet.
    7. Between the "Public Class" line and the Form1_Load line, add a line to create an instance of the AdvRichTextBox class.
    8. In the Form1_Load event handler, add code to add the instance to the forms controls, and test it.

    The complete form code should look something like this.
    Code:
    Public Class Form1
    
      Private justifiableTextBox As AdvRichTextBox = New AdvRichTextBox
    
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(justifiableTextBox)
        justifiableTextBox.Text = "This is a test to see if the text that is selected will be justified if we choose to."
        justifiableTextBox.SelectAll()
        justifiableTextBox.SelectionAlignment = TextAlign.Justify
        justifiableTextBox.SelectionLength = 0
      End Sub
    End Class
    10. Run the project and you should see a form with a textbox on it with justified text in it.

    I just ran the project created above with these steps and it ran without any errors or warnings.
    Last edited by passel; Dec 19th, 2014 at 09:00 AM.

  38. #38

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text

    Hi,
    Thank you Passel for the Topic Review, I was just about to post my latest problems.

    However I'll now start a fresh project and try to follow exactly what you've said...
    I'd like to mention also that yes, you're correct about not all of us being totally au fait with this stuff, in my case you can add poor short term memory due to advancing years, one thing I might suggest is that whenever you use an acronym you might consider spelling the whole thing out for the first time... Although I ought to know what the IDE is, and I think I do know what it is, I have no idea what IDE actually stands for.

    Thanks again for your help, it really is appreciated...

    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  39. #39
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Justifying text

    IDE = Integrated Development Environment = Visual Studio
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  40. #40

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Justifying text



    Thank you.

    What does this line from 'post #22' mean ?

    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _

    Is it VB.NET ?


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width