hamid Posted October 16, 2004 Posted October 16, 2004 hi, i have a mdi application and menu "file>new win".when user click "new win" for first time i want create new window but when user click again and there is new window i want call same window. please help me :D Quote [ once4ever ]
Leaders Iceplug Posted October 18, 2004 Leaders Posted October 18, 2004 Declare a boolean: Public NewWindow As Form 'or whatever. When you click on new win, in addition to creating a new instance of a form, you would set this to reference the NewWindow as well. On the form, when you modify this new window so that it is no longer new, you should set this NewWindow variable to Nothing. Then, when you click on new win, you would first check If NewWindow Is Nothing Then add the new window, otherwise, you would focus NewWindow. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Leaders snarfblam Posted October 18, 2004 Leaders Posted October 18, 2004 A code example : [Code] Dim MyWindow as TheFormIMade Sub AddOrFocusWindow If MyWindow Is Nothing MyWindow = New TheFormIMade Else MyWindow.Focus End If End Sub [/Code] Quote [sIGPIC]e[/sIGPIC]
Leaders Iceplug Posted October 19, 2004 Leaders Posted October 19, 2004 And why would you have to have a code example explaining what I just said? But, that was just the easy part. To get the MDIChildren to communicate with the MDIParent, you'd have to supply each MDIChild with a reference to the MDIParent so that you can set the NewWindow reference value. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
hamid Posted October 20, 2004 Author Posted October 20, 2004 thx but please give me VC#.net code: MDIChild mychild=new MDIChild; mychild.MDIParent()=this; mychild.showform(); Quote [ once4ever ]
Leaders Iceplug Posted October 20, 2004 Leaders Posted October 20, 2004 No, you need the parent's reference private YourForm frm; //In the child form class. In the constructor, you pass in the parentform as an argument and assign it to Yourform. public void KidForm(YourForm F) { //Constructor. frm = F; Then, when you modify the form: frm.NewWindow = null; // If you used the child's Parent property, you would not be able to access the .NewWindow property. :) Well, maybe you could cast it to a YourForm. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
hamid Posted October 25, 2004 Author Posted October 25, 2004 thx Iceplug, but please tell me step by step, Quote [ once4ever ]
Joe Mamma Posted October 25, 2004 Posted October 25, 2004 no no no! use a factory pattern hide the constructor. Public Class SingleInstance Inherits System.Windows.Forms.Form 'Static instance all references will use Private Shared theInstance As SingleInstance 'The constructor is marked as PRIVATE!!! Private Sub New() MyBase.New() InitializeComponent() End Sub 'Static Property returning the shared instance Public Shared ReadOnly Property Instance() As SingleInstance Get If theInstance Is Nothing Then theInstance = New SingleInstance End If theInstance.Show() theInstance.BringToFront() Instance = theInstance End Get End Property call it ala: dim si as SingleInstance = SingleInstance.Instance Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted October 25, 2004 Posted October 25, 2004 oh yeah. . . override the dispose method to set the shared instance to nothing: Public Class SingleInstance Inherits System.Windows.Forms.Form 'Static instance all references will use Private Shared theInstance As SingleInstance 'The constructor is marked as PRIVATE!!! Private Sub New() MyBase.New() InitializeComponent() End Sub 'Set the Shared Instance to nothing Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) theInstance = Nothing End Sub 'Static Property returning the shared instance Public Shared ReadOnly Property Instance() As SingleInstance Get If theInstance Is Nothing Then theInstance = New SingleInstance End If theInstance.Show() theInstance.BringToFront() Instance = theInstance End Get End Property End Class Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.