|
-
Sep 8th, 2007, 06:27 PM
#1
Thread Starter
Hyperactive Member
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!!!!! 
-
Sep 8th, 2007, 08:48 PM
#2
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
-
Sep 8th, 2007, 08:52 PM
#3
Thread Starter
Hyperactive Member
Re: UserControl Help...
I need to know the const values of GWL STYLE And ES_MULTILINE
Visual Basic Rules!!!!! 
-
Sep 8th, 2007, 09:02 PM
#4
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
-
Sep 8th, 2007, 09:06 PM
#5
Thread Starter
Hyperactive Member
Re: UserControl Help...
This method doesn't work...
Visual Basic Rules!!!!! 
-
Sep 8th, 2007, 09:10 PM
#6
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 8th, 2007, 09:11 PM
#7
Thread Starter
Hyperactive Member
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!!!!! 
-
Sep 8th, 2007, 09:18 PM
#8
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:
Dim MaxLines As Long
Private Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Const EM_LINEFROMCHAR = &HC9&
Private Sub Text1_Change()
Static LastText As String
Static LastCaretPos As Long
Static SecondTime As Boolean
Dim CurrentCaretPos As Long
Static NotFirstTime As Boolean
If NotFirstTime = False Then
NotFirstTime = True
Exit Sub
End If
With Text1
If Not SecondTime Then
CurrentCaretPos = .SelStart
.SelStart = Len(.Text)
If SendMessageLong(.hwnd, EM_LINEFROMCHAR, _
-1&, 0&) + 1 > MaxLines Then
Beep
SecondTime = True
.Text = LastText
.SelStart = LastCaretPos
Else
LastText = .Text
.SelStart = CurrentCaretPos
LastCaretPos = .SelStart
End If
End If
End With
SecondTime = False
End Sub
Private Sub Form_Load()
' Here, I am setting MaxLines to 100 lines just to give
' the code something to work with initially. You can set
' this initial value to whatever you want and, of course,
' reset it to any other value (for example, 1 to make it
' a single line entry TextBox
MaxLines = 100
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
-
Sep 8th, 2007, 09:45 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|