473,805 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overload NEW on Form?

Tom
How is the best way to overload the New constructor for a form? For
instance, I want to be able to pass things to the constructor, or just
default with the plain New. Maybe say something like:

Dim x as New MyForm(parm01, parm02)

Should I just override new? What is the best way to do this for a form? (The
reason I am asking is it appears that the New for a form does a number of
things, like initialize controls, etc)

Tom
Nov 20 '05 #1
2 3466
On Fri, 7 Nov 2003 16:16:31 -0500, Tom wrote:
How is the best way to overload the New constructor for a form? For
instance, I want to be able to pass things to the constructor, or just
default with the plain New. Maybe say something like:

Dim x as New MyForm(parm01, parm02)

Should I just override new? What is the best way to do this for a form? (The
reason I am asking is it appears that the New for a form does a number of
things, like initialize controls, etc)

Tom


Just overload but call the other constructor. Note that I used the
reserved word MyClass. You can also just call New().

Public Sub New(arg1 As integer, arg2 As string)
MyClass.New() 'Call the original constructor
'Do stuff with the arguments here.
End Sub

But there are other ways to do it as well. Perhaps someone knows a better
way?

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #2
* "Tom" <to*@nospam.com > scripsit:
How is the best way to overload the New constructor for a form? For
instance, I want to be able to pass things to the constructor, or just
default with the plain New. Maybe say something like:

Dim x as New MyForm(parm01, parm02)

Should I just override new? What is the best way to do this for a form? (The
reason I am asking is it appears that the New for a form does a number of
things, like initialize controls, etc)


Just define a parameterized constructor:

\\\
Public Sub New(ByVal i As Integer, ByVal j As Integer)
MyBase.New() ' Call parameterless ctor of the base class.
m_i = i
m_j = j
Nov 20 '05 #3

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

Similar topics

8
1578
by: David Sachs | last post by:
The following program illustrates an interesting effect of the way C++ resolves function overloading. I have verified with a member of the C++ stardard committee that the output shown is correct. *********************************Program******************************** #include <iostream> using std::cout;
1
2068
by: Piotre Ugrumov | last post by:
I'm following your help. I have written the overload of the operator <<. This overload work! :-) But I have some problem with the overload of the operator >>. I have written the overload of this least operator for the class Person, but I don't know how write the overload for a class that derived from the class Person. The overload of << in Person is this: ostream & operator<<(ostream &out, const Persona &p){ out<<p.getNome()<<"...
3
2252
by: Piotre Ugrumov | last post by:
I have done the overload on the operator >> and << in the class Attore. These 2 overload work correctly. I have done the overload of the same overload in the class Film. The class film ha inside an array of pointer to Attore. I have written these overload in these ways. the overload of << work correctly the overload of >> I don't know. I compile the class correctly, when I insert a film through the operator >> I don't receive error, but...
13
44212
by: some one | last post by:
I know that C++ lets you overload functions, but how do I overload functions in C?
1
1320
by: Eric Cadwell | last post by:
I'm inheriting from From, but my Show method requires a parameter, so I define an overloaded Show method: public void Show(Form Owner) Now I get intellisence for two methods: Control.Show() MyForm.Show(Form Owner) I need to hide Control.Show(). I tried hiding it... private new void Show()
17
2515
by: Chris | last post by:
To me, this seems rather redundant. The compiler requires that if you overload the == operator, you must also overload the != operator. All I do for the != operator is something like this: public static bool operator !=(MyType x, MyType y) { return !(x == y); } That way the == operator handles everything, and extra comparing logic isn't
2
3299
by: sparks | last post by:
I had the bright idea of using if/else to call different constructors based on a web form and what the user entered. ======================================= IF I DECLARE this here everything works fine... ====>>>> Member member = new Member(); ======================================= public void Button1_Click(object sender,System.EventArgs e) { if (ContractNumber.Text =="")
3
1785
by: dave | last post by:
Hi , I am trying to avoid behavior where everytime Button1Click is fired a new form is exposed. How can I keep the f object alive in the event so that a new object does not have to be created? Could I overload the Button Click event to accept the Form1 object?
5
3701
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar explicitly takes a pointer-to-member with no parameters, why is the lookup for the overloaded function not able to use the number of arguments to determine the appropriate function? Is there a relevant portion of the standard that governs the...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10614
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.