Vielen Dank für die schnelle Antwort.
Genauso hatte ich es auch vorher gemacht.
Allerdings übergab ich die Position und Größe in sevText1_GotFocus an vier Integer-Vars.
In sevText1_LostFocus wollte ich dann die alte Pos und Größe wiederherstellen. Und das funktionierte nie:
Private Sub sevText1_LostFocus(Index As Integer)
With sevText1(Index)
.Width = TxWidth
.Height = TxHeight
.Left = TxLeft
.Top = TxTop
.Refresh
.AutoRedraw = False
End With
End Sub Ich fand heraus, dass es nur klappt, wenn ich vor der ersten Zuweisung durch eine Var eine Zuwweisung mit einer Hardcodierten Zahl machte z.b. .Width = 4000.
Mach ich etwas falsch? hier der Code zum ausprobieren:
'Resize.bas
' zunächst die benötigten API-Deklarationen
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As _
Long, _
ByVal nIndex As _
Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As _
Long, _
ByVal nIndex As _
Long, ByVal _
dwNewLong As _
Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x _
As Long, _
ByVal y As Long, ByVal cx As Long, ByVal _
cy As Long, _
ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_DRAWFRAME = &H20
Private Const GWL_STYLE = (-16)
Private Const WS_THICKFRAME = &H40000
' Ermöglicht die Größe eines Objekts zur Laufzeit zu ändern
'
' bStatus = True, Größenänderung einschalten
' bStatus = False, Größenänderung abschalten
' =====================================================
Public Sub DoResize(hWndParent As Long, _
hWndObject As Long, ByVal bStatus As Boolean)
Dim Result As Long
Result = GetWindowLong(hWndObject, GWL_STYLE) Or _
WS_THICKFRAME
If Not bStatus Then _
Result = Result - WS_THICKFRAME
SetWindowLong hWndObject, GWL_STYLE, Result
SetWindowPos hWndObject, hWndParent, 0, 0, 0, 0, _
SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or _
SWP_DRAWFRAME
End Sub
'------------------------------------------------------------------------------
' ---------------------
'Form1
Option Explicit
Public TxResizeIndex As Integer
Dim TxWidth As String
Dim TxHeight As String
Dim TxLeft As String
Dim TxTop As String
Private Sub Form_Load()
End Sub
Private Sub sevText1_Click(Index As Integer)
With sevText1(Index)
If .Tag = "Resize" Then
.Tag = ""
DoResize Me.hwnd, .hwnd, False
.Refresh
.AutoRedraw = True
Else
.Tag = "Resize"
.AutoRedraw = True
DoResize Me.hwnd, .hwnd, True
End If
End With
End Sub
Private Sub sevText1_GotFocus(Index As Integer)
With sevText1(Index)
TxWidth = .Width
TxHeight = .Height
TxLeft = .Left
TxTop = .Top
End With
End Sub
Private Sub sevText1_LostFocus(Index As Integer)
With sevText1(Index)
.Width = 4000 ' ohne diese Zuweisung klappt es nicht
.Width = TxWidth
.Height = TxHeight
.Left = TxLeft
.Top = TxTop
.Refresh
.AutoRedraw = False
End With
End Sub Gruss Gunthard |