473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Subclassing question

How can you subclass a control and override just a sub-property like
Font.Size?

I was trying to do something like this:

namespace Compeat.Common.Controls
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.Font.Size = 12;
}

[DefaultValue(12)]
public override float Font.Size
{
get { return base.Font.Size; }
set { base.Font.Size = value; }
}
}
}

TIA,

Mike Rodriguez
Mar 21 '06 #1
4 4682
AFAIK, you can't. You'll need to override the entire Font property and pick
up the other values from base.Font.

--
Tim Wilson
..NET Compact Framework MVP

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:u9**************@TK2MSFTNGP11.phx.gbl...
How can you subclass a control and override just a sub-property like
Font.Size?

I was trying to do something like this:

namespace Compeat.Common.Controls
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.Font.Size = 12;
}

[DefaultValue(12)]
public override float Font.Size
{
get { return base.Font.Size; }
set { base.Font.Size = value; }
}
}
}

TIA,

Mike Rodriguez

Mar 21 '06 #2
Hi Tim,

I could do that, but how would I then set a default Font value? The
DefaultValue attribute seems to only want to accept static values.

Thanks,

Mike
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:uI**************@TK2MSFTNGP11.phx.gbl...
AFAIK, you can't. You'll need to override the entire Font property and
pick
up the other values from base.Font.

--
Tim Wilson
.NET Compact Framework MVP

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:u9**************@TK2MSFTNGP11.phx.gbl...
How can you subclass a control and override just a sub-property like
Font.Size?

I was trying to do something like this:

namespace Compeat.Common.Controls
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.Font.Size = 12;
}

[DefaultValue(12)]
public override float Font.Size
{
get { return base.Font.Size; }
set { base.Font.Size = value; }
}
}
}

TIA,

Mike Rodriguez


Mar 21 '06 #3
There are a couple ways to do this. Let's assume, for example, that you
wanted to have a default value of Microsoft Sans Serif, 12 pt, Bold. Then
you could do something like this.

private Font _font = new Font("Microsoft Sans Serif", 12.0F,
FontStyle.Bold);

[DefaultValue(typeof(Font), "Microsoft Sans Serif, 12pt, style=Bold")]
public override Font Font
{
get
{
return _font;
}
set
{
_font = value;
}
}

If you could not get the DefaultValue attribute to work in some situation,
then you could always use the ShouldSerializeXXX and ResetXXX methods.
http://msdn.microsoft.com/library/de...setmethods.asp

--
Tim Wilson
..NET Compact Framework MVP

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Hi Tim,

I could do that, but how would I then set a default Font value? The
DefaultValue attribute seems to only want to accept static values.

Thanks,

Mike
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:uI**************@TK2MSFTNGP11.phx.gbl...
AFAIK, you can't. You'll need to override the entire Font property and
pick
up the other values from base.Font.

--
Tim Wilson
.NET Compact Framework MVP

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:u9**************@TK2MSFTNGP11.phx.gbl...
How can you subclass a control and override just a sub-property like
Font.Size?

I was trying to do something like this:

namespace Compeat.Common.Controls
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.Font.Size = 12;
}

[DefaultValue(12)]
public override float Font.Size
{
get { return base.Font.Size; }
set { base.Font.Size = value; }
}
}
}

TIA,

Mike Rodriguez



Mar 21 '06 #4
Thanks!!

Mike
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:Of*************@TK2MSFTNGP09.phx.gbl...
There are a couple ways to do this. Let's assume, for example, that you
wanted to have a default value of Microsoft Sans Serif, 12 pt, Bold. Then
you could do something like this.

private Font _font = new Font("Microsoft Sans Serif", 12.0F,
FontStyle.Bold);

[DefaultValue(typeof(Font), "Microsoft Sans Serif, 12pt, style=Bold")]
public override Font Font
{
get
{
return _font;
}
set
{
_font = value;
}
}

If you could not get the DefaultValue attribute to work in some situation,
then you could always use the ShouldSerializeXXX and ResetXXX methods.
http://msdn.microsoft.com/library/de...setmethods.asp

--
Tim Wilson
.NET Compact Framework MVP

"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
Hi Tim,

I could do that, but how would I then set a default Font value? The
DefaultValue attribute seems to only want to accept static values.

Thanks,

Mike
"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in
message
news:uI**************@TK2MSFTNGP11.phx.gbl...
> AFAIK, you can't. You'll need to override the entire Font property and
> pick
> up the other values from base.Font.
>
> --
> Tim Wilson
> .NET Compact Framework MVP
>
> "Michael Rodriguez" <mi**@nospamforme.com> wrote in message
> news:u9**************@TK2MSFTNGP11.phx.gbl...
>> How can you subclass a control and override just a sub-property like
>> Font.Size?
>>
>> I was trying to do something like this:
>>
>> namespace Compeat.Common.Controls
>> {
>> public class MyTextBox : TextBox
>> {
>> public MyTextBox()
>> {
>> this.Font.Size = 12;
>> }
>>
>> [DefaultValue(12)]
>> public override float Font.Size
>> {
>> get { return base.Font.Size; }
>> set { base.Font.Size = value; }
>> }
>> }
>> }
>>
>> TIA,
>>
>> Mike Rodriguez
>>
>>
>
>



Mar 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Roy H. Berger | last post by:
If I want to subclass ConfigParser and changed the optionxform method to not return things in lower case wouldn't I just need the following code in my subclasss module? from ConfigParser import...
2
by: BJörn Lindqvist | last post by:
A problem I have occured recently is that I want to subclass builtin types. Especially subclassing list is very troublesome to me. But I can't find the right syntax to use. Take for example this...
11
by: Brent | last post by:
I'd like to subclass the built-in str type. For example: -- class MyString(str): def __init__(self, txt, data): super(MyString,self).__init__(txt) self.data = data
3
by: alotcode | last post by:
Hello: What is 'interprocess subclassing'? To give more context, I am writing in reference to the following remark: With the advent of the Microsoft Win32 API, interprocess subclassing was...
5
by: Pieter Linden | last post by:
Hi, This question refers sort of to Rebecca Riordan's article on Access web about subclassing entities: http://www.mvps.org/access/tables/tbl0013.htm How practical is this? I am writing a...
7
by: Guinness Mann | last post by:
I have a class that I use throughout my application, and I store collections of my class in an ArrayList. To avoid some really ugly casting I'd like to subclass ArrayList to get a typed version. ...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
10
by: Frank Millman | last post by:
Hi all I recently posted a question about subclassing. I did not explain my full requirement very clearly, and my proposed solution was not pretty. I will attempt to explain what I am trying to...
16
by: manatlan | last post by:
I've got an instance of a class, ex : b=gtk.Button() I'd like to add methods and attributes to my instance "b". I know it's possible by hacking "b" with setattr() methods. But i'd like to do...
5
by: Ray | last post by:
Hi all, I am thinking of subclassing the standard string class so I can do something like: mystring str; .... str.toLower (); A quick search on this newsgroup has found messages by others
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.