Page 1 of 2

Enable Disable Dropshadow With Checkbox

Posted: Thu Jul 05, 2012 12:20 am
by mikethedj4
What I'm trying to achieve is simple. Form1 has a dropshadow by default, and I want to enable/disable it using a checkbox in Form2.

I've always done the shadow using the following...
Code: Select all
    Private Const CS_DROPSHADOW As Integer = 131072
    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim Shadow As CreateParams = MyBase.CreateParams
            Shadow.ClassStyle = Shadow.ClassStyle Or CS_DROPSHADOW
            Return Shadow
        End Get
    End Property
Anyway that I can get the above to work in the below for enable/disabling the shadow using a checkbox?
Code: Select all
        If CamShadow.Checked Then
            
        Else

        End If

Re: Enable Disable Dropshadow With Checkbox

Posted: Thu Jul 05, 2012 5:20 pm
by clanc789
You should place that code:
Code: Select all
        If CamShadow.Checked Then
            
        Else

        End If
in a timer with:
Code: Select all
 enabled = true
interval = 1
This way it keeps checking.

Re: Enable Disable Dropshadow With Checkbox

Posted: Thu Jul 05, 2012 7:00 pm
by un kn0 wn
Here try this:
Code: Select all
Public Class Form1

    Public Function ChangeShadow(ByVal enable As Boolean)
        Const CS_DROPSHADOW As Integer = 131072
        Dim Shadow As CreateParams = MyBase.CreateParams

        If enable Then
            'Your code for enabling the shadow.
        Else
            'Your code for disabling the shadow.
        End If

        Return Shadow

    End Function

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        ChangeShadow(CheckBox1.Checked)
    End Sub

Re: Enable Disable Dropshadow With Checkbox

Posted: Thu Jul 05, 2012 7:21 pm
by MrAksel
Guys the problem is that the CreateParams property is only called once; when the window (form) is created. Its not something you can just change at runtime. I've been searching for a while now, but I haven't found any solution :(

Re: Enable Disable Dropshadow With Checkbox

Posted: Fri Jul 06, 2012 7:01 am
by Dummy1912
sound maybe stupid but what about the '_HandleCreated function ?

Re: Enable Disable Dropshadow With Checkbox

Posted: Fri Jul 06, 2012 9:39 am
by MrAksel
Code: Select all
Private Const CS_DROPSHADOW As Integer = &H20000
Private Shadow As Boolean = False

Protected Overrides ReadOnly Property CreateParams() As CreateParams
	Get
		Dim p As CreateParams = MyBase.CreateParams

		If Shadow Then
			p.ClassStyle = p.ClassStyle Or CS_DROPSHADOW
		ElseIf (p.ClassStyle And CS_DROPSHADOW) <> 0 Then
			p.ClassStyle -= CS_DROPSHADOW
		End If

		Return p
	End Get
End Property

Private Sub checkBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
	Shadow = checkBox1.Checked
	RecreateHandle()
End Sub
This works on my computer. The shadow is a bit weird, but its maybe just my settings

Re: Enable Disable Dropshadow With Checkbox

Posted: Fri Jul 06, 2012 10:25 pm
by Vikhedgehog
MrAksel wrote:
Guys the problem is that the CreateParams property is only called once; when the window (form) is created. Its not something you can just change at runtime. I've been searching for a while now, but I haven't found any solution :(
Maybe make it reload the form?

Re: Enable Disable Dropshadow With Checkbox

Posted: Sat Jul 07, 2012 4:42 am
by mikethedj4
MrAksel wrote:
Code: Select all
Private Const CS_DROPSHADOW As Integer = &H20000
Private Shadow As Boolean = False

Protected Overrides ReadOnly Property CreateParams() As CreateParams
	Get
		Dim p As CreateParams = MyBase.CreateParams

		If Shadow Then
			p.ClassStyle = p.ClassStyle Or CS_DROPSHADOW
		ElseIf (p.ClassStyle And CS_DROPSHADOW) <> 0 Then
			p.ClassStyle -= CS_DROPSHADOW
		End If

		Return p
	End Get
End Property

Private Sub checkBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
	Shadow = checkBox1.Checked
	RecreateHandle()
End Sub
This works on my computer. The shadow is a bit weird, but its maybe just my settings
Anyway I can call this from a separate form? I tried, but no luck.
DropShadowToggle.zip

Re: Enable Disable Dropshadow With Checkbox

Posted: Sat Jul 07, 2012 10:07 am
by Codex
Mike, try replacing MyBase.CreateParams with Form2.CreateParams. I have no idea if it works, didn't test it.

Re: Enable Disable Dropshadow With Checkbox

Posted: Sat Jul 07, 2012 12:00 pm
by mikethedj4
Did that, and got...
Code: Select all
Error	1	Overload resolution failed because no 'CreateParams' is accessible.	C:\Users\Michael\documents\visual studio 2010\Projects\DropShadowToggle\DropShadowToggle\Form1.vb	13	37	DropShadowToggle