Lad brugere justere Controls runtime
Jeg har fundet noget kode på MSDN i VB6. Efter at have fumlet med at få det til at du i VB.NET har jeg nu 1 fejl tilbage. Kan i hjælpe mig med det?Proplemet ligger i linjen med SetWindowPos. Jeg får meddelelsen:
-----------------------------------------------------
An unhandled exception of type 'System.NullReferenceException' occurred in ResizingControls_vb.exe
Additional information: Object reference not set to an instance of an object.
-----------------------------------------------------
Koden kommer her:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
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 Sub 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)
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Const SWP_NOMOVE = &H2
Const SWP_DRAWFRAME = &H20
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ResizeControl(TextBox1, ParentForm)
End Sub
Function ResizeControl(ByVal ControlName As Control, ByVal FormName As Form)
Dim NewStyle As Long
NewStyle = GetWindowLong(ControlName.Handle.ToInt32, GWL_STYLE)
NewStyle = NewStyle Or WS_THICKFRAME
NewStyle = SetWindowLong(TextBox1.Handle.ToInt32, GWL_STYLE, NewStyle)
SetWindowPos(ControlName.Handle.ToInt32, FormName.Handle.ToInt32, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)
End Function
End Class