473,606 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a Form that has only one instance

Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0
Nov 20 '05 #1
4 2293
"Sumit" <vi*******@hotm ail.com> schrieb
Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0


I don't understand the question. I'd say: Don't create a second instance.

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Hi,

You could try something like this.

Public Class Form2
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "
Private Shared instance As Form2

Public Shared ReadOnly Property DefInstance() As Form2
Get
If instance Is Nothing Then instance = New Form2
Return instance
End Get
End Property
End Class

To use

Dim frm As Form2 = Form2.DefInstan ce
frm.ShowDialog( )

Ken
------------------
"Sumit" <vi*******@hotm ail.com> wrote in message
news:3e******** *************** *****@phx.gbl.. .
Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0

Nov 20 '05 #3
* "Sumit" <vi*******@hotm ail.com> scripsit:
Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0


How did you do that in VB6?

BTW: Singleton design pattern.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
add don't forget to set your constructor as private...
private sub New()
end sub

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:ev******** ******@tk2msftn gp13.phx.gbl...
Hi,

You could try something like this.

Public Class Form2
Inherits System.Windows. Forms.Form

#Region " Windows Form Designer generated code "
Private Shared instance As Form2

Public Shared ReadOnly Property DefInstance() As Form2
Get
If instance Is Nothing Then instance = New Form2
Return instance
End Get
End Property
End Class

To use

Dim frm As Form2 = Form2.DefInstan ce
frm.ShowDialog( )

Ken
------------------
"Sumit" <vi*******@hotm ail.com> wrote in message
news:3e******** *************** *****@phx.gbl.. .
Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0


Nov 20 '05 #5

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

Similar topics

3
1176
by: Peteroid | last post by:
Is it possible to make a public parent class method unavailable (i.e., generate an error at compile time) to a particular child class? For example, say a parent class has a public method Add( ). I want to create a child class of this parent class that does not have an Add( ) method (while possibly another child class does). I think I figured it out while writing this, so tell me if this is the 'standard method'. Make the parent class...
1
11971
by: Viken Karaguesian | last post by:
Hello everyone, Just wanting some advice. I'd like to start removing the Microsoft-generated guestbook (a feature of FrontPage) on my websites but I'm not sure if it can be done just using HTML. There seems to be a lot of server-side processing going on. The guesbooks are setup in such a fashion that when user submits an entry, not only is it posted in the page for public viewing, but I also receive an e-mail letting me kow that the...
3
10277
by: sklett | last post by:
This BUG that is so ridiculous I can't believe they shipped 05 is making my life hell. I have tried the various solutions found on the web and none of them have worked thus far. What's even more troublesome is that it appears that 05 uses these new partial classes which would makes rolling back to 03 not possible. The error I get when trying to load my Form in the designer is as follows:...
69
8045
by: kabradley | last post by:
Alrighty Guys and Gals, I have another question that I hope you all can help me with. I have a report that uses a cross-tab query as its record source. This cross-tab query is getting all of its information from another query. That query, qryRpt, is pulling information from several different tables. One of these table is tblDistributions, a table that holds monthly distributions for a particular investment, and the second is tblDeduction, a...
12
2353
by: Rob | last post by:
Let's say you open Form1 that contains TabControl1 There are several tabs on TabControl1 Now you open a new Form2 that contains a User Control How can you determine the Selected tab in Form1 from the User Control in Form2 ? Hope this is clear enough...
4
1249
by: Tom Woods | last post by:
I'm new to C# and was wanting to access a method in the main form from another form frmMain has a method as such: public void AddNewForm(string s, int Id) { }
10
5308
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole number text box, a numerator text box, and a denominator text box. I realize that this is probably the closest I'll get to having fractions displayed in VB, so that's no big deal. I'm able to simplify most numbers with some code I've written,...
11
6236
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as the app is concerned). The problem is, If someone makes a typo, they may get an unexpected error due accidentally calling the original attribute instead of the wrapped version. Does anyone have a simple solution for this?
9
7261
by: Sam Lambson | last post by:
Hi, This is similar to another post, because I still haven't gotten to the bottom of it. I have a back end database on a shared drive. Each (of 4) user has a front end file on their own C: drive. The main form that users have is bound to a query which merges 2 linked tables. It is not an action query. When the query is executed, everyone still has access to the form/query, until somebody makes an update. Or so it seems.
0
8016
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
8440
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...
0
8431
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8306
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
5966
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
3937
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
3980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
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
0
1300
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.