I've recently gotten over the hurdle of a Borderless form that doesn't show in the Taskbar to not be hidden when the user clicks the Show Desktop button in windows by using the SetParent API to make the windows all children of the desktop, but now I can't change the Opacity of the form, it throws an exception:
Here's the code I have:
Any ideas on how to keep the windows children of the desktop but still allow the opacity to be something other than 1.0?
VB.NET:
System.ComponentModel.Win32Exception was unhandled
ErrorCode=-2147467259
Message="The parameter is incorrect"
NativeErrorCode=87
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Form.UpdateLayered()
at System.Windows.Forms.Form.set_Opacity(Double value)
at ReminderNotes.NoteBase.set_Opacity(Double value) in C:\Users\IBM_ADMIN\Desktop\Program Stuffs\ReminderNotes\ReminderNotes\NoteBase.vb:line 255
at ReminderNotes.NoteForm.TransparencyToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\IBM_ADMIN\Desktop\Program Stuffs\ReminderNotes\ReminderNotes\NoteForm.vb:line 254
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at ReminderNotes.MainModule.Main() in C:\Users\IBM_ADMIN\Desktop\Program Stuffs\ReminderNotes\ReminderNotes\MainApp.vb:line 62
InnerException:
VB.NET:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Public Shared Function SetParent(ByVal child As IntPtr, ByVal parent As IntPtr) As Integer
End Function
Public Sub New()
MyBase.New()
MyBase.FormBorderStyle = Windows.Forms.FormBorderStyle.None
MyBase.ShowInTaskbar = False
MyBase.Size = New Size(180I, 165I)
MyBase.MinimumSize = New Size(180I, 120I)
MyBase.AutoScroll = True
SetParent(Me.Handle, FindWindow("progman", Microsoft.VisualBasic.vbNullString))
End Sub
Private Sub TransparencyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Opacity values are stored as "1", "0.9", etc in the tag property
Me.Opacity = CDbl(CType(sender, ToolStripMenuItem).Tag.ToString)
End Sub