vb.net 窗体上的VB隐藏按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17721136/
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 hidden button on form
提问by ariban
I am using VB to search some data from a text file and then populate in excel. It's working. The problem is xl.visible=true makes the excel sheet to be visible at once & then the values keep on populating. I want to hide the excel till data population is complete. then make a button appear on the form which when clicked, will display the excel file.
我正在使用 VB 从文本文件中搜索一些数据,然后填充到 excel 中。它正在工作。问题是 xl.visible=true 使 Excel 工作表立即可见,然后值继续填充。我想隐藏 excel 直到数据填充完成。然后在表单上出现一个按钮,单击该按钮将显示 excel 文件。
Please help. Here is the code I'm using:
请帮忙。这是我正在使用的代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' create an excel instance
Dim xl = Microsoft.VisualBasic.CreateObject("Excel.Application")
xl.Visible = False
Dim wb = xl.Workbooks.Add()
Dim sheet = wb.ActiveSheet
' find lines starting with any whitepace followed by MTV or MTB and capture
' the text after =
Dim pattern = "(?<=\s*(MTV).*=).*"
Dim i = 1
Dim arg = {Microsoft.VisualBasic.ControlChars.CrLf, Microsoft.VisualBasic.ControlChars.Lf}
If RichTextBox3.Text = "" Then
MsgBox("No input. What will I process??")
Else
Timer1.Start()
For Each line In File.ReadLines(RichTextBox3.Text)
Dim match = Regex.Match(line, pattern)
' check each line and fill sheet
If match.Success Then
sheet.Cells(i, 1).Value = match.Value
i += 1
End If
Next
End If
xl.Visible = True
End Sub
回答by D_Bester
Use Button2 to do the Excel work but remove the line: xl.Visible = True
使用 Button2 执行 Excel 工作,但删除该行: xl.Visible = True
Put a button on your form called Button3 (or named whatever); set Button3 property Visible = False. Then at the bottom of Button2 click event put Button3.Visible = True
在您的表单上放置一个名为 Button3(或其他名称)的按钮;设置 Button3 属性 Visible = False。然后在Button2的底部点击事件放Button3.Visible = True
After your Button2 gets clicked you'll have Button3 visible. In Button3 click event put xl.Visible = True
单击 Button2 后,您将看到 Button3。在 Button3 单击事件中放置xl.Visible = True
To make this work, you'll need to declare "xl" as a module or class variable. Just put Dim xl as objectabove your sub and remove the Dim inside your sub; that will do it.
为了使这项工作,您需要将“xl”声明为模块或类变量。只需放在Dim xl as object您的潜水艇上方并移除您的潜水艇内的 Dim;那会做到的。
回答by helpfultipman
Simple type button1.Hide()when you click on the button or something else it will then hide the button. Hope this helps you out.
button1.Hide()当您单击按钮或其他内容时,简单类型将隐藏该按钮。希望这可以帮助你。
Remember, button1.Hide()refers to the first button - if it is the 2nd button it would be button2.hide(), etc.
请记住,button1.Hide()指的是第一个按钮 - 如果它是第二个按钮,它将是button2.hide(),等等。

