包含vb.net只打开一个的词条

怎样让VB.NET做的应用程序只启动一个实例

最简单的方法

专注于为中小企业提供网站建设、做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业新乐免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) 0 Then End

前提是你的程序名别太普通了容易和别的进程重名就不行了

vb net只运行一个程序

方法一:通过Diagnostics.Process.GetProcessesByName函数来检测程序是否已经启动

Imports System.Windows.Forms

Module Module1

Sub Main()

'检测多重启动

If Diagnostics.Process.GetProcessesByName( _

Diagnostics.Process.GetCurrentProcess.ProcessName).Length 1 Then

MessageBox.Show("已经一个实例的本程序正在运行。")

Return

End If

Application.Run(New Form())

End Sub

End Module

不过这个方法有个缺点,如果用户改了下exe的名字就检测不到了,所以更好的方法如下

方法2:使用Mutex

Imports System.Windows.Forms

Module Module1

Sub Main()

Dim createdNew As Boolean

' 创建mutex

Dim mutex As System.Threading.Mutex = _

New System.Threading.Mutex(True, "YourAppName", createdNew)

If createdNew = False Then

MessageBox.Show("已经一个实例的本程序正在运行。")

Return

End If

Application.Run(New Form())

' 释放mutex

mutex.ReleaseMutex()

End Sub

End Module

vb.net如何实现:只开启一个exe实例打开多个txt文件?

试试看这样行不:在应用程序设置中,勾选“生成单个实例应用程序”,然后在应用程序事件中处理这个事件

Private Sub MyApplication_StartupNextInstance(sender As Object, e As StartupNextInstanceEventArgs) Handles Me.StartupNextInstance

'这里的 e.CommandLine应该就是双击第二个文件时传进来的命令行

End Sub

VB.NET编的form程序,如何操作可以搞成只能运行一个实例,也就是像微信一样只能单开不能躲开?

在项目上右键,然后选择属性,打开如下图所示的项目属性对话框:

然后选择左边的“应用程序”标签页,再勾选上“生成单个实例应用程序”。

用VB.NET制作图片浏览器时 ,打开图片文件时只能一张一张的打开,如何设置可以一次打开多个图片文件

Public Class Form1

Dim Files() As String

Dim ImgNum As Integer = 0

Dim CurIdx As Integer = 0

Sub OpenFiles()

InitialSet()

Try

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

If Not OpenFileDialog1.FileNames Is Nothing Then

Files = OpenFileDialog1.FileNames

Else

Files(0) = OpenFileDialog1.FileName

End If

ImgNum = Files.Length

Dim s As String = String.Format("你共打开 {0} 张图片", ImgNum)

Me.Text = s

StateSet()

CurIdx = 1

DisplayImage(CurIdx)

Else

StateSet()

Me.PictureBox1.Image = Nothing

End If

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Sub InitialSet()

Me.OpenFileDialog1.Multiselect = True

Me.OpenFileDialog1.Filter = "(*.jpg)|*jpg"

Me.OpenFileDialog1.FilterIndex = 0

ImgNum = 0

CurIdx = 0

If Not Files Is Nothing Then

Array.Clear(Files, 0, Files.Length - 1)

End If

End Sub

Sub DisplayImage(ByRef Idx As Integer)

If IO.Path.GetExtension(Files(Idx - 1)).ToLower = ".jpg" Then

Me.PictureBox1.Load(Files(Idx - 1))

End If

StateSet()

End Sub

Sub StateSet()

If ImgNum 1 Then

Me.btnNext.Enabled = True

Else

Me.btnNext.Enabled = False

Me.btnPervious.Enabled = False

Exit Sub

End If

If CurIdx 1 And ImgNum 1 Then

Me.btnPervious.Enabled = True

Else

Me.btnPervious.Enabled = False

End If

If CurIdx ImgNum And ImgNum 1 Then

Me.btnNext.Enabled = True

Else

Me.btnNext.Enabled = False

End If

End Sub

Sub NextIamge(ByRef Idx As Integer)

If Idx ImgNum Then

Idx += 1

Else

Exit Sub

End If

DisplayImage(Idx)

End Sub

Sub PerviousIagme(ByRef Idx As Integer)

If Idx 1 Then

Idx -= 1

Else

Exit Sub

End If

DisplayImage(Idx)

End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

Try

NextIamge(CurIdx)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click

OpenFiles()

End Sub

Private Sub btnPervious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPervious.Click

Try

PerviousIagme(CurIdx)

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

End Class

vb.net 怎么执行一个excel文件,仅是打开

vb.net没用过,vb6.0的话可以用getobject这种方法,你可以改改试试,看能不能用

Dim xlApp As Object

Set xlApp = GetObject(ExcelFileName).Application '获取Excel对象


标题名称:包含vb.net只打开一个的词条
文章来源:http://scyanting.com/article/hpjppi.html