Dotnet TabControls dilema

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 08 August 2008   #1
Dotnet TabControls dilema

Hi guys,

I have searched about trying to find an answer to this and a number of posts come close but not quite enough info for me to actually cope! I am trying to get a basic DOT NET tabcontrol to work, since my boss has insisted a new tool that I have written has one.

This is my attempt so far




--Destroy dialog if it already exists.
try(destroyDialog theRollout)catch()

--Create a rollout
rollout theRollout "The Rollout" width:300
(
	--Create the dotNet TabControl 
	dotNetControl tc "system.windows.forms.tabcontrol" height:200

	fn initTc thetc=
	(
        --Manually build 3 tab pages
        t1 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 1"
        t3 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 2"
        t2 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 3"

        --How do I then add controls to these tab pages!?!?
	--l1 = dotNetobject "System.Windows.Forms.Label"
	--l1.Text = "Moo"

	--t1.controls.add l1

	thetc.controls.add t1
	thetc.controls.add t2
	thetc.controls.add t3

	
	)
	
	on theRollout open do
	(
	initTc tc
	)

)
createDialog theRollout	


The above code creates a basic Tab Control with 3 tabpages really nicely. But I cannot figure out how to add any controls to any of the tab pages. The commented out code shows my attempts (and thought process), which is clearly wrong! I have seen other discussions mentioning sub rollouts, but I have tried creating separate rollouts and then adding them to the tabpages as subrollouts and I just keep getting errors!

MSDN shows examples of UI elements being added using the line:


t1.controls.add l1


where t1 is a tabpage and l1 is a simple UI element (say label)

Could anyone guide me in how to actually add UI elements to the separate TabPages! I would be really grateful. Examples or instruction more than welcome!

Thanks for your time everyone,

Rich
 
Old 08 August 2008   #2
Penny slowly dropping?

Hi guys,

Is the solution to hide and reveal subrollouts on a Tabcontrol clicked event, rather than trying to add the subrollouts to the Tabcontrol pages themselves?

Any milage in that approach....

Cheers

Rich
 
Old 08 August 2008   #3
I found this piece of code on the .net thread some weeks ago. It creates some UI stuff inside the tab page. Not MAX rollouts, but I guess the command would be the same. Hope it's useful


 (
  dotnet.loadassembly "System.Data" 
  
 Color = dotNetClass "System.Drawing.Color" 
 ScrollBars = dotNetClass "System.Windows.Forms.ScrollBars"
   
 -- Create Tabs Container 
  tabControl1 = dotnetobject "system.windows.forms.TabControl"
  tabControl1.size = dotnetobject "system.drawing.size" 395 195
  tabControl1.Location = dotnetobject "System.Drawing.Point" 0 0 
   
 --Create Tabs
  tabPage1 = dotnetobject "System.Windows.Forms.TabPage"
  tabPage1.text = "Goodbye World"
  tabPage2 = dotnetobject "System.Windows.Forms.TabPage"
  tabPage2.text = "Hello World"
  tabPage1.backColor = color.fromArgb 200 200 200 
  tabPage2.backColor = color.fromArgb 200 200 200 
   
 -- Add Some Columns to the Datagrid
  dt = dotnetobject "system.data.DataTable""Test"
  Column1 = dotnetobject "System.Data.DataColumn" "id" (dotnetclass "System.Int32")
  Column2 = dotnetobject "System.Data.DataColumn" "Name" (dotnetclass "System.String")
  dt.columns.add Column1
  dt.columns.add Column2
    
 for i=0 to 2 do 
 (
 	 row=#(dotnetobject "System.Int32" i,dotnetobject "System.String" (i as string)) 
 	 dt.rows.add row
  )
    
 -- Create Datagrid
  DGrid1 = dotnetobject "System.Windows.Forms.DataGrid"
  DGrid1.Location = dotNetObject "System.Drawing.Point" 10 10
  DGrid1.Width = 365
  DGrid1.Height = 120
  DGrid1.Visible = true
  DGrid1.DataSource = dt 
   
 -- Create TextBox
  TB1TextBox = dotNetObject "System.Windows.Forms.TextBox"
  TB1TextBox.Location = dotNetObject "System.Drawing.Point" 10 10
  TB1TextBox.Width = 365
  TB1TextBox.Height = 120
  TB1TextBox.Visible = true
  TB1TextBox.MultiLine = true
  TB1TextBox.ScrollBars = ScrollBars.Vertical
  TB1TextBox.AcceptsReturn = true
  TB1TextBox.AcceptsTab = true
  TB1TextBox.WordWrap = true
   
 -- Create Buttons
  
 button01 = dotnetobject "System.Windows.Forms.button"
  button01.text = "goodbye" 
 button01.Location = dotNetObject "System.Drawing.Point" 300 138
    
 -- Create Form
  TabForm = dotNetObject "System.Windows.Forms.Form"
  TabForm.Size = dotNetObject "System.Drawing.Size" 400 225
  TabForm.Text = "Title"
  TabForm.TopMost = true
  FormBorderStyle = dotNetClass "System.Windows.Forms.FormBorderStyle"
  TabForm.FormBorderStyle = FormBorderStyle.FixedDialog
  TabForm.ShowInTaskbar = false
  TabForm.MinimizeBox = true
  TabForm.MaximizeBox = false
  Tabform.helpbutton = true
   
 -- Add UI elements to Tabs
  tabpage1.controls.add(TB1textbox)
  tabpage1.controls.add(button01)
  tabpage2.controls.add(DGrid1)
   
 -- Add Tabs to Tab Container
  tabcontrol1.controls.add(tabpage1)
  tabcontrol1.controls.add(tabpage2)
  
  -- Add Tab Container to UI Form
  TabForm.Controls.Add(tabcontrol1)
  
 -- Show application Form
  TTApp = dotNetClass "System.Windows.Forms.Application"
  TTApp.Run TabForm
  
 )
