Re: Expandable Props - Minor Drawing/Coloring Issue
Having them in separate class files or not should make no difference (they're all separate in mine.)
So in the GradientPanel class you have the GradientStyle property and it's in the
Set portion of that property where you want to call Invalidate to have the Panel redraw
itself when you change one of the component properties of GradientStyle.
Re: Expandable Props - Minor Drawing/Coloring Issue
Not quite. The GradientPanel class (inherits Panel) just has the OnPaint override and thats all. Then in the GradientStyle class I
have the expandable properties. shouldnt the 3 props be in the GradientPanel? Basically, the GradientPanel &
GradientStyle classes should be merged in order to get the MyBase or Me for invalidating?
Re: Expandable Props - Minor Drawing/Coloring Issue
I think we're getting crossed-wires here somewhere.
If GradientPanel is going to have a property called GradientStyle
which is of the type GradientStyle, then it will have a Get and Set accessor,
that's where you call the Invalidate, not in either the GradientStyle or GradientStyleConverter classes.
Here's a mock up of what your GradientPanel control would look like:
VB Code:
Imports System.ComponentModel
Public Class MyControl
Inherits Panel
Private _gradientStyle As New GradientStyle
' This is the property your control exposes that uses the
' Expandable class type and converter
<Browsable(True), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property GradientStyle() As GradientStyle
Get
Return _gradientStyle
End Get
Set(ByVal Value As GradientStyle)
_gradientStyle = Value
' Need to call Invalidate Here to cause your
' control to redraw itself when the expandable
' properties change
Me.Invalidate()
End Set
End Property
' Implement separate "ShouldSerialize" and "Reset" methods because of the
' Complex nature of the expandable property type
Private Function ShouldSerializeGradientStyle() As Boolean
' Return True to indicate the value is not default and should be persisted
Return Not (_gradientStyle.GradientMode = LinearGradientMode.Mode1 AndAlso _gradientStyle.PanelColor1.Equals(Color.Red) AndAlso _gradientStyle.PanelColor2.Equals(Color.Blue))
End Function
Private Sub ResetGradientStyle()
' Reset the property to a default value
_gradientStyle = New GradientStyle
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
' This is where you use your control settings to redraw your control
MyBase.OnPaint(e)
Select Case _gradientStyle.GradientMode
Case LinearGradientMode.Mode1
e.Graphics.FillRectangle(Brushes.Red, New Rectangle(New Point(0, 0), Me.Size))
Case LinearGradientMode.Mode2
e.Graphics.FillRectangle(Brushes.Green, New Rectangle(New Point(0, 0), Me.Size))
Case LinearGradientMode.Mode3
e.Graphics.FillRectangle(Brushes.Blue, New Rectangle(New Point(0, 0), Me.Size))
End Select
End Sub
End Class
Regards,
- Aaron.
Re: Expandable Props - Minor Drawing/Coloring Issue
Thats what I thought it should be like. Instead I had two of the classes split. so thats why I dont have the me or
mybase when setting the props?
I am going to make the necessary mods and it will probably take a while since I dont want to mess it up and
loose what I have got so far. Its usually a pain to rollback source safe unless I do it to a new directory.
Thanks for all your help. I will post back when I finish the changes :thumb:
Re: Expandable Props - Minor Drawing/Coloring Issue
Ok, I got the CreateInstance procedure updated so I thought I would post it. I had to do a few mods since I am
using Option Strict and Explicit ON.
VB Code:
Public Overloads Overrides Function CreateInstance(ByVal context As System.ComponentModel.ITypeDescriptorContext, _
ByVal propertyValues As System.Collections.IDictionary) As Object
' Create a new instance of the Gradient Style
' with the supplied property values
Dim obj1 As Object = propertyValues("GradientMode")
Dim obj2 As Object = propertyValues("PanelColor1")
Dim obj3 As Object = propertyValues("PanelColor2")
If obj1 Is Nothing Then obj1 = LinearGradientMode.ForwardDiagonal
If obj2 Is Nothing Then obj2 = Color.Red
If obj3 Is Nothing Then obj3 = Color.Blue
Dim gs As New GradientStyle
gs.GradientMode = CType(obj1, LinearGradientMode)
gs.PanelColor1 = CType(obj2, Color)
gs.PanelColor2 = CType(obj3, Color)
Return gs
End Function
I'm "still" working on the modifications to merge the two classes together.
Hopefully this will be done real soon. :)
Re: Expandable Props - Minor Drawing/Coloring Issue
Aaron, you are a true Guru!!!
Thanks for solving the Reset issue and drawing issue!
I am implementing the changes tonight and can hopefully move forward "finally"!!!
Many Thanks,
Robert
Re: Expandable Props [RESOLVED]
Hey,
Very quick first post to thank you for this ridiculously helpful post - after 2 days of trawling the web, this solved my problem in a couple of hours (and it would have been even quicker if I'd read the whole post, rather than trying to second guess what was coming...).
Thanks again, and VBForums is my new favourite forum!
Dave.