本文介绍了控制创建事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在VB.Net中创建了一个类,它继承了面板类,所以我将它用作我的应用程序中的控件。我如何捕获何时创建此控件作为事件?

我尝试调整大小的事件,定义一个第一次为false的布尔值,并在第一次调整大小事件时变为true,因此将发生一次,所以我认为它会在设计师创建时调用resize事件,但事实并非如此。这是我的代码:

Hi,
I've created a class in VB.Net, it inherits panel class, so I'll use it as a control in my application. How can I catch "when this control is created" as event?
I tried resized event defining a boolean that is false at the first time, and becomes true at first resize event, so will occur once, so I tought it would call resize event when it is created by designer, but it didn't. Here is my code:

Public Class ScrollPanel
    Inherits Panel
    Dim pnl As New Panel With {.Location = New Point(0, 0), .Size = New Size(Me.Width - 10, Me.Height), .BackColor = Color.White}
    Dim kgOk As Boolean = False

    Private Sub SC() Handles MyBase.SizeChanged
        If Not kgOk Then
            Controls.Add(pnl)
            kgOk = True
        End If
    End Sub
End Class

推荐答案

Public Class ScrollPanel
    Inherits Panel

    Private sText As String = "New Panel"

    Public Sub New()
        MsgBox(String.Concat(sText, " has been created!"), MsgBoxStyle.Information, "Message")
    End Sub



    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class





用法:



Usage:

Dim sp As ScrollPanel = New ScrollPanel With {.Parent = Me, .Size = New Size(100, 100), .Location = New Point(80, 80), .Visible = True}





更多:

[]


这篇关于控制创建事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 05:07