Skip to content

WinForms: improve the designer experience for .NET Framework apps#4425

Merged
swharden merged 6 commits intoScottPlot:mainfrom
CoderPM2011:#4362
Nov 4, 2024
Merged

WinForms: improve the designer experience for .NET Framework apps#4425
swharden merged 6 commits intoScottPlot:mainfrom
CoderPM2011:#4362

Conversation

@CoderPM2011
Copy link
Contributor

@CoderPM2011 CoderPM2011 commented Nov 3, 2024

resolve #4362

After investigation, it was found that FormsPlot inherits FormsPlotBase, and its member Plot will call the method in SkiaSharp, so FormsPlotBase also needs to be adjusted.

Adjusted to detect whether FormsPlotBase throws an exception that libSkiaSharp.dll cannot be found, and display the current version and error message on the control.

like this
image


I found that I had to be careful whether FormsPlot properties were set in Form.Designer.cs.
If the property calls SkiaSharp, it may also affect the control and cause an error.🤔

@swharden
Copy link
Member

swharden commented Nov 3, 2024

Wow @CoderPM2011, great find! This is fantastic! 🚀

@swharden
Copy link
Member

swharden commented Nov 3, 2024

Hi @CoderPM2011 - I'm curious, how are you testing this?

I have a SDK project that I set to target net48 and I'm getting this 😅

image

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net48</TargetFramework>
        <Nullable>enable</Nullable>
        <UseWindowsForms>true</UseWindowsForms>
        <ImplicitUsings>enable</ImplicitUsings>
        <IsPackable>false</IsPackable>
        <SignAssembly>True</SignAssembly>
        <LangVersion>latest</LangVersion>
        <AssemblyOriginatorKeyFile>../../Key.snk</AssemblyOriginatorKeyFile>
    </PropertyGroup>

    <ItemGroup>
        <ProjectReference Include="..\..\ScottPlot5 Controls\ScottPlot.OpenGL\ScottPlot.OpenGL.csproj" />
        <ProjectReference Include="..\..\ScottPlot5 Controls\ScottPlot.WinForms\ScottPlot.WinForms.csproj" />
        <ProjectReference Include="..\..\ScottPlot5\ScottPlot.csproj" />
    </ItemGroup>

</Project>
namespace Sandbox.WinForms;

static class Program
{
    [STAThread]
    static void Main()
    {
#if NETFRAMEWORK
#else
        ApplicationConfiguration.Initialize();
#endif
        Application.Run(new Form1());
    }
}

@swharden
Copy link
Member

swharden commented Nov 3, 2024

Oof, it seems to be failing for me the same way when I try to load any control (including a blank one) from the ScottPlot.WinForms assembly 💀

@CoderPM2011
Copy link
Contributor Author

Hi @CoderPM2011 - I'm curious, how are you testing this?

I first have the ScottPlot.WinForms project generate the Nuget package.
Then in the newly created .Net Framework 4.6.2 project, install the locally generated Nuget package for testing.

@swharden
Copy link
Member

swharden commented Nov 3, 2024

Hi @CoderPM2011 - I'm curious, how are you testing this?

I first have the ScottPlot.WinForms project generate the Nuget package. Then in the newly created .Net Framework 4.6.2 project, install the locally generated Nuget package for testing.

Ah, interesting! I've only tested this running from source which may explain why I've had difficulty reaching a solution.

Thanks again for your feedback and this PR! I'm excited to give this a try soon 👍

@CoderPM2011
Copy link
Contributor Author

Ah, interesting! I've only tested this running from source which may explain why I've had difficulty reaching a solution.

I'm guessing that the reason for the failure to work from the source code may be related to multiple target frameworks or whether VS itself is running properly. 🤔

@CoderPM2011
Copy link
Contributor Author

CoderPM2011 commented Nov 4, 2024

In my repository branch test-#4362.

I tested the pattern directly referenced in the source project.
I found that the multi-target framework does affect the toolbox.
Maybe it has something to do with this dotnet/msbuild#7856 .

If I change ScottPlot.WinForms to only target net462 then I get it working.
Sometimes you encounter an exception. After restarting Visual Studio, try again and it will work normally.

My test result
image

@swharden
Copy link
Member

swharden commented Nov 4, 2024

I found that the multi-target framework does affect the toolbox.

Wow, that was the magic piece of information! I got it working now and will refine the error screen a bit. This is what I'm thinking of having it show when the DLL fails to load:

image

... but if this is successful after the next release, I'm tempted to use System.Drawing.Graphics to manually draw a title, grid, and axes, and display it as a Bitmap in a PictureBox and I bet most people will have no idea there was a failure! 🚀

@swharden
Copy link
Member

swharden commented Nov 4, 2024

I'll merge this now, but note that it has been modified to only show this message if design time mode is detected. The reason is I don't want that message accidentally showing up on client machines of a third party publishes an app using ScottPlot. Instead, we can explore adding a new PR to display a user-facing message (not aimed at developers necessarily) for when the DLL cannot be located.

This is a semi-common issue actually, unrelated to running inside visual studio, because sometimes people build an app but forget to include all those platform specific subfolders (e.g., I once published a WinForms app and omitted the arm folders but someone with one of those new windows arm tablet PCs couldn't load the app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WinForms: improve the designer experience for .NET Framework apps

2 participants