Notifications
Clear all

[Closed] Form Components Opacity

Hi

Is there any way to set opacity 100% for components
in the form which have opacity 80%


 fn netDrColor clr  = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
 fn netDrSize size = (dotNetObject "Drawing.Size" size.x size.y)
 fn onPaint s a =
 (
 	local fillBrush = dotnetobject "System.Drawing.SolidBrush" (netDrColor red)
 	local rect = (dotnetobject "System.Drawing.Rectangle" 20 20 100 100)
 	--a.graphics.clear (netDrColor green)
 	--a.graphics.SetClip rect
 	a.graphics.FillRectangle fillBrush rect
 )
 f = dotnetObject "Form"
 f.size = netDrSize [400, 400]
 f.backcolor = netDrColor green
 f.opacity = 0.8
 
 
 lbl = dotnetObject "Label"
 lbl.backcolor = netDrColor yellow
 lbl.size = netDrSize [250, 250]
 dotNet.addeventhandler lbl "Paint" onPaint
 
 f.controls.add lbl
 
 f.show()
 

Im found something here , but I don’t realy understand what he say:
http://www.itags.org/dotnet/20633/

5 Replies

the best way to do it is to use two forms (one on top of the other):


  try(form.close()) catch()
form = dotnetobject "MaxCustomControls.Maxform"
form.size = dotnetobject "System.Drawing.Size" 200 200
form.opacity = 0.7
		
tb = dotnetobject "Button"
tb.text = "Top Button"
tb.Dock = tb.Dock.Top

bb = dotnetobject "Button"
bb.text = "Bottom Button"
bb.Dock = bb.Dock.Bottom	
	
fn onLoad s a =
(
	top = dotnetobject "System.Windows.Forms.Form"
	top.StartPosition = top.StartPosition.Manual
	top.ShowInTaskBar = off
	top.FormBorderStyle = top.FormBorderStyle.None
	top.TransparencyKey = top.BackColor
	top.Controls.addrange #(tb, bb)

	s.AddOwnedForm top
	top.Location = s.PointToScreen (dotnetclass "System.Drawing.Point").Empty
	top.Size = s.ClientSize
	top.Show (dotnetobject "MaxCustomControls.Win32HandleWrapper" (dotnetobject "System.IntPtr" s.handle))
)	
dotNet.addEventHandler form "Load" onLoad
fn onLocationChanged s a = if (top = s.OwnedForms[1]) != undefined do top.location = s.PointToScreen (dotnetclass "System.Drawing.Point").Empty	
dotNet.addEventHandler form "LocationChanged" onLocationChanged
fn onSizeChanged s a = if (top = s.OwnedForms[1]) != undefined do top.Size = s.ClientSize	
dotNet.addEventHandler form "ClientSizeChanged" onSizeChanged
form.showmodeless()
  
1 Reply
(@polimeno)
Joined: 11 months ago

Posts: 0

Could you explain more about this .showmodeless() method ?

Hi

 I was thinking about something like this before

heh, but I didn’t know how to bind two forms together.

 Hey Man! You are the Best!

  

 I’m tried to fix it for Max9 with you C# WindowWrapper Function , but it not works


 the buttons are not clickable and still have opacity... strange

   
   global WindowWrapper 
   if WindowWrapper == undefined do
   ( 
   	fn getWindowWrapper = 
   	(
   		source = ""
   		source += "using System;
"
   		source += "using System.Windows.Forms;
"
   		source += "public class WindowWrapper : IWin32Window
"
   		source += "{
"
   		source += "	public WindowWrapper(IntPtr handle) { _hwnd = handle; }
"
   		source += "	public WindowWrapper(Int32 handle) { _hwnd = (IntPtr)handle; }
"
   		source += "	public IntPtr Handle { get { return _hwnd; } }
"
   		source += "	private IntPtr _hwnd;
"
   		source += "}
"
   		-- Compile on fly
   		csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
   		compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
   		compilerParams.ReferencedAssemblies.Add("System.dll");
   		compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
   		compilerParams.GenerateInMemory = on
   		compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
   
   		compilerResults.CompiledAssembly
   	)
   	getWindowWrapper()
   	WindowWrapper = dotnetobject "WindowWrapper" (windows.getMAXHWND()) 
   )
   
    try(form.close()) catch()
    
   form = dotnetobject "form"
   form.size = dotnetobject "System.Drawing.Size" 200 200
   form.opacity = 0.7
   		
   tb = dotnetobject "Button"
   tb.text = "Top Button"
   tb.Dock = tb.Dock.Top
   
   bb = dotnetobject "Button"
   bb.text = "Bottom Button"
   bb.Dock = bb.Dock.Bottom	
   	
   fn onLoad s a =
   (
   	top = dotnetobject "Form"
   	top.StartPosition = top.StartPosition.Manual
   	top.ShowInTaskBar = off
   	top.FormBorderStyle = top.FormBorderStyle.None
   	top.TransparencyKey = top.BackColor
   	top.Controls.addrange #(tb, bb)
   
   	s.AddOwnedForm top
   	top.Location = s.PointToScreen (dotnetclass "System.Drawing.Point").Empty
   	top.Size = s.ClientSize
   	top.Show(dotnetobject "WindowWrapper" (dotnetobject "System.IntPtr" s.handle))
   )	
   dotNet.addEventHandler form "Load" onLoad
   fn onLocationChanged s a = if (top = s.OwnedForms[1]) != undefined do top.location = s.PointToScreen (dotnetclass "System.Drawing.Point").Empty	
   dotNet.addEventHandler form "LocationChanged" onLocationChanged
   fn onSizeChanged s a = if (top = s.OwnedForms[1]) != undefined do top.Size = s.ClientSize	
   dotNet.addEventHandler form "ClientSizeChanged" onSizeChanged
   
   form.Show(WindowWrapper)
   
   
   

