Jump to content

What is the right way to use Winforms inside an effect plugin?


Recommended Posts

// Name:
// Submenu:
// Author:
// Title:
// Version:
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
#endregion

class MyForm : Form
{
    public MyForm()
    {
        this.InitializeComponent();
    }

    System.ComponentModel.IContainer components = null;

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    private void InitializeComponent()
    {

        //UI stuff
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(800, 450);
        this.Text = "MyForm";
    }


}

void Render(Surface dst, Surface src, Rectangle rect)
{
    global::System.Windows.Forms.Application.EnableVisualStyles();
    global::System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
    global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware);

    Application.Run(new MyForm());
}

 

Tried it like this, and it works only the first 3-4 times you call the effect, after the 3-4 time, paint.net crashes the it displays the following exception:

Quote

Exception details:
System.InvalidOperationException: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

In the code above I am calling Application.SetCompatibleTextRenderingDefault() before i call Application.Run, so why is it not working if you keep using the effect more than 3 or 4 times? I am running this in a Single Render Call effect plugin

 

 

the usual

 

0054-0133.gif

Link to comment
Share on other sites

Your are developing a plugin and not an application.

 

Derive you effect plugin from PaintDotNet.Effects.Effect and override CreateConfigDialog.

There you should return a new dialog derived from EffectConfigDialog.

This is the dialog you can populate with your own controls.

 

  • Thanks 1

midoras signature.gif

Link to comment
Share on other sites

What @midora said. Those calls into System.Windows.Forms.Application are not for plugin use. Paint.NET already configures those at application startup. You do not use Application.Run() in a plugin. Paint.NET calls your CreateConfigDialog() method and then displays the Form you return.

  • Thanks 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Seen these? 

I'm not sure if @toe_head2001 is maintaining them, but they are a great starting point to creating effects with a custom UI.

  • Thanks 1
Link to comment
Share on other sites

On 1/7/2023 at 5:13 AM, Ego Eram Reputo said:

Seen these? 

I'm not sure if @toe_head2001 is maintaining them, but they are a great starting point to creating effects with a custom UI.

Thank you! This is exactly what I needed, I have been struggling til now to get ConfigDialog and ConfigToken to work. 

the usual

 

0054-0133.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...