Notifications
Clear all

[Closed] Dot net buttons

I’m trying to build a user interface but I realized quickly that the default maxscript button didn’t have enough visual options for what I wanted to do.
SO I looked into dot net but I still can’t find what i’m looking for.

What i’d like is to have a circular button. Is there a way to do it in dot net? Should I use a picture and map onto my button instead?

on the other side i’d be happy with another type of solution: is there a way to give a 45 degree rotation to a button in either mxscript or dontnet

13 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

.NET + WPF = any shape, any transform, any color and opacity

hmm so i assume there’s not right of the bat function for what I wanted to do.
oh well… time to learn wpf

so far i’ve been unable to do anything good witg wpf yet anyother leads?

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

what’s the problem with wpf?
also you can do custom draw on paint event. there are some samples on this forum. i remember at least one by LO for sure…

as i have a time i will post a wpf sample code.

(@denist)
Joined: 11 months ago

Posts: 0

here is a sample how to make round button using .NET and WPF classes


try(wp.close()) catch()
fn makeToolBall size:[50,50] =
(
	global _b = ball = dotnetobject "System.Windows.Shapes.Ellipse"
	
	local mcolor = dotnetclass "System.Windows.Media.Color"
	
	ball.Width = size.x
	ball.Height = size.y
	ball.Stroke = dotnetobject "System.Windows.Media.SolidColorBrush" (mcolor.FromArgb 150 20 20 20) --Black --MidnightBlue
	ball.StrokeThickness = 1.5

	local radBrush = dotnetobject "System.Windows.Media.RadialGradientBrush"
	local gpClass = dotnetclass "System.Windows.Media.GradientStop"
	local mcolors = dotnetclass "System.Windows.Media.Colors"
	
	radBrush.GradientOrigin = dotnetobject "System.Windows.Point" 0.25 0.25
	radBrush.GradientStops.Add (dotnetobject gpClass mcolors.White 0.0) 
	radBrush.GradientStops.Add (dotnetobject gpClass mcolors.LightSteelBlue 0.95) 
	radBrush.GradientStops.Add (dotnetobject gpClass mcolors.SlateGray 0.99) 

	ball.Fill = radBrush
	
	local cv = dotnetobject "System.Windows.Controls.Canvas"
	cv.Width = ball.Width
	cv.Height = ball.Height
	cv.Children.Add ball
	
	local wp = dotnetobject "System.Windows.Window"
	wp.WindowStartupLocation = wp.WindowStartupLocation.Manual
	wp.Left = 800
	wp.Top = 200
	wp.Width = ball.Width + 40
	wp.Height = ball.Height + 50
	wp.WindowStyle = wp.WindowStyle.ToolWindow

	wp.Title = "ExtraToolball"
	wp.ShowInTaskbar = off

	fn onMouseDown s e = 
	(
		format "mouse down...
"
	)
	dotnet.addeventhandler ball "MouseDown" onMouseDown
	fn onMouseUp s e = 
	(
		format "mouse up...
"
	)
	dotnet.addeventhandler ball "MouseUp" onMouseUp
	wp.content = cv
	
	wih = dotnetobject "System.Windows.Interop.WindowInteropHelper" wp
	wih.owner = dotnetobject "IntPtr" (windows.getmaxhwnd())

	wp
)	
wp = makeToolBall()
wp.Show()

wow thanks for that snippet, I was trying to use xaml code format feel kinda ashamed now.

ok so I’m trying to integrate the ball fn into a standard rollout ( got rid of the window creation stuff) So i can be able to call it and create circular button at ease
but when I do so I get

– Runtime error: dotNet runtime exception: The calling thread must be STA, because many UI components require this.
google tell me something a Dispatcher.CurrentDispatcher but how can I plug this?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

here is how to add the button for a rollout:


try(destroydialog wpfRollout) catch()

rollout wpfRollout "" width:70 height:80
(
	dotNetControl eh "Integration.ElementHost" width:50 height:50 align:#left offset:[0,0]
	
	fn makeToolBall size:[50,50] =
	(
		local ball = dotnetobject "System.Windows.Shapes.Ellipse"
		
		local mcolor = dotnetclass "System.Windows.Media.Color"
		
		ball.Width = size.x
		ball.Height = size.y
		ball.Stroke = dotnetobject "System.Windows.Media.SolidColorBrush" (mcolor.FromArgb 150 20 20 20) --Black --MidnightBlue
		ball.StrokeThickness = 1.5

		local radBrush = dotnetobject "System.Windows.Media.RadialGradientBrush"
		local gpClass = dotnetclass "System.Windows.Media.GradientStop"
		local mcolors = dotnetclass "System.Windows.Media.Colors"
		
		radBrush.GradientOrigin = dotnetobject "System.Windows.Point" 0.25 0.25
		radBrush.GradientStops.Add (dotnetobject gpClass mcolors.White 0.0) 
		radBrush.GradientStops.Add (dotnetobject gpClass mcolors.LightSteelBlue 0.95) 
		radBrush.GradientStops.Add (dotnetobject gpClass mcolors.SlateGray 0.99) 

		ball.Fill = radBrush
				
		fn onMouseDown s e = (format "mouse down...
")
		dotnet.addeventhandler ball "MouseDown" onMouseDown
		fn onMouseUp s e = (format "mouse up...
")
		dotnet.addeventhandler ball "MouseUp" onMouseUp
		
		ball
	)	

	on wpfRollout open do
	(
		eh.child = makeToolBall()
	)
)

createDialog wpfRollout style:#(#style_toolwindow,#style_sysmenu,#style_resizing)

if WindowsFormsIntegration assembly is not loading automatically you have to manually load it:


dotNet.loadAssembly @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll"

using right for your system path

Works like a charm I think I was missing the integration.elementhost thing
Thanks you.

One little thing though is there a way to have the white part around the circle to be transparent?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

there is no easy way to make its background transparent but you can do the same color as rollout background:


	on wpfRollout open do
	(
		eh.Backcolor = ((dotnetClass "ManagedServices.CuiUpdater").GetInstance()).getMaxColor 0
		eh.child = makeToolBall()
	)


sadly thats not gonna work as the button needs to be over a picture, i’ll do some research later today

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

there is my sample on this forum about how to make semitransparent window forms control. it’s only way that i know.

ok thank you, i’ll look for it asap