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.
Printable View
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.
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.
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.
So how do I do it?
So, you're saying that you've never opened a form in a WinForms app before?
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
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.
So how do I do that?
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
I've been trying that
This is not working, am i close?Code:Dim winform As New userwindow
DirectCast(winfor, MyFormName)
winform.ShowDialog()
What's the second line for?
I'm converting MyFormName into winfor ??
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.
It's a Windows Form. Created in VB 2008
Create that type? okay how?
Dim winform as new Window.Form
Thanks not an option
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?
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.
Am I still missing something here, why are you using the same winform window?