gpt4 book ai didi

vb.net - 如何从 ShowDialog 窗口返回一个值?

转载 作者:行者123 更新时间:2023-12-01 07:14:18 25 4
gpt4 key购买 nike

主界面

DoSomething()
My.Forms.frmMessage.ShowDialog(Me)
If AcceptButtonClicked Then
' Do Code
DoCode()
Else
' Cancel Button Pressed
DoOtherCode()
End If
DoMore()

消息
My.Forms.frmMain.AcceptButtonClicked = True

有没有办法将值从对话框窗口传递回主窗口上的暂停线程?我想知道他们在填写弹出的表格后是否按下了确定或取消按钮。

最佳答案

您可以使用 DialogResult 表格上的属性(property)。该值将由您调用的 ShowDialog 函数返回。您也可以设置此 property on your buttons所以 WinForms 将处理表单属性的设置。

在您的 frmMessage您必须相应地设置属性( pick the one you need, OK and Cancel )。然后您可以轻松检查返回值:

If My.Forms.frmMessage.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
' OK button pressed
DoCode()
Else
' Cancel button pressed
DoOtherCode()
End If

不要忘记,用户可能能够以另一种方式关闭表单,而不是用您的按钮关闭它(例如,通过使用关闭按钮关闭它)。

关于vb.net - 如何从 ShowDialog 窗口返回一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17982144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com