unload form1_Form1.Hide和Unload Me有什么区别?

unload form1

Hide and Unload are techniques in Visual Basic 6—VB.NET does things differently. In VB6, you can see the difference clearly by creating a form with a CommandButton component and a test statement in the Click event. Note that these two statements are mutually exclusive, so only one can be tested at a time.

隐藏和卸载是Visual Basic 6中的技术,VB.NET的处理方式有所不同。 在VB6中,通过在Click事件中创建带有CommandButton组件和测试语句的表单,可以清楚地看到差异。 请注意,这两个语句是互斥的,因此一次只能测试一个。

Visual Basic 6卸载语句 ( Visual Basic 6 Unload Statement )

The Unload statement removes the form from memory. In most simple VB6 projects, Form1 is the startup object so the program stops running too. To prove this, code the first program with Unload.

Unload语句从内存中删除该窗体。 在大多数简单的VB6项目中,Form1是启动对象,因此程序也停止运行。 为了证明这一点,请使用Unload对第一个程序进行编码。

Private Sub Command1_Click()   Unload MeEnd Sub

私人子Command1_Click()卸载MeEnd子

When the button is clicked in this project, the program stops.

在该项目中单击按钮时,程序停止。

Visual Basic 6隐藏语句 ( Visual Basic 6 Hide Statement )

To demonstrate Hide, run this code in VB6 so the Hide method of Form1 is executed.

为了演示Hide,请在VB6中运行此代码,以便执行Form1的Hide方法。

Private Sub Command1_Click()   Form1.HideEnd Sub

私人子Command1_Click()Form1.HideEnd子

Notice that Form1 disappears from the screen, but the square "End" icon on the Debug toolbar shows the project is still active. If you're in doubt, the Windows Task Manager that is displayed with Ctrl+Alt+Del shows the project is still in Run mode.

注意,Form1从屏幕上消失了,但是“调试”工具栏上的方形“结束”图标显示该项目仍处于活动状态。 如果您有疑问,则与Ctrl + Alt + Del一起显示的Windows任务管理器将显示项目仍处于“运行”模式。

与隐藏表单进行沟通 ( Communicating With a Hidden Form )

The Hide method only removes the form from the screen. Nothing else changes. For example, another process can still communicate with objects on the form after the Hide method is called. Here's a program that demonstrates that. Add another form to the VB6 project and then add a Timer component and this code to Form1:

Hide方法仅从屏幕上删除表单。 没有其他改变。 例如,在调用Hide方法之后,另一个进程仍可以与表单上的对象进行通信。 这是一个演示程序。 将另一个窗体添加到VB6项目,然后添加一个Timer组件,并将此代码添加到Form1:

Private Sub Command1_Click()   Form1.Hide   Form2.ShowEnd Sub

私人子Command1_Click()Form1.Hide Form2.ShowEnd Sub

Private Sub Timer1_Timer()   Form2.Hide   Form1.ShowEnd Sub

私有子Timer1_Timer()Form2.Hide Form1.ShowEnd Sub

In Form2, add a Command button control and this code:

在Form2中,添加一个Command按钮控件和以下代码:

Private Sub Command1_Click()   Form1.Timer1.Interval = 10000 ' 10 seconds   Form1.Timer1.Enabled = TrueEnd Sub

私人子Command1_Click()Form1.Timer1.Interval = 10000'10秒Form1.Timer1.Enabled = TrueEnd Sub

When you run the project, clicking the button on Form1 makes Form1 disappear and Form2 appear. However, clicking the button on Form2 uses the Timer component on Form1 to wait 10 seconds before making Form2 disappear and Form1 appear again even though Form1 isn't visible.

当您运行该项目时,单击Form1上的按钮会使Form1消失并显示Form2。 但是,单击Form2上的按钮将使用Form1上的Timer组件等待10秒钟,直到Form2不可见,Form2消失并再次出现Form1。

Since the project is still running, Form1 keeps appearing every 10 seconds—a technique you might use to drive a coworker batty one day.

由于项目仍在运行,因此Form1会每隔10秒钟出现一次,这是您一天可能会用来吸引同事的技术。

翻译自: https://www.thoughtco.com/difference-between-form1hide-and-unload-me-3424279

unload form1

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值