Enable Disable Dropshadow With Checkbox

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
11 posts Page 1 of 2
Contributors
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

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
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

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.
Practice makes perfect!

VIP since: 6-10-2011
User avatar
un kn0 wn
VIP - Donator
VIP - Donator
Posts: 269
Joined: Mon Mar 29, 2010 6:12 pm

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
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

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 :(
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

sound maybe stupid but what about the '_HandleCreated function ?
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

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
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
Vikhedgehog
VIP - Donator
VIP - Donator
Posts: 812
Joined: Fri Nov 05, 2010 6:24 pm

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?
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

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
You do not have the required permissions to view the files attached to this post.
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Mike, try replacing MyBase.CreateParams with Form2.CreateParams. I have no idea if it works, didn't test it.
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

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
11 posts Page 1 of 2
Return to “Coding Help & Support”