MATLAB: Does the plot not automatically resize when I manually change the figure size in a .NET application

assemblydllfigureMATLAB Compiler SDKnetresizeresizefcn

I have a .NET application that shows a simple plot.
However, the axes object does not refresh when I manually resize the figure window until I click + zoom and then – zoom on the toolbar.

Best Answer

This issue has been fixed as of MATLAB R2018b. For earlier MATLAB releases, please follow the guidelines below.
In the attachment, the Visual Studio project "ConsoleApp2" is the project that should be opened.
The MATLAB function "myfun.m" is the function that has been compiled into the .NET DLL "myAssembly.dll" with the following command from MATLAB Command Window:
>> mcc -W 'dotnet:myAssembly,myClass,4.0,private' -T link:lib myfun
In order to solve this issue, you need to add the following code at the end of the MATLAB function "myfun.m":
>> set( gcf, 'ResizeFcn', @(~,~)drawnow );
The above code will force MATLAB to refresh the current figure and therefore the axes are forced to be resized according to the current figure size.
After the MATLAB function is modified, please compile the .NET DLL again and make sure that the right DLL is added to the Visual Studio project under "Dependencies" --> "Assemblies".
Note: remember to check that the version of "MWArray.dll" is consistent with the release of MATLAB that you are using, otherwise the build might fail. If you have a different version of "MWArray.dll", remember to remove the one in the project and add the one that corresponds to the MATLAB release that you have (which is located in "<MATLAB directory>\<release>\toolbox\dotnetbuilder\bin\win64\v4.0").