Simple Move Control Script

Here’s a quick and easy script to simply move a control on the panel, it takes the control name and new positions as the arguments.

Determining the name of a control is pretty simple, right click on the field -> Advanced -> Show Field Information

WIT0115 is the field name for the Item Label

And the script itself

/*
**	Name:	MoveControl.js
**
**	Description:
**	 Change the position of a control
**
**	Arguments:
**
**	<Control Name>,<column>,<row>
**
**	Eg.
**		WEITNO,15,2
**	 will move the control WEITNO to column 15, row 2
**
**	Written By:	scott.campbell@potatoit.kiwi
**
**
*/

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript
{
	class MoveControl
	{
		var gDebug = null;

		public function Init(element: Object, args: Object, controller : Object, debug : Object)
		{
			var content : Object = controller.RenderEngine.Content;
			gDebug = debug;
			try
			{
				if(null != args)
				{
					var argumentArray = args.split(",");

					if(null != argumentArray)
					{
						if(argumentArray.length > 2)
						{
							var control = ScriptUtil.FindChild(content, argumentArray[0]);
							if(null != control)
							{
								var column = int.Parse(argumentArray[1]);
								var row = int.Parse(argumentArray[2]);
								setPosition(control, column, row);
							}
						}
					}

				}
			}
			catch(ex)
			{
				debug.Error(ex);
			}
		}

		private function setPosition(aControl, aColumn, aRow)
		{
			if(null != aControl)
			{
				gDebug.Debug("Set Controls Position");
				gDebug.Debug(" +-- Control: " + aControl.Name);
				gDebug.Debug(" +---- Column: " + aColumn);
				gDebug.Debug(" +---- Row: " + aRow);
				Grid.SetColumn(aControl, aColumn);
				Grid.SetRow(aControl, aRow);
			}
		}
	}
}

This entry was posted in Development, M3 / MoveX, Misc. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s