Сделаем опять переменные локальными
1 2 3 | private System.Windows.Forms.Label label1; private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.Button button1; |
И создадим новое событие "Click" для кнопки button1.
Можно прописать его вручную
1 2 3 4 5 6 7 | //Form1.Designer.cs this .button1.Click += new System.EventHandler(button1_Click); //Form1.cs public void button1_Click( object sender, EventArgs e) { } |
или двойным кликом по файлу Form1.cs открыть вид Design
или же опять-таки двойным кликом по кнопке в виде Design создем такой же код автоматически.
А теперь создадим новый метод
1 2 | public delegate void TeapotCreateEventHandler( object sender, TeapotCreateEventArgs ValueArgs); public event TeapotCreateEventHandler TeapotCreate; |
И новый класс TeapotCreateEventArgs, наследованный от EventArgs
Подробнее о EventArgs и EventHandler вы можете прочесть на MSDN
EventArgs.
EventHandler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public class TeapotCreateEventArgs : EventArgs { public TeapotCreateEventArgs( decimal Radius) { this .Radius = Radius; } public TeapotCreateEventArgs( decimal Radius, int Segments, bool Body, bool Handle, bool Spout, bool Lid) { this .Radius = Radius; this .Segments = Segments; this .Body = Body; this .Handle = Handle; this .Spout = Spout; this .Lid = Lid; } public decimal Radius; /// <summary> /// Описываем переменные и инициализупуем сразу их /// (Это нужно , если мы захотим объявить class TeapotCreateEventArgs только с параметром Radius) /// </summary> public int Segments = 5; public bool Body = true , Handle = true , Spout = true , Lid = true ; } |
И теперь пропишем его в коде обработки события нажатия кнопки
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | private void button1_Click( object sender, EventArgs e) { // Обрабатываем событие только если оно создано: // (то есть в макскрипте должно быть прописано dotnet.AddEventHandler form "TeapotCreate" maxscriptFunction) if (TeapotCreate != null ) TeapotCreate( this , new TeapotCreateEventArgs(numericUpDownRadius.Value, ( int )numericUpDownSeg.Value, this .checkBoxBody.Checked, this .checkBoxHandle.Checked, this .checkBoxSpout.Checked, this .checkBoxLid.Checked )); /*ИЛИ if (TeapotCreate != null) TeapotCreate(this, new TeapotCreateEventArgs(numericUpDownRadius.Value)); */ } |
Открываем maxscript editor и пишем там
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ( local dll_filename = "EvenHandler.dll" local Assembly = (dotNetClass "System.Reflection.Assembly" ).Load ((dotNetClass "System.IO.File" ).ReadAllBytes dll_filename) myForm = Assembly.CreateInstance "TeapotCreator.Form1" fn CreateTeapot e = ( Teapot radius:e.Radius \ segments:e.Segments \ body:e.Body \ handle:e.Handle \ spout:e.Spout \ lid:e.Lid ) dotNet.addEventHandler myForm "TeapotCreate" CreateTeapot myForm.ShowModeless() ) |
Таким образом, не объявляя контролы на форме как глобальные мы тем не менее можем передавать их значения для создания объектов в 3ds Max.
Ссылка на проект
https://dl.dropbox.com/u/1880100/%21Blogger/EvenHandler.zip
Комментариев нет:
Отправить комментарий