返回winform按钮值
下面的代码是在 Ironpython 中,但我正在寻找 Ironpython 或任何其他语言(C#、VB...)中的 winforms 解决方案
我有一个 winforms 按钮:
self._button1 = System.Windows.Forms.Button()
self._button1.Location = System.Drawing.Point(234, 191)
self._button1.Name = "selectFolder_button"
self._button1.Size = System.Drawing.Size(121, 23)
self._button1.TabIndex = 1
self._button1.Text = "select"
self._button1.Click += self.Button1Click
self.Controls.Add(self._button1)
单击该按钮时会打开“选择文件夹对话框”:
def FolderDialog(self):
dialog = System.Windows.Forms.FolderBrowserDialog()
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK):
folderString = dialog.SelectedPath
return folderString
def Button1Click(self, sender, e):
folderString = self.FolderDialog()
return folderString
我怎样才能调用'folderString' 在同一 winforms 表单中的其他方法中?看看它有什么价值。是否有一些像“self._button1.Value”这样的属性? 我将不胜感激任何形式的帮助。先感谢您。
The code below is in Ironpython, but I am looking for winforms solution in Ironpython or any other language (C#, VB...)
I have a winforms button:
self._button1 = System.Windows.Forms.Button()
self._button1.Location = System.Drawing.Point(234, 191)
self._button1.Name = "selectFolder_button"
self._button1.Size = System.Drawing.Size(121, 23)
self._button1.TabIndex = 1
self._button1.Text = "select"
self._button1.Click += self.Button1Click
self.Controls.Add(self._button1)
which when clicked opens 'select folder dialog' with:
def FolderDialog(self):
dialog = System.Windows.Forms.FolderBrowserDialog()
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK):
folderString = dialog.SelectedPath
return folderString
def Button1Click(self, sender, e):
folderString = self.FolderDialog()
return folderString
How can I call the 'folderString' in some other method within the same winforms form? To see which value it has. Is there some 'self._button1.Value' like property?
I would be grateful for any kind of help. Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在此处找到了解决方案。
本质上,我创建了一个类,然后将其实例化为 Winforms 类全局范围:
然后在“Button1Click”方法中为其分配了一个新值:
最后,我只在 Winforms 的任何其他方法中调用“self.selectedFolder.Value”班级。
感谢您的帮助@Idle_Mind
I found a solution here.
Essentially I created a class, then instantiated it the Winforms class global scope:
Then assigned to it a new value inside the "Button1Click" method:
In the end I just call the 'self.selectedFolder.Value' inside any other method of the Winforms class.
Thank you for the help @Idle_Mind