Page 2 of 2 FirstFirst 12
Results 41 to 57 of 57

Thread: [RESOLVED] Justifying text

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

    Re: Justifying text

    It is telling .Net how to handle that array when it creates a version of the structure in unmanaged memory, i.e. when the program wants to send the structure to an API call, or write the structure to a file and read from a file into memory, the data from the structure as managed by .Net can be scattered around memory, wrapped in object classes, etc.
    .Net can organize the structure anyway it sees fit, unless you specifically tell it to do otherwise.
    In this case, we need it to match the message structure expected by the SendMessage API, (really as the receiver of the message expects it), so the first instruction,
    <StructLayout(LayoutKind.Sequential)>
    Says to layout the structure in the order specified and without extra field alignment bytes packed between fields to optimize access to the fields.
    And the UnmanagedType.ByValArray, creates the space in the structure to allow the dynamic array to be 32 elements long (a fixed size array), at that point in the structure.

  2. #42

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

    Re: Justifying text

    Wow !

    You might like to know I'm finding some answers, I've not yet found how to put the new text box into a TLP but I'm still trying..,
    meanwhile...

    Name:  Form1  04.jpg
Views: 271
Size:  28.1 KBName:  Form1  05.jpg
Views: 248
Size:  24.9 KB
    These are to show the details of the test form, and a typical 'Start'.
    The new class is exactly as post#22.

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private JTB As AdvRichTextBox = New AdvRichTextBox
    4.  
    5.     Private Sub Form1_Load() Handles MyBase.Load
    6.         Dim Jtxt As String
    7.         Dim NewX As Integer
    8.  
    9.         Button1.Text = "Test"
    10.         Button2.Text = "EXIT"
    11.         Me.Controls.Add(JTB)
    12.         JTB.Width = Me.Width - 32   'An arbitary figure, less than the two side margins.
    13.         JTB.Height = 180
    14.         NewX = (Me.Width / 2) - (JTB.Width / 2) - 8 'Location X for JTB central.
    15.         JTB.Anchor = AnchorStyles.None
    16.         RePos(JTB, NewX, 5)
    17.         Jtxt = "This is a test to see if the text that is selected will be justified if we choose to."
    18.         Jtxt += vbCrLf & JTB.Anchor.ToString
    19.         TxBox(Jtxt)
    20.  
    21.     End Sub
    22.  
    23.     Public Sub TxBox(ByVal Jx As String)
    24.         JTB.Text = Jx
    25.         JTB.SelectAll()
    26.         JTB.SelectionAlignment = TextAlign.Justify
    27.         JTB.SelectionLength = 0
    28.  
    29.     End Sub
    30.  
    31.     Private Sub RePos(ByVal This As Control, ByVal NewX As Integer, ByVal NewY As Integer)
    32.         Dim Here As New Point(NewX, NewY)
    33.         This.Location = Here
    34.     End Sub
    35.  
    36.     Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
    37.  
    38.         Application.Exit()
    39.     End Sub
    40.  
    41.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    42.         Dim z As String
    43.  
    44.         JTB.Font = New Font("Ariel Narrow", 16, FontStyle.Bold, GraphicsUnit.Point)
    45.         z = "Mary had a little lamb, his feet were black as soot, "
    46.         z += "and everywhere that Mary went, his sooty foot he put."
    47.         TxBox(z)
    48.  
    49.     End Sub
    50. End Class

    I'm enjoying this...

    Thanks guys...

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

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

    Re: Justifying text

    Quote Originally Posted by Poppa Mintin View Post
    ... I've not yet found how to put the new text box into a TLP but I'm still trying..,
    meanwhile...
    Just add it to the TableLayoutPanel instead of the form.
    When you add controls to a TableLayoutPanel, you also specify which X,Y position (column,row) you want the control, so below I'm adding it to the second row, First column.
    Code:
      Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TableLayoutPanel1.Controls.Add(justifiableTextBox, 0, 1)
        '    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
    Last edited by passel; Dec 19th, 2014 at 04:52 PM.

  4. #44

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

    Re: Justifying text

    Thanks again Passel, I've got that now...

    I've hit a snag, and as I was typing that, I figured out a way around it... I hope.

    I've been trying for about an hour n half to find how to specify ColumnSpan in the TLP for my nice new RTB, It would seem that ColumnSpan isn't catered for in the class. I've been trying to find information about it in User32.dll but that's a jungle !

    But it's my belief that there's nothing to stop me from using more than one TLP in a form. I'm using TLP in my main project because I want to be able to resize the RTBs on the form.

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

  5. #45

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

    Re: Justifying text

    Hi... More problems, I'm trying to get ambitious now, and it's not working.

    My test project now has four TLPs and I can successfully write to three Justifiable Rich Text Boxes in three of 'em (The 4th has buttons) but the subroutine is cumbersome so I'm trying to streamline it a bit...

    I figure this should work but (of course) it doesn't. Currently the test project only has one form, I'll save the problems of multi-form work till I've got this bit working.
    I've shown how the three text boxes are generated, but not how they're put in the TLPs because that's not the problem... But I'm aware that the fact that they're in a TLP may be.

    It's this subroutine that's giving me grief, in code line 10 I'm trying to assign JTB 1, 2 or 3 to the variable Bn.
    The four lines after that all work correctly when I use them individually with JTB1, JTB2 and JTB3.
    Stepping through the code as far as line 12, Bn still as the value 'Nothing', so (again) I'm doing something wrong, or maybe not doing something I ought to be doing.

    vb,net Code:
    1. Public Class Form1
    2.  
    3.     Private JTB1 As AdvRichTextBox = New AdvRichTextBox
    4.     Private JTB2 As AdvRichTextBox = New AdvRichTextBox
    5.     Private JTB3 As AdvRichTextBox = New AdvRichTextBox
    6.  
    7.     Private Sub Write2Box(ByVal Jx As String, ByVal Bx As Integer)
    8.         Dim Bn As AdvRichTextBox
    9.  
    10.         Bn = CType(Me.Controls("JTB" & Bx.ToString),AdvRichTextBox)
    11.  
    12.         Bn.Text = Jx
    13.         Bn.SelectAll()
    14.         Bn.SelectionAlignment = TextAlign.Justify
    15.         Bn.SelectionLength = 0
    16.  
    17.     End Sub
    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  6. #46
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Justifying text

    Quote Originally Posted by Poppa Mintin View Post
    Stepping through the code as far as line 12, Bn still as the value 'Nothing'
    If you're creating controls at runtime you need to set their Name property or will be nothing (or blank string?).
    Me.Controls() expects a control index or the string Name of the control...

    Code:
    Private JTB1 As RichTextBox
    
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        JTB1 = New RichTextBox
        JTB1.Name = "JTB100"
        Me.Controls.Add(JTB1)
    End Sub
    
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim bx As Integer = 100
        Dim Bn = DirectCast(Me.Controls.Item("JTB" & bx.ToString), RichTextBox)
        ' test
        Bn.BackColor = Color.Red
    End Sub

  7. #47
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Justifying text

    Well the problem is Me.Controls... but not quite the way Edge indicates... Me.Controls will only contain controls DIRECTLY on the form... since you ARTBs are on TLPs, they are not on the form... they are in the controls collection of their respective TLP.

    -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??? *

  8. #48
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Justifying text

    Also, to make it easier, you should be passing the ARTB itself... not the name... then you don't care where it is.

    -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??? *

  9. #49

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

    Re: Justifying text

    Quote Originally Posted by techgnome View Post
    Also, to make it easier, you should be passing the ARTB itself... not the name... then you don't care where it is.

    -tg
    Thanks -tg

    That's finally sorted out.


    Edgemeal

    I tried your solution totally without success but I suspect you didn't realise we're not talking about ordinary RTBs here.

    I did find however that I needed to 'Name' them as you indicated before my for-to loop would work. And as you may've seen techgnome has the answer.

    Everyone else.

    Thanks for all your help guys.

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

  10. #50
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Justifying text

    Quote Originally Posted by Poppa Mintin View Post
    Edgemeal

    I tried your solution totally without success but I suspect you didn't realise we're not talking about ordinary RTBs here.

    I did find however that I needed to 'Name' them as you indicated before my for-to loop would work. And as you may've seen techgnome has the answer.
    Why not just copy the advanced richtextbox class code to its own class file and build the project?... then that control will be in the toolbox and can be used like any other control in the toolbox and you don't need to do all this, unless you're adding and/or removing the control at runtime then OK, I didn't read the whole thread.

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

    Re: [RESOLVED] Justifying text

    edit - unneccessary post
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  12. #52

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

    Re: Justifying text

    Quote Originally Posted by Edgemeal View Post
    Why not just copy the advanced richtextbox class code to its own class file and build the project?... then that control will be in the toolbox and can be used like any other control in the toolbox and you don't need to do all this.
    It took me a couple of days to discover what you meant by this, I just couldn't find any reference to the new textbox in the Toolbox, I decided to call it 'SmartBox' by the way, doesn't take so much typing, or room on the code line, (I considered 'CoolBox' but thought that might be a bit too casual.)

    However I found that I'd been looking in the wrong place, until now I've always gone down the Toolbox list alphabetically from the first item, I discovered quite accidentally that the new item was above the 'first' one.

    I'm only mentioning it now in case someone else has the same problem, and to mention that using this new 'SmartBox' from the Toolbox has other advantages, I can nominate the Font Unit for example and have access to many features which I couldn't find how to do before.

    Again guys, thanks for all your help.

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

  13. #53

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

    Re: Justifying text

    Quote Originally Posted by Poppa Mintin View Post
    It took me a couple of days to discover what you meant by this, I just couldn't find any reference to the new textbox in the Toolbox.
    I'm only mentioning it now in case someone else has the same problem.
    Oh dear... More problems.

    Turns out it's me that has the same problem... Quick question first, in case this is the problem.

    Once the new Class has been declared via 'Properties > Add Class', ought the new textbox to be listed in the toolbox prior to the 2012 version ?

    I may've mentioned that I couldn't get version 2012 to install on a laptop, and I discovered today that Microsoft say on their download page that they've discontinued the 2012 Free version. So... I decided to start a new Project, with a new name in version 2010.

    I've entered the new Class as previously described, and added the six forms then copied and pasted all the objects from my previous project straight into the new forms. Then likewise the six code pages with no apparent problems... Done the same thing several times previously.

    However Form2 didn't copy the new textboxes across. So of course I thought, 'no problem, I'll enter 'em manually from the toolbox' as I did in the 2012 version. But this time no new textbox in the toolbox.

    I've looked very carefully at every item in there... No new textbox.

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

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

    Re: Justifying text

    Did you build the project, using VB 2010.?
    You have to build the project to create the control, which would then show up in the toolbox.
    By default, a control built in a later version of VB would be targeting a later .Net framework, so wouldn't work with 2010.

  15. #55

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

    Re: Justifying text

    Quote Originally Posted by passel View Post
    Did you build the project, using VB 2010.?
    Yes I think so. I opened the new project in VB2010.
    Then I copied Post #22 and pasted it directly into the new Class... 'SmartBox.vb'.
    Then I opened 5 more Forms... Form1 existed, I added Form2 to Form6. Then expanded each form big enough to hold all it's components.
    For each form I opened a FormX.vb. (Double click the top border of each form) This also generated the...
    Private Sub FormX_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    for each form so I deleted those.

    Next I saved and Closed VB2010, opened the project I was copying in VB2012 and opened Form1.vb[Design], clicked inside the form and then did 'Control + A' to focus all the components and did 'Control + C' to copy them. Then closed '12 and opened '10, opened the project and Form1.vb[Design], clicked inside the form to get it focused and did 'Control + V' to paste all the components.
    I did the same for each of the others in turn.

    That was the finish of opening '12. For each FormX I used 'File open' to open and copy the source code from the '12 project folder for FormX.vb, and pasted it directly into the corresponding FormX.vb.

    Then I tried to build the project but found the 'SmartBoxes' hadn't copied and discovered I couldn't find 'Smartbox' in the tool box.

    So, I believe I built the project in '10, not '12.

    Maybe you'll tell me different.

    Poppa.

    Edit: I copied and pasted the source code from an open file, didn't just 'drag' it.

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

  16. #56

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

    Re: [RESOLVED] Justifying text

    The Toolbox has several groups of controls, I've looked very carefully through all of these.
    The last group is headed 'General', and in my case it says:
    There are no usable controls in this group. Drag an item onto this text to add it to the toolbox.
    I tried doing this by 'Dragging' 'SmartBox' from the Solution Explorer (Once I'd figured out how to stop the toolbox auto-hiding) and it said 'Toolbox Item(s) Added'.

    I looked in the 'General' group expecting to see it there, but of course it isn't. I searched carefully through each of the other groups but it's not in any of those either.

    Ah well... Bed time for sad Poppa.
    Along with the sunshine there has to be a little rain sometime.

  17. #57

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

    Re: [RESOLVED] Justifying text

    Ok guys... I've got this one resolved too...

    Because I'm copying from a project which already had SmartBox added to the toolbox, I didn't realise that when I make a new project, the instance on the form has to name the same item as the one I'm going to use in the program... I just copied the one I had in the previous project which had had it's original name changed.

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

Page 2 of 2 FirstFirst 12

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