-
May 30th, 2010, 11:36 PM
#1
Thread Starter
Fanatic Member
Open WinForm
How can i open a WinForm Class from a button in my WPF project?
I've added my WinForm to my solutions explorer via add existing class.
-
May 30th, 2010, 11:59 PM
#2
Re: Open WinForm
First, why would you? Why not recreate the same functionality in a WPF Window?
As for the question, presumably you would show a Windows Form exactly the same way as you always do. There's no reason it should be any different.
-
May 31st, 2010, 12:32 AM
#3
Re: Open WinForm
Tested and confirmed. The only difference is that there is no default instance. Default instances are a function of the application framework, which is set up to support Windows in a WPF app, not Forms.
-
May 31st, 2010, 01:30 AM
#4
Thread Starter
Fanatic Member
-
May 31st, 2010, 01:34 AM
#5
Re: Open WinForm
So, you're saying that you've never opened a form in a WinForms app before?
-
May 31st, 2010, 01:41 AM
#6
Thread Starter
Fanatic Member
Re: Open WinForm
I do it this way
MyFormName.Show
When I type my form name in my WPF project I don't get the Show options showing
-
May 31st, 2010, 01:44 AM
#7
Re: Open WinForm
As I said, there's no default instance. You need to create a new object of that type first, just as you do for any other type. Once you have an object, then you can access its members, e.g. call its Show method.
-
May 31st, 2010, 01:47 AM
#8
Thread Starter
Fanatic Member
-
May 31st, 2010, 01:57 AM
#9
Re: Open WinForm
This is the part where you get to think. You've created objects before. How did you do it then? Maybe you should take a look at some of your own code.
http://www.vbforums.com/showthread.php?t=616468
-
May 31st, 2010, 02:04 AM
#10
Thread Starter
Fanatic Member
Re: Open WinForm
I've been trying that
Code:
Dim winform As New userwindow
DirectCast(winfor, MyFormName)
winform.ShowDialog()
This is not working, am i close?
-
May 31st, 2010, 02:09 AM
#11
Re: Open WinForm
What's the second line for?
-
May 31st, 2010, 02:13 AM
#12
Thread Starter
Fanatic Member
Re: Open WinForm
I'm converting MyFormName into winfor ??
-
May 31st, 2010, 02:33 AM
#13
Re: Open WinForm
What EXACTLY is the type of the form you want to display? Create that type of form and display it. That's all. There's no converting to be done because it already is exactly what it's supposed to be.
-
May 31st, 2010, 02:39 AM
#14
Thread Starter
Fanatic Member
Re: Open WinForm
It's a Windows Form. Created in VB 2008
Create that type? okay how?
Dim winform as new Window.Form
Thanks not an option
-
May 31st, 2010, 02:49 AM
#15
Re: Open WinForm
You're missing some of the basics here. When you add a form to your project you are creating a new class. That new class inherits System.Windows.Forms.Form, which is what makes it a Windows Form. It inherits all the form functionality from its base class but it is a new class and you add new functionality to it. The new class might be MainForm or OptionsDialog or AboutBox or whatever you choose to name it. What is yours?
-
May 31st, 2010, 02:56 AM
#16
Thread Starter
Fanatic Member
Re: Open WinForm
I'm about to give up, I can't simply import an existing item and view it. It's got all sorts of errors and when i continue it's just a blank form. i take it it's not possible to import a form from another project
-
May 31st, 2010, 03:12 AM
#17
Re: Open WinForm
Originally Posted by AirlineSim
I'm about to give up, I can't simply import an existing item and view it. It's got all sorts of errors and when i continue it's just a blank form. i take it it's not possible to import a form from another project
When I tested I added a new item in the Solution Explorer, which probably added all the necessary references and imports automatically. In your case, because you're importing an existing item, you may well need to add those automatically.
Open or create a WinForms project and go to the References page of the project properties. Whatever references and imports you see there, make sure they are also present in your WPF project containing the WinForm. Add any references that are missing and then tick any imports that are unticked. I'm guessing that you'll need at least System.Windows.Forms and System.Drawing in each case.
-
Jun 6th, 2010, 12:40 PM
#18
Frenzied Member
Re: Open WinForm
Am I still missing something here, why are you using the same winform window?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|