*** Refreshing control at design time when property changed? 
Author Message
 *** Refreshing control at design time when property changed?

I'm creating a usercontrol in VB.NET and certain properties I'm adding
are affecting the display of the control at design-time.  How can I make
the control refresh itself during design time when a property changes?

I can put code in the PAINT event which is called whenever the control is
resized or moved, so how can I call that in my own properties?  I cannot
just call PAINT, because my actual properties aren't getting run, just
the values are being stored (it seems).

Any thoughts?



Sun, 01 May 2005 12:42:07 GMT  
 *** Refreshing control at design time when property changed?
All you need to do is call the refresh method when the property changes...

I did the following:
1) Create a New Windows Application
2) Create a UserControl and add the following code
    Dim m_Color As Color = Color.Black
    Public Property MyColor() As Color
        Get
            Return m_Color
        End Get
        Set(ByVal Value As Color)
            m_Color = Value
            Me.Refresh()
        End Set
    End Property

    Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim b As Brush = New SolidBrush(m_Color)
        e.Graphics.DrawString("My Color is: " & m_Color.ToString, Me.Font,
b, 0, 0)
        b.Dispose()
    End Sub
3) Build the solution
4) Switch to Form1 designer
5) Add the User Control to the form.
6) Select the control and change the MyColor property.

Thanks
Gary Spangler [MS]

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I'm creating a usercontrol in VB.NET and certain properties I'm adding
> are affecting the display of the control at design-time.  How can I make
> the control refresh itself during design time when a property changes?

> I can put code in the PAINT event which is called whenever the control is
> resized or moved, so how can I call that in my own properties?  I cannot
> just call PAINT, because my actual properties aren't getting run, just
> the values are being stored (it seems).

> Any thoughts?



Mon, 02 May 2005 04:44:34 GMT  
 *** Refreshing control at design time when property changed?
Well...

This example works.  And in fact, when I added a read-only property, it too
was refreshed in the property window when a change is made (sort of what I'm
trying to do).

The problem appears to be due to that I am Creating a base class (child of
UserControl) which has a lot of the core functionality I need and then two
derived classes from this base class.  So these properties are in there on
the base class, but being called on the derived class.  I think this
indirectness is causing the problem.  Thoughts?



Quote:
> All you need to do is call the refresh method when the property changes...

> I did the following:
> 1) Create a New Windows Application
> 2) Create a UserControl and add the following code
>     Dim m_Color As Color = Color.Black
>     Public Property MyColor() As Color
>         Get
>             Return m_Color
>         End Get
>         Set(ByVal Value As Color)
>             m_Color = Value
>             Me.Refresh()
>         End Set
>     End Property

>     Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As
> System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
>         Dim b As Brush = New SolidBrush(m_Color)
>         e.Graphics.DrawString("My Color is: " & m_Color.ToString, Me.Font,
> b, 0, 0)
>         b.Dispose()
>     End Sub
> 3) Build the solution
> 4) Switch to Form1 designer
> 5) Add the User Control to the form.
> 6) Select the control and change the MyColor property.

> Thanks
> Gary Spangler [MS]

> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.


> > I'm creating a usercontrol in VB.NET and certain properties I'm adding
> > are affecting the display of the control at design-time.  How can I make
> > the control refresh itself during design time when a property changes?

> > I can put code in the PAINT event which is called whenever the control
is
> > resized or moved, so how can I call that in my own properties?  I cannot
> > just call PAINT, because my actual properties aren't getting run, just
> > the values are being stored (it seems).

> > Any thoughts?



Mon, 09 May 2005 13:10:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Saving properties of ActiveX control from design time to run time

2. Design-time properties in Run-time Controls

3. Changing property default values at design time

4. Preserving the values of a property, changed in design time

5. Changing design time properties during execution

6. Changing design time properties at runtime

7. Custom Control with Design Time only properties

8. DBCombo Control Crashes System at Design Time (Record Source Property)

9. Setting design-time properties of UserControl constituent controls

10. Specifying design-time properties in ActiveX controls

11. ActiveX Control Design-Time Properties

12. Design Time Controls Properties

 

 
Powered by phpBB® Forum Software