Avatar billede stenner Nybegynder
18. juni 2003 - 12:14 Der er 1 løsning

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
Avatar billede kedde65 Praktikant
07. august 2003 - 13:06 #1
Det er kaldet til din resizeControl der fejler. Du kalder den med parameteren parentForm, det skal være følgende linie istedet

ResizeControl(TextBox1, Me)

VH CK
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester