Notifications
Clear all

[Closed] dotNet UI

 lo1

Sure, glad to help.

Btw, I recently wrote a c# spinner control which mimics the behaviour of the 3dsmax spinner control, I’ll try to post it here.

An improvement on that above script would be to put it into a struc.

Rotem
Speaking of c# I spent my freetime in the past day converting the maxscript .net stuff over to complete standalone c# in visual studio.
It’s completed and working. I’ve attached the Spacer.exe file.

If anyone wants me to I’d be more than welcome to uploading a zip file which would contain the entire visual studio build if anyone would like to modify it or add to it.

As mentioned above the script right now does not have max like spinners in it but if someone wants to add that they are more then welcome to. Just let me know and I’ll upload the zip.

Check it out.

UPDATE
ButtonSpacerV6.zip is the visual studio build/files

Thanks
John

 lo1

cool… good job

Great stuff! Cheers for attaching the files. I’m very comfortable with maxscript / dotNet but have very little experience with c#, I’ll have a look through this as an example. Thanks for all the work you guys have put in to this thread. It’s got some really great info within it

 lo1

Here’s the max-style spinner I mentioned.
I just noticed that LoneRobot had already built a similar class ages ago. Hope this is useful to anyone in any case…

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

public class MaxSpinner : NumericUpDown
{
    private bool dragging;
    private Point dragPoint;
    private decimal dragValue;
    private decimal defaultValue;

    public float FloatValue
    {
        get { return (float)Value; }
        set { Value = (decimal)value; }
    }

    public float DefaultValue
    {
        get { return (float)defaultValue; }
        set { defaultValue = (decimal)value; }
    }

    public MaxSpinner()
    {
        dragging = false;
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        if (Controls[0].Bounds.Contains(e.Location))
        {
            if (e.Button == MouseButtons.Left)
            {
                dragging = true;
                dragPoint = e.Location;
                dragValue = Value;
            }
            else if (e.Button == MouseButtons.Right)
            {
                Value = Math.Min(Math.Max(defaultValue,Minimum),Maximum);
            }
        }
    }

    protected override void OnMouseMove(MouseEventArgs e)
    {
        base.OnMouseMove(e);
        if (dragging)
        {
            Value = Math.Min(Math.Max(dragValue + (dragPoint.Y - e.Location.Y) * Increment ,Minimum),Maximum);
        }
    }

    protected override void OnMouseUp(MouseEventArgs mevent)
    {
        base.OnMouseUp(mevent);
        if (dragging)
        {
            dragging = false;
        }
    }

    public void Clear()
    {
        Text = String.Empty;
    }
}

Because maxscript converts decimals to integers instead of to floats, I’ve added the .FloatValue to get the property of the spinner without it being cast to an integer.

1 Reply
(@jokermartini)
Joined: 11 months ago

Posts: 0

Thanks Rotem for the contribution!
I’ll add this to the c# build and be sure to credit you.

Thanks guys for keeping the thread going and helping me out as well as everyone else.

This thread is just getting started.
I’m going to keep going with the dotNet stuff like I mentioned above and further develop examples for everyone to learn from.

The c# version of the script is actually the first every script I built in vs. So it was a very cool and fun learning process to take something I originally wrote in a google doc excel > maxscript rollout > dotNet form > standalone c# exe. All in a matter of a feww weeks.

I’ve learned a ton of information and techniques as well as coding formats.
I’ll be posting more stuff on my site in the future on notes for c# for anyone who may be interested in learning it. It’s rather pretty straight forward and easy to transition to if you know maxscript.

If anyone does end up modifying or adding to the build I’d love to check it out.

here is a dotNet maxscript spinner.
credit – Paul Neal


--Create a dotNet form control.
form=dotNetObject "form"
form.bounds=(dotNetObject "system.drawing.rectangle" 10 10 150 100)

--Create a dotNet NumericUpDown control.
nud=dotNetObject "System.Windows.Forms.NumericUpDown"
nud.location=(dotNetObject "system.drawing.point" 10 10)
nud.DecimalPlaces=2
nud.Increment=.1
nud.maximum=100
nud.minimum=-10
nud.value=10
nud.ReadOnly=false

--This is needed so that we can type in the values as well as use the spinner. 
enableAccelerators=false

--Set variables to hold the mouse position and current value of the spinner. 
lastMousePos=0
curVal=0

--Mouse down function to set the variables above to the starting values. 
fn nudMouseDown sender arg=
(
	case arg.button of
	(
		--Check for the left mouse button
		(arg.button.left):
		(
			lastMousePos=(arg.location).y
			curVal=sender.value
		)
		--Check for the right mouse button
		(arg.button.right):
		(
			sender.value=0
		)
	)
)

--On mouseMove event
fn nudMouseMove sender arg=
(
	case arg.button of
	(
		--Check for the left mouse button. 
		(arg.button.left):
		(
			--Get the offset from the last position of the mouse
			mouseOffSetY=(lastMousePos-arg.location.y)*.1
			--Add that position to the curVal variable
			curVal=curVal+=mouseOffSetY
			
			--Check if the curVal is within limits of the spinner.
			if curVal>=sender.minimum and curVal<=sender.maximum do
			(
				--Set the value of the spinner
				sender.value=curVal
			)
			--Check if the value has gone above or below the min max values and set them.
				--This is needed if the value changes more rapidly then the spinner can react.
 			if curVal<=sender.minimum do sender.value=sender.minimum
 			if curVal>=sender.maximum do sender.value=sender.maximum
			
			--Set the lastMousePos value to the current value of the mouse. 
			lastMousePos=arg.location.y
		)
	)
)

--Create the event handlers
dotNet.addEventHandler nud "mouseDown" nudMouseDown
dotNet.addEventHandler nud "mouseMove" nudMouseMove
--Set the life time control of the spinner to be handled by dot net and not Max script. 
	--This stops garbage collections from deleting the event handlers. 
dotNet.setLifeTimeControl nud #dotNet

--Add the NumericUpDown to the form and show the form. 
form.controls.add nud
form.show()   

So this is what I’m after and working on. I’m attempting to get some sort of subrollout system working. When the user clicks on that button it then loads that .ms file and its controls are then visible in the main dialogs Control Panel.

I tried created a controlPanel and nothing was seeming to show.
Think of it as the buttons at the top of the main dialog being tabs. The main reason I’m not using tabs is because I want to be able to create custom looking buttons and use them as tabs.

I’ve attached the wirecolor files as seen in the image if anyone wants to make an attempt at this. I’ll be working on this more throughout the following days and seeing what I get. I’ll be sure to post.

 lo1

here is some quick and dirty code that shows how you could do something like this

theform = dotnetobject "form"
theform.bounds = dotnetobject "system.drawing.rectangle" 200 200 300 300

--THIS CONTROL WILL ACT AS AN EMPTY SPACE TO HOST YOUR SUBPANELS IN
containerPanel = dotnetobject "panel"
containerPanel.bounds = dotnetobject "system.drawing.rectangle" 10 50 280 240

fn btnClicked s e = 
(
	containerPanel.controls.clear()
	containerPanel.controls.add s.tag
)

--SUB PANEL 1
subPanel1 = dotnetobject "panel"
subPanel1.backcolor = subpanel1.backcolor.green
subPanel1.bounds = dotnetobject "system.drawing.rectangle" 0 0 280 240

subButton1 = dotnetobject "combobox"
subButton1.bounds = dotnetobject "system.drawing.rectangle" 20 20 100 20

subPanel1.controls.add subButton1

--SUB PANEL 2
subPanel2 = dotnetobject "panel"
subPanel2.backcolor = subpanel2.backcolor.blue
subPanel2.bounds = dotnetobject "system.drawing.rectangle" 0 0 280 240

subButton2 = dotnetobject "button"
subButton2.text = "sub button 2"
subButton2.bounds = dotnetobject "system.drawing.rectangle" 20 20 100 20

subPanel2.controls.add subButton2

--MAIN FORM CONTROLS
btn1 = dotnetobject "button"
btn1.bounds = dotnetobject "system.drawing.rectangle" 20 20 100 30
btn1.text = "button 1"
btn1.tag = subPanel1
dotnet.addeventhandler btn1 "Click" btnClicked

btn2 = dotnetobject "button"
btn2.bounds = dotnetobject "system.drawing.rectangle" 140 20 100 30
btn2.text =  "button 2"
btn2.tag = subPanel2
dotnet.addeventhandler btn2 "Click" btnClicked

theForm.controls.addRange #(btn1,btn2,containerpanel)
theForm.show()
Page 6 / 18