Reputation: 993
Have used this in other forms/apps without any difficulties. However, in this single form application, it doesn't appear to be working:
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
I get "blurp" every time. 'Topmost' property in form desiginer is false. Any ideas?
Upvotes: 1
Views: 480
Reputation: 993
Well, that was random. The solution was to add me.hide
to the top of the me.load event.
Final working code (with some other bits tidied up):
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Hide()
'exe [1] [2] / [3] [4]
' 1: ScreenNumber
' 2: ImgFile
' 3: Screen Width
' 4: Screen Height
If Not File.Exists(clArgs(2)) Then
Debug.WriteLine("File doesn't exist. Closing..")
Application.Exit()
End If
_selectedScreenNo = clArgs(1)
_screenWidth = Screen.AllScreens(_selectedScreenNo).Bounds.Width
_screenHeight = Screen.AllScreens(_selectedScreenNo).Bounds.Height
Me.Location = Screen.AllScreens(_selectedScreenNo).Bounds.Location + New Point(0, 0)
If clArgs.Count > 3 Then
If clArgs.Count < 5 Then
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)
Dim fs As FileStream
Dim FreedImage As Image
fs = New FileStream(clArgs(2), FileMode.Open)
FreedImage = Image.FromStream(fs)
fs.Close()
Me.BackgroundImage = FreedImage
Me.BackgroundImageLayout = ImageLayout.Stretch
End Sub
Upvotes: 1