OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
Go Back  Xtreme Visual Basic Talk > > > OverRiding BackColor of a UserControl


Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2012, 05:12 PM
Gruff's Avatar
GruffOverRiding BackColor of a UserControl Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default OverRiding BackColor of a UserControl


I am writing a small usercontrol that contains several labels and blank areas of the usercontrol.

I want to override the BackColor property such that I can set the back color of the controls as well as the backcolor of the usercontrol to the same color.

When I use the following property
Code:
Public Overrides Property BackColor As Color Get Return Me.BackColor End Get Set(value As Color) lblTitle.BackColor = value lblToggle.BackColor = value Me.BackColor = value End Set End Property

I get a recursive error when using Me.BackColor

What is the proper way to do this.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #2  
Old 10-24-2012, 06:54 PM
PlausiblyDamp's Avatar
PlausiblyDampOverRiding BackColor of a UserControl PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Is MyBase.BackColor the one you are after? Failing that you might just want to create your own class level variable to hold the colour and store / retrieve it from there.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 10-25-2012, 07:40 AM
AtmaWeapon's Avatar
AtmaWeaponOverRiding BackColor of a UserControl AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'm pretty sure PD is right about the MyBase. You also might consider just doing a simple override and using DefaultValueAttribute to make it play nice in the designer.

Code:
<DefaultValue(Color.Whatever)>
Public Overrides Property BackColor As Color
    Get
        Return MyBase.BackColor
    End Get
    Set(ByVal value As Color)
        lblTitle.BackColor = value
        lblToggle.BackColor =  value
        MyBase.BackColor = value
    End Set
End Property
I think you also have to set it in your control's constructor. Not 100% on that. It's one of those things I test on the fly rather than memorize.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 10-25-2012, 08:36 AM
DrPunk's Avatar
DrPunkOverRiding BackColor of a UserControl DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

You could override OnBackColorChanged and act on that instead.
__________________
There are no computers in heaven!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
 
OverRiding BackColor of a UserControl
OverRiding BackColor of a UserControl
 
-->