RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
vb.net入口主函数,主函数是c程序的入口

vb.net 窗体程序的入口在哪

方法如下:

大名网站建设公司创新互联,大名网站设计制作,有大型网站制作公司丰富经验。已为大名成百上千提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的大名做网站的公司定做!

1、打开例1.1创建的工程。

2、选择窗体Form1并双击该窗体,出现窗体的调事件的过程代码体。

3、在窗体调用的过程代码体中编制如下过程代码:

Private Sub Form_Load()

Form1.Width = 4860

Form1.Height = 2520

End Sub

4、设置窗体Form1的SartUpPosition属性为2-屏幕中心,这样运行窗体可以发现,屏幕的大小与例1.6中通过属性设置的大小是一致的。

详细阐述 vb.net 中main

每个 Visual Basic 应用程序均必须包含一个称为VB.NET Main过程。该过程为应用程序的起始点并为应用程序提供总体控制。.NET Framework 在已加载应用程序并准备将控制传递给它时,将调用 Main 过程。除非您要创建 Windows 窗体应用程序,否则就必须为自运行的应用程序编写 Main 过程。

Main 中包含首先运行的代码。在 Main 中,可以确定在程序启动时首先加载的窗体,确定系统上是否已在运行您的应用程序副本,为应用程序建立一组变量,或者打开应用程序需要的数据库。

VB.NET Main过程的要求

独立运行的文件(扩展名通常为 .exe)必须包含 Main 过程。库(例如,扩展名为 .dll)不独立运行,因而不需要 Main 过程。可以创建的不同类型的项目的要求如下:

控制台应用程序可以独立运行,而且您必须提供至少一个 Main 过程。

Windows 窗体应用程序可以独立运行。但是,Visual Basic 编译器会在此类应用程序中自动生成一个 Main 过程,因而您不需要编写此过程。

类库不需要 Main 过程。这些类库包括 Windows 控件库和 Web 控件库。作为类库部署 Web 应用程序。

声明VB.NET Main过程

有四种方法可以声明 Main 过程。它可以使用参数或不使用参数,可以返回值或不返回值。

注意

如果在类中声明 Main 过程,则必须使用 Shared 关键字。在模块中,Main 不必是 Shared。

最简单的方法是声明一个不使用参数或不返回值的 Sub 过程。

Module mainModule

Sub Main()

MsgBox("The Main procedure

is starting the application.")

' Insert call to appropriate

starting place in your code.

MsgBox("The application

is terminating.")

End Sub

End ModuleMain

还可以返回一个 Integer 值,操作系统将其作为程序的退出代码。其他程序可以通过检查 Windows ERRORLEVEL 值来测试该代码。若要返回退出代码,必须将VB.NET Main过程声明为 Function 过程而不是 Sub 过程。

Module mainModule

Function Main() As Integer

MsgBox("The Main procedure

is starting the application.")

Dim returnValue As Integer = 0

' Insert call to appropriate

starting place in your code.

' On return, assign appropriate

value to returnValue.

' 0 usually means successful

completion.

MsgBox("The application is

terminating with error level " _

CStr(returnValue) ".")

Return returnValue

End Function

End ModuleMain

还可以采用一个 String 数组作为参数。数组中的每个字符串均包含一个用于调用程序的命令行参数。您可以根据它们的值采取不同的操作。

Module mainModule

Function Main(ByVal cmdArgs()

As String) As Integer

MsgBox("The Main procedure is

starting the application.")

Dim returnValue As Integer = 0

' See if there are any arguments.

If cmdArgs.Length 0 Then

For argNum As Integer = 0 To

UBound(cmdArgs, 1)

' Insert code to examine cmdArgs

(argNum) and take

' appropriate action based on its value.

Next argNum

End If

' Insert call to appropriate starting

place in your code.

' On return, assign appropriate

value to returnValue.

' 0 usually means successful completion.

MsgBox("The application is

terminating with error level " _

CStr(returnValue) ".")

Return returnValue

End Function

End Module

可以声明VB.NET Main过程来检查命令行参数而不返回退出代码,如下所示。

Module mainModule

Sub Main(ByVal cmdArgs() As String)

MsgBox("The Main procedure is

starting the application.")

Dim returnValue As Integer = 0

' See if there are any arguments.

If cmdArgs.Length 0 Then

For argNum As Integer = 0 To

UBound(cmdArgs, 1)

' Insert code to examine cmdArgs

(argNum) and take

' appropriate action based on its value.

Next argNum

End If

' Insert call to appropriate

starting place in your code.

MsgBox("The application is

terminating."

End Sub

End Module

VB.NET string$函数

VB6的String()函数,在VB.NET中,改用 StrDup()函数,使用格式与VB6的String()函数类似:

例如:

VB6中,String(5,"*") ,是产生5个星号字符,"*****"

VB.Net中,改用 StrDup(5,"*") ,也是产生5个星号字符,"*****"

VB.net窗体程序如何让cmd调用?

VB.NET 里面会有一个main方法表示函数的入口

main方法的参数就是命令行传给它的

shutdown.exe能直接调用是因为你的环境变量有C盘的windows目录

你只要在你程序的输出目录(一般为bin)里面打开命令行输入程序名称.exe就可以直接执行你的窗体

如果你要调试输入命令的效果,你打开你项目的属性,找到调试里面的命令行参数,在里面输入测试参数就能在你main函数里面看到结果了

那如果你想打开任何命令行都可以执行你的窗体程序,那你把你程序的安装目录设置为环境变量,这样就可以直接执行这个命令了

VB.Net Sub Main 的问题

看你的意思,你是不是想问怎么在VB.NET中获取命令行参数?如果是这样,很简单,在Vb.NET中,利用System.Environment.GetCommandLineArgs函数返回一组系统传送的启动参数。

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

Dim myArg() As String, i As Integer

myArg = System.Environment.GetCommandLineArgs

If myArg.Length 0 Then

For i = 1 To UBound(myArg)

MsgBox(myArg(i).ToString)

Next

End If

End Sub

假设你的程序编译为A.EXE,运行时用 A.EXE /a /s /pt 带参数运行,则用上述代码,可分别显示/a /s /pt


网页名称:vb.net入口主函数,主函数是c程序的入口
标题路径:http://scyingshan.cn/article/phiohg.html