[Tutorial : Creating a basic tool] Form not showing up in Max

 
 
 
Posted by:Darholm
Data created:18 September 2011

Hello,

I'm trying the Spline Align tutorial and I have a problem with the windows form. When Max starts, it effectively loads the SplineAlign.dll because I see the form showing up, but it doesn't stay displayed on screen. It just pops and disappears.

This is the code i'm using :

SplineAlign.cs :

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Max;
namespace SplineAlign
{
    public class SplineAlign : IPlugin
    {
        #region IPlugin Members
        public void Cleanup()
        {
            
        }
        public void Initialize(IGlobal global, System.ComponentModel.ISynchronizeInvoke sync)
        {
            SplineAlignDialog dialog = new SplineAlignDialog(global);
            dialog.Show();
                       
        }
        #endregion
    }
}

 

SplineAlignDialog.cs :

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using Autodesk.Max;

 

namespace SplineAlign

{

    public partial class SplineAlignDialog : Form

    {

        IGlobal global;

        public SplineAlignDialog(IGlobal global)

        {

            this.global = global;

            InitializeComponent();

        }

 

        private void SplineAlignDialog_Load(object sender, EventArgs e){}

 

        private void button1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("Hello World!");

        }

    }

}

 

Thanks for the help!

 

 

Darholm

 

try to create a userControl instead of a WinForm and call the *.dll using a dotnetControl in maxscript, something like this:

 

dotnet.loadAssembly @"C:\xxx\yourdll.dll"

if classof yourRollout == RolloutClass then destroyDialog yourRollout

rollout yourRollout "Title" width:Width height:Height

(

dotnetControl nameControl "yournamespace.yourUserControl" pos:[0,0] width:Width height:Height

)

createDialog yourRollout

 

where:

yourRollout is the name of your maxscript Rollout

nameControl: dotNetControl name

yournamespace: namespace from your c# project

yourUserControl: userControl name from your project

Width: width of your userControl from c# project

Height: height of your userControl from c# project

 

i hope it help you.

Henriqu Melo.