![]() |
Using Multiple Windows...
Alright well what im trying to achieve is to open a window onto of the main window.
I am createing a notepad/ richtext editor, and when the user clicks file new on the menu a window should prompt with the FileNew Form I created. I know in VB6 all I had to do is say TheFormName.Visible = True but its not this way in .NET, anyone know how? Also to clear up any confusion, the form I want to show has already been created and is in the project explorer, the forms name is frmFileNew Thanks. |
You need to load a new instance of the form:
:
Dim MyForm As TheFormName |
Alright thanks, that worked. The reason I messed up on the article I read was it said Dim oForm As FormName, and I was thinking it was like a variable Integer, and thats what FormName represented, but really it actually meant the forms name 0_o.
Anyways is there any way to make the Parent window inactive (without disabling it) while the new form is open. Like most applications when you go file new, and the new dialog comes up, you cant play around with the main program until you close the new dialog... |
After you create the form, use the ShowDialog method.
|
Set the Enabled process to False, I guess.
|
ShowDialog, instead of Show worked. Thanks. I have one last question about trying to communicate to the main form from the new form....
I have two forms formMain formFileNew When you click the new button on formMain the formFileNew form comes up, when you click OK on formFileNew it needs to close itself (which works) and enable rtbTextBox on formMain, which doesnt work. I cant figure out how to naviagate the code to the main form. Heres the code I tried in formFileNew to do this, which doesnt work: :
Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOk.ClickformMain.rtbTextBox.Enabled = True Fails and I get an error. Everything is spelled correct as well. Anyone know how to do this? |
First of all, you can't declare a variable with the same name as a variable type:
:
Dim frmMain As formMain:
frmMain = New formMainOut of interest, what does formFileNew actually do? |
Ooble's advice would create another form resulting in 3. I suppose you want to communicate back to the *original* form. This is not VB6, you need a reference to "communicate" with a form. In your setup, A method in the formMain class creates and gets a reference to an instance of formFileNew. formFileNew has no way to access the formMain instance that created it. I would suggest adding a property on the formFileNew class specifying what the user has selected. When the form closes, access the property. ShowDialog returns when the form is closed, so the property should have the data you want.
|
You could declare your main form's instance as a public shared variable: if your project runs the main form, you'll need to create global a main() routine for startup, i.e.
:
Public Shared ifrmSomeForm As frmSomeFormThen wherever you are, the main instance of the form frmSomeForm can be accessed via ifrmSomeForm without worrying about race conditions etc. |
Alright, Thanks you guys.
Ooble: Yea I need to refrence the original not create another, but formFileNew is the dialog / form that comes up asking for what kind of New file you want to create, Text File, which will have no highlighting, PHP which will have php highlighting, html which will have html highlighting, rich text, which will have a whole bunch of rich text options, or specify your own type, also asks where you want to save it, and which abbreviations, headers, footers you want to use if any... so yea... Daemeon: I didnt quite understand what you meant. Im really new to VB .NET so I dont know much about it, or how to do things. The only thing I understood is it couldnt be done, if that is what you were saying 0_o... I got confused about here "I would suggest adding a property on the formFileNew class specifying what the user has selected. When the form closes, access the property. ShowDialog returns when the form is closed, so the property should have the data you want." I dont know what you meant by add a property to the class, specifying what the user has selected... Rory: I didnt quite understand that code, as I am new to VB .NET X_X. But reading that code I am guessing it globalizes the 2nd form... atleast thats what I got out of it... Sorry im really new to this, and cant understand any of this very well. This seems kind of object oriented, which ive never worked with before. Sorry for my noobishity -_-. EDIT After reading over the posts a couple of times were you saying like: On the formMain's code make an event for when OK or close is clicked on formFileNew and get its data and enable the richtext box from there? would that work? or were you saying something else? |
| All times are GMT -5. The time now is 6:09 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC