vb.net VB.net如何重置一个表格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19779664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.net how to reset a form?
提问by Tuller45
I wanna know if it's posible to reset a form? I'm making a battle game but i need to reset the form after a battle so i can play the battle infinity times
我想知道是否可以重置表格?我正在制作一个战斗游戏,但我需要在战斗后重置表格,这样我才能无限次玩战斗
Maybe something a little like this:
也许有点像这样:
If TextBox1.Text = "You Won!" Then
Me.reset
End If
Of course this dosen't work that is why im asking for help to reset the form. Thanks!
当然,这不起作用,这就是为什么我要求帮助重置表单。谢谢!
回答by Hans Passant
The very simple solution is to just create a new instance of the form and closing the "used" one. Greatly assisted by the Project + Properties, Shutdown mode setting. Change it to "When last form closes". Which makes this code work:
非常简单的解决方案是创建一个新的表单实例并关闭“已使用”的实例。项目 + 属性、关机模式设置的大力协助。将其更改为“当最后一个表单关闭时”。这使此代码工作:
If Me.TextBox1.Text = "You Won!" Then
Dim frm = New Form1 '' Change the class name if necessary
frm.Show()
Me.Close()
End If
回答by TheProgrammer
The Easiest way
最简单的方法
call from the form you want to reset/restart
从您要重置/重新启动的表单中调用
---form name---
---表格名称---
application.restart
application.restart
me.refresh
我.刷新
that will do the magic. :)
那会变魔术。:)
回答by Reed Copsey
Of course this dosen't work that is why im asking for help to reset the form. Thanks!
当然,这不起作用,这就是为什么我要求帮助重置表单。谢谢!
There is no built in method to do this. You would need to write a Reset
method on your form, which would go through and setup all of the properties and values back to their original state.
没有内置的方法可以做到这一点。您需要Reset
在表单上编写一个方法,该方法将遍历并将所有属性和值设置回其原始状态。
回答by Borrell Fankam
If you want to reset a form that can be re-opened from another form later on, you need a slight tweak:
如果您想重置以后可以从另一个表单重新打开的表单,您需要稍作调整:
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
Dim f2 As New client1Form
Me.Dispose() '~~> Or Me.Close()
f2.Show()
starterForm.currentForm = f2
End Sub
- We make the new form,
f2
then dispose of the current one.
- 我们制作新表格,
f2
然后处理当前表格。
- We then show the new
f2
form and set thecurrentForm
(Dim currentForm As Form
) to equal the newf2
form so that when we click on the button which handles the opening of the originalclient1Form
, it will open this newf2
, instead of the old one which we got rid ofwithMe.dispose()
orMe.Close()
.
- 然后我们显示新
f2
表单并将currentForm
(Dim currentForm As Form
)设置为等于新f2
表单,这样当我们单击处理原始表单打开的按钮时client1Form
,它将打开这个新表单f2
,而不是我们用Me.dispose()
或删除的旧表单。Me.Close()
.
- Without the
starterForm.currentForm = f2
, when we re-open the form, it'll just give you the original you had before, including any data that remained, if you usedMe.Close()
) or just an empty version of the original form, (if you usedMe.Dispose()
). But we want then new form & any data we enter into it.
- 如果没有
starterForm.currentForm = f2
,当我们重新打开表单时,它只会为您提供之前拥有的原始,包括任何剩余的数据(如果您使用Me.Close()
)或只是原始表单的空版本(如果您使用Me.Dispose()
)。但是我们想要新的表格和我们输入的任何数据。
- On the parent form we are using
currentForm.Show()
on the click event of the open form button.
- 在父表单上,我们
currentForm.Show()
在打开表单按钮的点击事件上使用。