It worked now for Max9 , finaly! Thanks Denis 🙂


global WindowWrapper 
if WindowWrapper == undefined do
( 
	fn getWindowWrapper = 
	(
		source = ""
		source += "using System;
"
		source += "using System.Windows.Forms;
"
		source += "public class WindowWrapper : IWin32Window
"
		source += "{
"
		source += "	public WindowWrapper(IntPtr handle) { _hwnd = handle; }
"
		source += "	public WindowWrapper(Int32 handle) { _hwnd = (IntPtr)handle; }
"
		source += "	public IntPtr Handle { get { return _hwnd; } }
"
		source += "	private IntPtr _hwnd;
"
		source += "}
"
		-- Compile on fly
		csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
		compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
		compilerParams.ReferencedAssemblies.Add("System.dll");
		compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
		compilerParams.GenerateInMemory = on
		compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

		compilerResults.CompiledAssembly
	)
	getWindowWrapper()
	WindowWrapper = dotnetobject "WindowWrapper" (windows.getMAXHWND()) 
)

 try(form.close()) catch()
--Main From
form = dotnetobject "form"
form.size = dotnetobject "System.Drawing.Size" 200 200
form.opacity = 0.7

fn netDrColor clr	   = ((dotNetClass "Drawing.Color").fromArgb clr.r clr.g clr.b)
fn netDrRect pos size   = (dotnetObject "Drawing.Rectangle" pos.x pos.y size.x size.y)
fn closeTopForm s a = (s.parent.owner.close() )	
fn onSizeChanged s a =
(
	local top = s.OwnedForms[1] 
	if top != undefined do top.Size = s.ClientSize
)
fn onLocationChanged s a = 
(
	local top = s.OwnedForms[1] 
	if top != undefined do top.location = s.PointToScreen (dotnetclass "System.Drawing.Point").Empty
)	
fn onLoad s a =
(
	tb = dotnetobject "Button"
	tb.text = "Top Button"
	tb.backColor = netDrColor green
	tb.Dock = tb.Dock.Top
	
	bb = dotnetobject "Button"
	bb.text = "Close"
	bb.backColor = netDrColor green
	bb.Dock = bb.Dock.Bottom
	
	top = dotnetobject "Form"
	top.StartPosition = top.StartPosition.Manual
	top.ShowInTaskBar = false
	top.FormBorderStyle = top.FormBorderStyle.None
	top.TransparencyKey = top.BackColor
	top.Controls.addrange #(tb, bb)
	
	dotNet.addEventHandler bb "MouseUp" closeTopForm

	s.AddOwnedForm top
	top.Location = s.PointToScreen (dotnetclass "System.Drawing.Point").Empty
	top.Size = s.ClientSize
	top.Show()
)

dotNet.addEventHandler form "Load" onLoad
dotNet.addEventHandler form "LocationChanged" onLocationChanged	
dotNet.addEventHandler form "ClientSizeChanged" onSizeChanged

form.Show(WindowWrapper)


show the form modelessly means show the form and set the main application’s window (main MAX window in our case) as the parent.

here is a pretty good explanation:
http://en.wikipedia.org/wiki/Dialog_box#Modeless