0
已經在其他形式/應用程序沒有任何困難使用此。然而,在這個單表格應用程序,它似乎並沒有工作:ShowWithoutActivation神祕不工作
Imports System.IO
Public Class CPWBBackground
Dim _selectedScreenNo As Integer
Dim _screenWidth As Integer = 400
Dim _screenHeight As Integer = 300
Dim _CPWIni As New Dictionary(Of String, String)
Dim clArgs() As String = Environment.GetCommandLineArgs()
Protected Overloads Overrides ReadOnly Property ShowWithoutActivation() As Boolean
Get
Return True
End Get
End Property
Private Sub FromActivate() Handles Me.Activated
MsgBox("blurp")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
'exe [1] [2]/[3] [4]
' 1: ScreenNumber
' 2: ImgFile
' 3: Screen Width
' 4: Screen Height
' Me.Opacity = 0
'TestFileExists
If Not File.Exists(clArgs(2)) Then
Debug.WriteLine("File doesn't exist. Closing..")
Application.Exit()
End If
_selectedScreenNo = clArgs(1)
'Set vars
Try
_screenWidth = Screen.AllScreens(_selectedScreenNo).Bounds.Width
_screenHeight = Screen.AllScreens(_selectedScreenNo).Bounds.Height
'Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.Location = New Point(0, 0)
If clArgs.Count > 3 Then
If clArgs.Count < 5 Then
'MsgBox("There should be either 2 or 4 arguments - only 3 - please check your command line.")
Debug.WriteLine("Not enough args. Closing.")
Application.Exit()
Else
_screenWidth = clArgs(3)
_screenHeight = clArgs(4)
End If
End If
Me.Size = New Size(_screenWidth, _screenHeight)
Me.ShowInTaskbar = False
PictureBox1.Size = New Size(_screenWidth, _screenHeight)
Me.Location = Screen.AllScreens(_selectedScreenNo).Bounds.Location + New Point(0, 0)
Dim fs As FileStream
Dim FreedImage As Image
fs = New FileStream(clArgs(2), FileMode.Open)
FreedImage = Image.FromStream(fs)
fs.Close()
PictureBox1.BackgroundImage = FreedImage
PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
Catch ex As Exception
Application.Exit()
End Try
End Sub
Private Sub CPWBBackground_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
NotifyIcon1.Dispose()
End Sub
Private Sub CloseToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CloseToolStripMenuItem.Click
Me.Close()
End Sub
End Class
我得到「blurp」每次。表單設計師的'最高'屬性是錯誤的。有任何想法嗎?
太多無關的代碼。它有問題,Load事件中的ShowInTaskbar賦值已經足以防止它被激活。水晶球說,你點擊窗口,從而激活它。 http://stackoverflow.com/help/mcve –
感謝漢斯,但是「最小」和「完整」之間存在某種緊張關係,因爲我完全不知道問題出在哪裏 - 因此很難將其簡化爲簡化/蒸餾示例。不,這不是我點擊表格。表單在沒有任何用戶交互的情況下激活。另外,我正在嘗試實現未激活的窗體,未激活窗體。 – stigzler