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.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
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...
I've always done the shadow using the following...
Code: Select all
Anyway that I can get the above to work in the below for enable/disabling the shadow using a checkbox?
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
Code: Select all
If CamShadow.Checked Then
Else
End If
You should place that code:
Code: Select all
in a timer with:
If CamShadow.Checked Then
Else
End If
Code: Select all
This way it keeps checking. enabled = true
interval = 1
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
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
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]()
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!

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
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
Code: Select all
This works on my computer. The shadow is a bit weird, but its maybe just my settingsPrivate 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
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]()
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!

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?
MrAksel wrote:Anyway I can call this from a separate form? I tried, but no luck.Code: Select allThis works on my computer. The shadow is a bit weird, but its maybe just my settingsPrivate 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
You do not have the required permissions to view the files attached to this post.
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
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
Copyright Information
Copyright © Codenstuff.com 2020 - 2023