473,406 Members | 2,633 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,406 software developers and data experts.

MyBase.New Question on Inherited UserControls

Hi

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

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call

End Sub

Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

I then inherit from the control with MyInheritedUserControl and add a
text box to the control, again the constructor and InitializeComponent
is automatically generated by the VS:

Public Sub New()
MyBase.New()

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

'Add any initialization after the InitializeComponent() call

End Sub

Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox1"
'
'MyInheritedControl
'
Me.Controls.Add(Me.TextBox1)
Me.Name = "MyInheritedControl"
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
MyInheritedUserControl:

"'MyInheritedControl..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:
MyInheritedControl..ctor()MyInheritedControl.
InitializeComponent()MyInheritedControl.set_TextBo x1(
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 4023
* BluDog <ne**@nospam.bludog.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.bludog.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
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...
11
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
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...
9
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
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...
3
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...
4
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....
4
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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.