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?
Printable View
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?
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:
chemCode:SetWindowLong(TextBox.hWnd, GWL_STYLE, ES_MULTILINE)
I need to know the const values of GWL STYLE And ES_MULTILINE
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
This method doesn't work...
Show your code.
chem
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
Having looked into it further.. the MultiLine property is unchangable at runtime.. no matter how hard you try. Heres a workaround though:
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.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
chem
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.