473,586 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MyBase.New Question on Inherited UserControls

Hi

I have a UserControl called MyUserControl that has the following
constructor and InitializeCompo nent (automatically generated by VS):

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

Private Sub InitializeCompo nent()
components = New System.Componen tModel.Containe r()
End Sub

I then inherit from the control with MyInheritedUser Control and add a
text box to the control, again the constructor and InitializeCompo nent
is automatically generated by the VS:

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

End Sub

Private Sub InitializeCompo nent()
Me.TextBox1 = New System.Windows. Forms.TextBox
Me.SuspendLayou t()
'
'TextBox1
'
Me.TextBox1.Loc ation = New System.Drawing. Point(16, 32)
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Tab Index = 0
Me.TextBox1.Tex t = "TextBox1"
'
'MyInheritedCon trol
'
Me.Controls.Add (Me.TextBox1)
Me.Name = "MyInheritedCon trol"
Me.ResumeLayout (False)

End Sub

My company is implementing FxCop
(http://www.gotdotnet.com/team/fxcop/), a fantastic utility, but it
flags the following warning on the constructor in
MyInheritedUser Control:

"'MyInheritedCo ntrol..ctor()' contains a call chain that results in a
call to a virtual method defined by the class. Review the following
call stack for unintended consequences:
MyInheritedCont rol..ctor()MyIn heritedControl.
InitializeCompo nent()MyInherit edControl.set_T extBox1(
TextBox WithEventsValue )"

"Virtual methods defined on the class should not be called from
constructors. If a derived class has overridden the method, the
derived class version will be called (before the derived class
constructor is called)."

With a link to more information:

http://www.gotdotnet.com/team/fxcop/...orVirtual.html

Can someone explain what is actually wrong here please?

Thanks

Blu.
Nov 21 '05 #1
2 4036
* BluDog <ne**@nospam.bl udog.net> scripsit:
With a link to more information:

http://www.gotdotnet.com/team/fxcop/...orVirtual.html

Can someone explain what is actually wrong here please?


I found the description + sample really self-explaining. So I suggest
to take a closer look at it and play around with the sample provided in
the document referenced above.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
On 18 Aug 2004 12:40:55 +0200, hi************* **@gmx.at (Herfried K.
Wagner [MVP]) wrote:
* BluDog <ne**@nospam.bl udog.net> scripsit:
With a link to more information:

http://www.gotdotnet.com/team/fxcop/...orVirtual.html

Can someone explain what is actually wrong here please?


I found the description + sample really self-explaining. So I suggest
to take a closer look at it and play around with the sample provided in
the document referenced above.


I agree that it makes sense, but why does the code that VS adds
automatically break their own rules?
Nov 21 '05 #3

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

Similar topics

5
2418
by: DraguVaso | last post by:
Hi, I have my custom Inherited DataGrid. I override the OnPaint-event to speed up things and avoid flikkering using Double Buffering. To draw the normal things of the DataGrid I have to call the MyBase.OnPain(pe). But in my opinion it doesn't seem to be painted on the buffer. Everything works fine, but I think it should work better if my...
11
5280
by: Crirus | last post by:
I need to derive the Windows.Forms.Control 2 times so I design a class like this Public Class BMControl Inherits System.Windows.Forms.UserControl Public Class MapControl Inherits BMControl
9
2100
by: Dennis | last post by:
When a class (myownclass) inheirits another class, how can I get an object reference to the underlyng MyBase class instance from within myownclass. The base class has a method that I want to utilize in myownclass but the method is private and can't be inheirited. I need to utilize that base class method. -- Dennis in Houston
9
9242
by: Henry Padilla | last post by:
I realize that MyBase.MyBase is illegal, so how DO I get to the Parent of MyBase? In Short what is the VB equivalent of "::"? Example: Class Component Inherits Hashtable
1
1178
by: Support | last post by:
Hello: I have an application that I wish to update upon login via login script but since the application is in the start-up menu, I cannot override the exe, so, I wrote a function that iterates through all the instances of this application and kills the one instance that is not itself and then shuts itself down. The idea is that in a...
3
2089
by: b747_440 | last post by:
Dear Newsgroup, I'm an old VB6.0 developper who switched some time ago to VB.NET 2005. I really like that new Visual Studio. However, something is going wrong now and I can't figure out, what it is... I was playing around with UserControls which are inherited from standard .NET controls to make myself some transparent controls. Suddenly I...
4
11860
by: Sugan | last post by:
Hi, i came across custom usercontrols in VB 2005 and i'm not clear about the difference between "Me" and "MyBase". 1. What is the difference between the two keywords in a UserControl. 2. Even if they are different, is there any harm in using it interchangeably?
4
4107
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a user control that is designed as below. I am creating these User Controls Dynamically in another form. They are multiple types of User Controls all with a common Interface so I can use a Factory to create them all in a generic way. The problem is that if I create a IMyInterface - I cannot access the derived UserControl...
0
902
by: Phill W. | last post by:
OK, so VB'2005 let's you build whizzo UserControls with all that Anchoring and Docking stuff taking care of the layout, so you don't have to hard-code it all anymore. But ... When you then /inherit/ from that UserControl, how in Blue Blazes do you persuade the Forms Designer /not/ to suspend the layout events that keep the base Control...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.