|
|
|
date: Tue, 23 Oct 2007 11:54:01 -0700,
group: microsoft.public.inetsdk.programming.scripting.jscript
back
changing textbox size dynamically
I have a textbox that I would like to change the size dynamically as the user
types and it word wraps. I have used the following vb code (pasted below)
but what I need is to do it in javascript. So I ask if anyone out there has
done this in javascript and willing to share how it was done? My javascript
is very very weak so be kind.
Thanks to anyone who responds.
... John
Option Explicit
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_FMTLINES = &HC8
Const EM_LINEFROMCHAR = &HC9
Dim MinWidth As Long
Dim MaxWidth As Long
Dim MaxHeight As Long
Dim LastCursor As Long
Dim LastText As String
Dim SingleLineOnly As Boolean
Private Sub Form_Load()
With Text1
Set Me.Font = .Font
MaxHeight = .Container.ScaleHeight - .Top
MaxWidth = .Container.ScaleWidth - .Left
MinWidth = Me.TextWidth("XX")
.Height = Me.TextHeight("X")
.Width = MinWidth
End With
End Sub
Private Sub Text1_Change()
Dim RequiredHeight As Long
Dim LinesHigh As Long
With Text1
.Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
6 * .BorderStyle, vbPixels, Me.ScaleMode)
If .Width < MinWidth Then
.Width = MinWidth
ElseIf .Width > MaxWidth Then
.Width = MaxWidth
End If
SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
LinesHigh = 1 + UBound(Split(Replace$(.Text, _
vbCr & vbCrLf, vbNewLine), vbNewLine))
SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
RequiredHeight = LinesHigh * Me.TextHeight("X") + _
Me.ScaleY(6 * .BorderStyle, _
vbPixels, Me.ScaleMode)
If RequiredHeight < MaxHeight Then
.Height = RequiredHeight
Else
.Text = LastText
.SelStart = LastCursor
End If
.Refresh
End With
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If SingleLineOnly Then
If KeyAscii = 13 Then KeyAscii = 0
End If
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
LastText = Text1.Text
LastCursor = Text1.SelStart
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
LastCursor = Text1.SelStart
End Sub
date: Tue, 23 Oct 2007 11:54:01 -0700
author: JohnE
Re: changing textbox size dynamically
"JohnE" wrote in message
news:DA91C993-9771-4767-92BE-7400BBBA557F@microsoft.com...
>I have a textbox that I would like to change the size dynamically as the
>user
> types and it word wraps. I have used the following vb code (pasted below)
> but what I need is to do it in javascript. So I ask if anyone out there
> has
> done this in javascript and willing to share how it was done? My
> javascript
> is very very weak so be kind.
>
> Thanks to anyone who responds.
>
> ... John
>
>
> Option Explicit
>
> 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_FMTLINES = &HC8
> Const EM_LINEFROMCHAR = &HC9
>
> Dim MinWidth As Long
> Dim MaxWidth As Long
> Dim MaxHeight As Long
> Dim LastCursor As Long
> Dim LastText As String
> Dim SingleLineOnly As Boolean
>
> Private Sub Form_Load()
> With Text1
> Set Me.Font = .Font
> MaxHeight = .Container.ScaleHeight - .Top
> MaxWidth = .Container.ScaleWidth - .Left
> MinWidth = Me.TextWidth("XX")
> .Height = Me.TextHeight("X")
> .Width = MinWidth
> End With
> End Sub
>
> Private Sub Text1_Change()
> Dim RequiredHeight As Long
> Dim LinesHigh As Long
> With Text1
> .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
> 6 * .BorderStyle, vbPixels, Me.ScaleMode)
> If .Width < MinWidth Then
> .Width = MinWidth
> ElseIf .Width > MaxWidth Then
> .Width = MaxWidth
> End If
> SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
> LinesHigh = 1 + UBound(Split(Replace$(.Text, _
> vbCr & vbCrLf, vbNewLine), vbNewLine))
> SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
> RequiredHeight = LinesHigh * Me.TextHeight("X") + _
> Me.ScaleY(6 * .BorderStyle, _
> vbPixels, Me.ScaleMode)
> If RequiredHeight < MaxHeight Then
> .Height = RequiredHeight
> Else
> .Text = LastText
> .SelStart = LastCursor
> End If
> .Refresh
> End With
> End Sub
>
> Private Sub Text1_KeyPress(KeyAscii As Integer)
> If SingleLineOnly Then
> If KeyAscii = 13 Then KeyAscii = 0
> End If
> End Sub
>
> Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
> LastText = Text1.Text
> LastCursor = Text1.SelStart
> End Sub
>
> Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
> X As Single, Y As Single)
> LastCursor = Text1.SelStart
> End Sub
>
You can't run code like that from script, it has no facility to call into
non COM libraries.
If the textbox is on a webpage then it's easy, just get a reference to the
box and set its size property.
If the textbox is a textbox on a windows form then one approach would be
wrap the code above in an ActiveX library and call that from script.
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Fri, 2 Nov 2007 09:21:04 -0000
author: Joe Fawcett am
Re: changing textbox size dynamically
"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message
news:unhwyGTHIHA.6068@TK2MSFTNGP05.phx.gbl...
> "JohnE" wrote in message
> news:DA91C993-9771-4767-92BE-7400BBBA557F@microsoft.com...
>>I have a textbox that I would like to change the size dynamically as the
>>user
>> types and it word wraps. I have used the following vb code (pasted
>> below)
>> but what I need is to do it in javascript. So I ask if anyone out there
>> has
>> done this in javascript and willing to share how it was done? My
>> javascript
>> is very very weak so be kind.
>>
>> Thanks to anyone who responds.
>>
>> ... John
>>
>>
>> Option Explicit
>>
>> 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_FMTLINES = &HC8
>> Const EM_LINEFROMCHAR = &HC9
>>
>> Dim MinWidth As Long
>> Dim MaxWidth As Long
>> Dim MaxHeight As Long
>> Dim LastCursor As Long
>> Dim LastText As String
>> Dim SingleLineOnly As Boolean
>>
>> Private Sub Form_Load()
>> With Text1
>> Set Me.Font = .Font
>> MaxHeight = .Container.ScaleHeight - .Top
>> MaxWidth = .Container.ScaleWidth - .Left
>> MinWidth = Me.TextWidth("XX")
>> .Height = Me.TextHeight("X")
>> .Width = MinWidth
>> End With
>> End Sub
>>
>> Private Sub Text1_Change()
>> Dim RequiredHeight As Long
>> Dim LinesHigh As Long
>> With Text1
>> .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
>> 6 * .BorderStyle, vbPixels, Me.ScaleMode)
>> If .Width < MinWidth Then
>> .Width = MinWidth
>> ElseIf .Width > MaxWidth Then
>> .Width = MaxWidth
>> End If
>> SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
>> LinesHigh = 1 + UBound(Split(Replace$(.Text, _
>> vbCr & vbCrLf, vbNewLine), vbNewLine))
>> SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
>> RequiredHeight = LinesHigh * Me.TextHeight("X") + _
>> Me.ScaleY(6 * .BorderStyle, _
>> vbPixels, Me.ScaleMode)
>> If RequiredHeight < MaxHeight Then
>> .Height = RequiredHeight
>> Else
>> .Text = LastText
>> .SelStart = LastCursor
>> End If
>> .Refresh
>> End With
>> End Sub
>>
>> Private Sub Text1_KeyPress(KeyAscii As Integer)
>> If SingleLineOnly Then
>> If KeyAscii = 13 Then KeyAscii = 0
>> End If
>> End Sub
>>
>> Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
>> LastText = Text1.Text
>> LastCursor = Text1.SelStart
>> End Sub
>>
>> Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
>> X As Single, Y As Single)
>> LastCursor = Text1.SelStart
>> End Sub
>>
> You can't run code like that from script, it has no facility to call into
> non COM libraries.
> If the textbox is on a webpage then it's easy, just get a reference to the
> box and set its size property.
> If the textbox is a textbox on a windows form then one approach would be
> wrap the code above in an ActiveX library and call that from script.
Yet this code has a Declare for SendMessage (called SendMessageLong by the
code). If that works then it is calling into a regular DLL. How is that
possible? I assume it is not a script; I assume it is VB code.
date: Fri, 2 Nov 2007 12:40:34 -0700
author: Sam Hobbs _change_social_to_socal
Re: changing textbox size dynamically
"Sam Hobbs" <samuel@social.rr.com_change_social_to_socal> wrote in message
news:%23$091gYHIHA.5208@TK2MSFTNGP04.phx.gbl...
> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message
> news:unhwyGTHIHA.6068@TK2MSFTNGP05.phx.gbl...
>> "JohnE" wrote in message
>> news:DA91C993-9771-4767-92BE-7400BBBA557F@microsoft.com...
>>>I have a textbox that I would like to change the size dynamically as the
>>>user
>>> types and it word wraps. I have used the following vb code (pasted
>>> below)
>>> but what I need is to do it in javascript. So I ask if anyone out
>>> there has
>>> done this in javascript and willing to share how it was done? My
>>> javascript
>>> is very very weak so be kind.
>>>
>>> Thanks to anyone who responds.
>>>
>>> ... John
>>>
>>>
>>> Option Explicit
>>>
>>> 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_FMTLINES = &HC8
>>> Const EM_LINEFROMCHAR = &HC9
>>>
>>> Dim MinWidth As Long
>>> Dim MaxWidth As Long
>>> Dim MaxHeight As Long
>>> Dim LastCursor As Long
>>> Dim LastText As String
>>> Dim SingleLineOnly As Boolean
>>>
>>> Private Sub Form_Load()
>>> With Text1
>>> Set Me.Font = .Font
>>> MaxHeight = .Container.ScaleHeight - .Top
>>> MaxWidth = .Container.ScaleWidth - .Left
>>> MinWidth = Me.TextWidth("XX")
>>> .Height = Me.TextHeight("X")
>>> .Width = MinWidth
>>> End With
>>> End Sub
>>>
>>> Private Sub Text1_Change()
>>> Dim RequiredHeight As Long
>>> Dim LinesHigh As Long
>>> With Text1
>>> .Width = Me.TextWidth(.Text) + Me.ScaleX(2 + _
>>> 6 * .BorderStyle, vbPixels, Me.ScaleMode)
>>> If .Width < MinWidth Then
>>> .Width = MinWidth
>>> ElseIf .Width > MaxWidth Then
>>> .Width = MaxWidth
>>> End If
>>> SendMessageLong .hwnd, EM_FMTLINES, 1, 0#
>>> LinesHigh = 1 + UBound(Split(Replace$(.Text, _
>>> vbCr & vbCrLf, vbNewLine), vbNewLine))
>>> SendMessageLong .hwnd, EM_FMTLINES, 0, 0#
>>> RequiredHeight = LinesHigh * Me.TextHeight("X") + _
>>> Me.ScaleY(6 * .BorderStyle, _
>>> vbPixels, Me.ScaleMode)
>>> If RequiredHeight < MaxHeight Then
>>> .Height = RequiredHeight
>>> Else
>>> .Text = LastText
>>> .SelStart = LastCursor
>>> End If
>>> .Refresh
>>> End With
>>> End Sub
>>>
>>> Private Sub Text1_KeyPress(KeyAscii As Integer)
>>> If SingleLineOnly Then
>>> If KeyAscii = 13 Then KeyAscii = 0
>>> End If
>>> End Sub
>>>
>>> Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
>>> LastText = Text1.Text
>>> LastCursor = Text1.SelStart
>>> End Sub
>>>
>>> Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _
>>> X As Single, Y As Single)
>>> LastCursor = Text1.SelStart
>>> End Sub
>>>
>> You can't run code like that from script, it has no facility to call into
>> non COM libraries.
>> If the textbox is on a webpage then it's easy, just get a reference to
>> the box and set its size property.
>> If the textbox is a textbox on a windows form then one approach would be
>> wrap the code above in an ActiveX library and call that from script.
>
>
> Yet this code has a Declare for SendMessage (called SendMessageLong by the
> code). If that works then it is calling into a regular DLL. How is that
> possible? I assume it is not a script; I assume it is VB code.
>
What's your question? The OP said it was VB, he wanted to do it in script.
As I said it is not possible for script to access native DLL functions
directly, they can only interact with COM DLLs.
--
Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Sun, 4 Nov 2007 15:45:14 -0000
author: Joe Fawcett am
|
|