__________________
The Lady and the Reaper, Oscar-nominated animated short, here
 
Old 08 August 2008   #4
By the way, in your script change:

 t1.controls.add l1 
 

for
t1.controls.add(l1)


It should work
__________________
The Lady and the Reaper, Oscar-nominated animated short, here
 
Old 08 August 2008   #5
When ever i have used them I have just used add and remove rollouts as I have wanted to be able to use standard max script UI items as well. It works well but you need to manage the changing of the tabs instead of manging the code needed for dotNet.
__________________
Paul Neale
http://paulneale.com
 
Old 08 August 2008   #6
Sorry to pipe in, but Paul and EverZen are right, I stole the idea from Bobo originally, who I think used it originally in the Deadline maxscript.

If you pop over to his site on script spot, you should be able to find some sample code.

Also do a search on the forum, I've replied to at least two questions on the subject...not very useful as I suggested exactly what I've suggested to you...why repeat what is great work...get it from the master himself.

Shane
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
Old 08 August 2008   #7
Much Appreciated!

Hi guys, thanks for the awesome set of replies.

Cheers Iker for digging up that code. It is really useful to see a broader application that ties in other Dot Net UI elements. I am definitely more confident after picking my way through that!

Paul and Shane, it was actually from bumping into another of your posts that got me to move in the subrollout direction. In this case adding and removing subrollouts has worked brilliantly and for my case it is better to stick to maxscript UI elements for most of the tool, since there is all the functionality that I need.

Much appreciated guys. Knowing these sorts of tricks are going to really help get some smoother UIs out. Really helpful stuff!

Thanks for your time,

Rich
 
Old 08 August 2008   #8
For Completeness....

For anyone that is interested this is how I addressed the final TabControl Code using the subrollout solution. I have used the MouseDown event and queried the index of the selected tab in order to know which rollouts to add and remove. This might not be the best way to do things, but it has worked for me so far.

The example is an adaption of the ActiveX example, but for DotNet. If it helps feel free to use it. If there is a better way to write it then feel free to comment too!

Thanks for everyones help




--Destroy dialog if it already exists.
try(destroyDialog theRollout)catch()


rollout firstRollout "Rollout 1" (
edittext edittext01 text:"This is just a test." height:135 width:262 )

