在 VB.NET 的 Windows 窗体控件中,InitializeComponent 何时何地被调用? [英] Where and when is InitializeComponent called in Windows Forms control in VB.NET?

查看:27
本文介绍了在 VB.NET 的 Windows 窗体控件中,InitializeComponent 何时何地被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VB.NET 中做一个 Windows 窗体项目,但 VB.NET 对我来说是全新的,我主要是一名 C# 开发人员.

I'm doing a Windows Forms project in VB.NET, but VB.NET is completely new to me, I'm primarily a C# developer.

在 C# Windows 窗体中,用户控件的 InitializeComponent 是从窗体/控件的构造函数中调用的.当我在 VB.NET 中创建相同的场景时,我没有得到构造函数,也找不到调用 InitializeComponent 的地方.

In C# Windows Forms, a user control's InitializeComponent is called from the form's/control's constructor. When I create same scenario in VB.NET I don't get a constructor, and I can't locate a place where InitializeComponent is called.

我需要在 InitializeComponent 和控件的 Load 事件引发之间调用我的代码,最好仍然在控件的构造函数中.我如何在 VB.NET 中执行此操作?

I need to call my code between InitializeComponent and when the control's Load event is raised, preferably still in the control's constructor. How do I do this in VB.NET?

推荐答案

转到表单中的查看代码",然后从右侧下拉菜单中选择新方法".

Go to View Code in your form, and from the right drop down and select "New Method".

在那里您可以看到调用 InitializeComponent 的位置并插入您的逻辑.

There you can see where InitializeComponent is called and insert your logic.

如果表单为空,您的代码应如下所示:

Your code, if your form is empty, should look like this:

Public Class Form1

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
    End Sub

End Class

这篇关于在 VB.NET 的 Windows 窗体控件中,InitializeComponent 何时何地被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