473,395 Members | 1,891 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,395 software developers and data experts.

C# override syntax

I wonder if it's possible to do something like this:

public class someClass {

Panel pnl;

public someClass() {
pnl = new Panel();
}
public override pnl.OnPaintBackground(...) {
}

}
Nov 16 '05 #1
5 6661
Hi,

Your class should be derived from Panel:

public class someClass :Panel
{
public someClass ()
{ }

protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground (pevent);
}
}

Best regards,
Peter Jausovec
(http://blog.jausovec.net)
Peder Y" <1@nowhere.com> je napisal v sporocilo
news:uS*************@TK2MSFTNGP11.phx.gbl ...
I wonder if it's possible to do something like this:

public class someClass {

Panel pnl;

public someClass() {
pnl = new Panel();
}
public override pnl.OnPaintBackground(...) {
}

}

Nov 16 '05 #2
Peder Y <1@nowhere.com> wrote:
I wonder if it's possible to do something like this:

public class someClass {

Panel pnl;

public someClass() {
pnl = new Panel();
}
public override pnl.OnPaintBackground(...) {
}

}


Nope. You have to create your own subclass of Panel which overrides
OnPaintBackground, and then instantiate that instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hi Peder,

As far as I know this is not possible. You will need to inherit the panel.

public class someClass
{
MyPanel pnl;

public someClass()
{
pnl = new MyPanel();
}
}

public class MyPanel : Panel
{
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
}
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4
Ok, thanks yall!

I wanted to avoid inheriting the class itself, but it looks like I have
no other choice then...

- P -
Peder Y wrote:
I wonder if it's possible to do something like this:

public class someClass {

Panel pnl;

public someClass() {
pnl = new Panel();
}
public override pnl.OnPaintBackground(...) {
}

}

Nov 16 '05 #5
Peder Y <1@nowhere.com> wrote:
I wanted to avoid inheriting the class itself, but it looks like I have
no other choice then...


Note that you /still/ can use your wrapper class if you're going for
encapsulation:

public class SomeClass
{
MyInheritedPanel panel;

public someClass() {
panel = new MyInheritedPanel();
}
}
Nov 16 '05 #6

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

Similar topics

14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
2
by: Adriano Coser | last post by:
Hello. After I converted my .net code to the new VC2005 syntax I started to get C4490 on my ExpandableObjectConverter subclass overrides. The GetProperties method is no longer called by the...
1
by: paulsmith5 | last post by:
Hi, I've never developed in CSharp before and I'm trying to adapt an existing user control written in CSharp. The user control inherits from the DataGridColumn. I'd like for one of my controls...
52
by: Jim Langston | last post by:
I wanted to do an operator override for but couldnt' figure out the syntax. I tried this (code that doesn't compile commented out with //: class CMyBitmap { public: CMyBitmap( int Rows, int...
2
by: mjansen.merge.emed | last post by:
Is there a way to override inline within the <bodya style of an element but not do it with a style attribute on the element? I know CSS Inheritance works for some styles, but doesn't appear to...
1
by: Bern McCarty | last post by:
I cannot figure out how to do this. It seems that the only way to introduce the "override" keyword into the mix is to give up on the simple property syntax. It seems that the designers of C++/CLI...
5
by: =?Utf-8?B?V0o=?= | last post by:
If I have a class A that has a virtual public function DoSomething() Class A { public: virtual void DoSomething(); } then I override this function to protected is class B Class B: public...
5
by: Tony Johansson | last post by:
Hello! Here I have an Interface called ITest and a class called MyClass which derive this intrface. As you can see I don't implement this method myTest in class MyClass because i use the...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.