Results 1 to 9 of 9

Thread: UserControl Help...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    UserControl Help...

    I am making a custom textbox control

    and my problem is when I try to map the textboxes multiline property to a property in my usercontrol it errors and says it is readonly...

    How can I get pass this?
    Visual Basic Rules!!!!!

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: UserControl Help...

    You can force its setting by throwing ES_MULTILINE into its window style. This is just pseudo-code as I don't have VB installed anymore.. but:
    Code:
    SetWindowLong(TextBox.hWnd, GWL_STYLE, ES_MULTILINE)
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: UserControl Help...

    I need to know the const values of GWL STYLE And ES_MULTILINE
    Visual Basic Rules!!!!!

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: UserControl Help...

    They are in your API Text file that comes with VB. Go to the API viewer and load the APIs, then search the constant values.

    Or, just type GWL_STYLE and ES_MULTILINE into google..

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: UserControl Help...

    This method doesn't work...
    Visual Basic Rules!!!!!

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: UserControl Help...

    Show your code.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: UserControl Help...

    In a module I have the api and the two const...

    and in the form_Load sub I have

    Code:
    SetWindowLong Text1.hwnd, GWL_STYLE, ES_MULTILINE
    Visual Basic Rules!!!!!

  8. #8
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: UserControl Help...

    Having looked into it further.. the MultiLine property is unchangable at runtime.. no matter how hard you try. Heres a workaround though:
    vb Code:
    1. Dim MaxLines As Long
    2.  
    3. Private Declare Function SendMessageLong Lib _
    4.     "user32" Alias "SendMessageA" _
    5.     (ByVal hwnd As Long, _
    6.      ByVal wMsg As Long, _
    7.      ByVal wParam As Long, _
    8.      ByVal lParam As Long) As Long
    9.  
    10. Const EM_LINEFROMCHAR = &HC9&
    11.  
    12. Private Sub Text1_Change()
    13.   Static LastText As String
    14.   Static LastCaretPos As Long
    15.   Static SecondTime As Boolean
    16.   Dim CurrentCaretPos As Long
    17.   Static NotFirstTime As Boolean
    18.   If NotFirstTime = False Then
    19.     NotFirstTime = True
    20.     Exit Sub
    21.   End If
    22.   With Text1
    23.     If Not SecondTime Then
    24.       CurrentCaretPos = .SelStart
    25.       .SelStart = Len(.Text)
    26.       If SendMessageLong(.hwnd, EM_LINEFROMCHAR, _
    27.                          -1&, 0&) + 1 > MaxLines Then
    28.         Beep
    29.         SecondTime = True
    30.         .Text = LastText
    31.         .SelStart = LastCaretPos
    32.       Else
    33.         LastText = .Text
    34.         .SelStart = CurrentCaretPos
    35.         LastCaretPos = .SelStart
    36.       End If
    37.     End If
    38.   End With
    39.   SecondTime = False
    40. End Sub
    41.  
    42. Private Sub Form_Load()
    43.   ' Here, I am setting MaxLines to 100 lines just to give
    44.   ' the code something to work with initially. You can set
    45.   ' this initial value to whatever you want and, of course,
    46.   ' reset it to any other value (for example, 1 to make it
    47.   ' a single line entry TextBox
    48.   MaxLines = 100
    49. End Sub
    Set the MultiLine property to True at design time. If you want it to be 1 line only, set MaxLines to 1. For multiline.. set it to a larger number.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: UserControl Help...

    Another option is to use two TextBox controls in your user control. One for single line, one for multiline. Show/Hide the textboxes as appropriate.

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