在应用运行时移动或最小化表单 [英] Moving or minimizing a form while app is runnng

查看:57
本文介绍了在应用运行时移动或最小化表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010构建Windows窗体应用程序.我希望能够在应用程序运行时将表单拖动到另一个位置或最小化表单.那可能吗?这是一个例子.我有一个带有一个按钮的表格.以下是与按钮关联的代码:

I am using visual studio 2010 to build a windows forms app. I want to be able to drag the form to another location or minimize the form while the app is running. Is that possible? Here''s an example. I have a form with one button. Here''s the code associated with the button:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim time0 As Integer
    Dim time1 As Integer
    For time0 = 0 To 1000000000
        time1 = time0
    Next
End Sub



在按下按钮之前,我可以拖动表格或将其最小化.一旦按下按钮,表单将被冻结,直到代码停止运行.



Before I push the button, I can drag the form or minimize it. Once I push the button, the form is frozen until the code stops running.

推荐答案

在循环中添加以下内容:
Add the following inside your loop:
Application.DoEvents();


这告诉您的代码响应外部事件,例如移动或调整大小.


This tells your code to respond to external events, such as moves or resizes.


另一种选择是使用 ^ ]
Another option is to use the Background Worker Class[^]


这篇关于在应用运行时移动或最小化表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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