Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to plot matlab figure inside winform application?

i have a matlab m-file, which plots some function. Using matlab, i have created net assembly project and finaly i got a dll to work with. I have a winform application created in visual studio using c#, and i call my dll(generated in matlab) from my application. Finally i get a graph in new window (figure command in matlab). For example, it looks like: http://i.stack.imgur.com/cbq5Z.png

Is it possible to embed a matlab figure into my winform app?

http://i.stack.imgur.com/S9V9s.png Saving picture in matlab and loading it to picturebox in winform is not a good solution, because i need to operate the figure (zoom, rotate in 3d).

like image 425
sagamor Avatar asked Jul 08 '14 13:07

sagamor


1 Answers

Matlab plots directly inside c++ GUI

This is what you need. You have to import FindWindow() method from User32.dll. It returns a pointer to the window which name you pass as the second argument. After you got the pointer, you have to set it's parent, using SetParent() method, which you can get from User32.dll aswell. In order to get a pointer to your form, use this.Handle:

 IntPtr foundWindow = FindWindow("SunAwtFrame", "Figure 1"); //I belive, this shall give you a pointer to your Matlab window
 SetParent(foundWindow, this.Handle);

And you can manage foundWindow position and size using SetWindowPos() and SetWindowLong() (import these from User32.dll).

like image 111
Denver Avatar answered Oct 23 '22 14:10

Denver