rollout secondRollout "Rollout 2" (
listbox listbox02 items:#("Line One","MAXScript Rocks","DotNet Too") width:260 )

rollout thirdRollout "Rollout 3" (
listbox multilistbox02 items:#("Option1","Option2","Option3") width:260 )



--Create a rollout
rollout theRollout "The Rollout" width:300
(
	--Create the dotNet TabControl control
dotNetControl tc "system.windows.forms.tabcontrol" height:25

--Create our subrollout that we can use to hide and reveal our different rollout choices
subRollout theSubRollout height:200

--Create a setup function for the DOT Net elements
fn initTc thetc=
	(
	--Create 3 Tab Pages
    t1 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 1"
    t2 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 2"
    t3 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 3"

        --Add the rollout to be initialise on the first Tabpage
   	addSubRollout theSubRollout  firstRollout height:200

        --Add the Tabpages to the TabControl
	thetc.controls.add t1
	thetc.controls.add t2
	thetc.controls.add t3
	)
	
	on tc mousedown arg do
		(	
                --Check which Tab is selected, and reveal the appropriate rollouts! 	
		case tc.SelectedTab.TabIndex of
		(
		0:
			(
			try
				(
				removeSubRollout theSubRollout secondRollout
				removeSubRollout theSubRollout thirdRollout
				)
			catch()

   			addSubRollout theSubRollout  firstRollout height:200
			)
		1:
			(
			try
				(
				removeSubRollout theSubRollout firstRollout
				removeSubRollout theSubRollout thirdRollout
				)
			catch()

   			addSubRollout theSubRollout secondRollout height:200
			)
		2:
			(
			try
				(
				removeSubRollout theSubRollout firstRollout
				removeSubRollout theSubRollout secondRollout
				)
			catch()

   			addSubRollout theSubRollout thirdRollout height:200
			)
		)

		)--End if mousedown

	on theRollout open do
	(
	initTc tc
	)

)
createDialog theRollout	height:230




Have fun....
 
Old 08 August 2008   #9
Thanks! Great stuff!

*files snippet in local inspiration folder*


-Johan
__________________
Online: LinkedIn
 
Old 08 August 2008   #10
That is just about what I have done, I think it is the best way if you want to be able to use standard Max controls as well as DotNet.

Originally Posted by EverZen: For anyone that is interested this is how I addressed the final TabControl Code using the subrollout solution. I have used the MouseDown event and queried the index of the selected tab in order to know which rollouts to add and remove. This might not be the best way to do things, but it has worked for me so far.

The example is an adaption of the ActiveX example, but for DotNet. If it helps feel free to use it. If there is a better way to write it then feel free to comment too!

Thanks for everyones help


 
 
 --Destroy dialog if it already exists.
 try(destroyDialog theRollout)catch()
 
 
 rollout firstRollout "Rollout 1" (
 edittext edittext01 text:"This is just a test." height:135 width:262 )
 
 rollout secondRollout "Rollout 2" (
 listbox listbox02 items:#("Line One","MAXScript Rocks","DotNet Too") width:260 )
 
 rollout thirdRollout "Rollout 3" (
 listbox multilistbox02 items:#("Option1","Option2","Option3") width:260 )
 
 
 
 --Create a rollout
 rollout theRollout "The Rollout" width:300
 (
 	--Create the dotNet TabControl control
 dotNetControl tc "system.windows.forms.tabcontrol" height:25
 
 --Create our subrollout that we can use to hide and reveal our different rollout choices
 subRollout theSubRollout height:200
 
 --Create a setup function for the DOT Net elements
 fn initTc thetc=
 	(
 	--Create 3 Tab Pages
     t1 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 1"
     t2 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 2"
     t3 = dotNetObject "System.Windows.Forms.TabPage" "Tabpage 3"
 
         --Add the rollout to be initialise on the first Tabpage
    	addSubRollout theSubRollout  firstRollout height:200
 
         --Add the Tabpages to the TabControl
 	thetc.controls.add t1
 	thetc.controls.add t2
 	thetc.controls.add t3
 	)
 	
 	on tc mousedown arg do
 		(	
                 --Check which Tab is selected, and reveal the appropriate rollouts! 	
 		case tc.SelectedTab.TabIndex of
 		(
 		0:
 			(
 			try
 				(
 				removeSubRollout theSubRollout secondRollout
 				removeSubRollout theSubRollout thirdRollout
 				)
 			catch()
 
    			addSubRollout theSubRollout  firstRollout height:200
 			)
 		1:
 			(
 			try
 				(
 				removeSubRollout theSubRollout firstRollout
 				removeSubRollout theSubRollout thirdRollout
 				)
 			catch()
 
    			addSubRollout theSubRollout secondRollout height:200
 			)
 		2:
 			(
 			try
 				(
 				removeSubRollout theSubRollout firstRollout
 				removeSubRollout theSubRollout secondRollout
 				)
 			catch()
 
    			addSubRollout theSubRollout thirdRollout height:200
 			)
 		)
 
 		)--End if mousedown
 
 	on theRollout open do
 	(
 	initTc tc
 	)
 
 )
 createDialog theRollout	height:230
 
 
 
 


Have fun....
__________________
Paul Neale
http://paulneale.com
 
Old 08 August 2008   #11
sweet - i was trying to figure this out only yesterday. I'll have a better look when i get into work. Thanks!
 
Old 08 August 2008   #12
Originally Posted by IkerCLoN: I found this piece of code on the .net thread some weeks ago. It creates some UI stuff inside the tab page. Not MAX rollouts, but I guess the command would be the same. Hope it's useful


LOL. I ran that script and thought to myself. "Wow that's super handy I should thank whoever wrote that and ask them to write more like it... and they even use the same sorts of variable names I use... weird... and.... heeyyyy I know that script."
 
Old 08 August 2008   #13
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:38 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.