Page 1 of 1

Changing Text color based on instance id number

Posted: Fri Oct 18, 2013 9:10 am
by jmkowol
Hello
I am fairly new to the iX Developer and have a question.

I have a screen used in 2 instances (ans aliases) and would like to change the color attributes of some of the Text entries or other visualization elements based on instance.
I know I could create "Dummy variables" for each instance use them like constants and than using the number in the Variable as value for color change in the #Alias on the screen.
Is there a more "elegant" and a rather more straight way to do so using script functions.
Thanks in Advance
J

Re: Changing Text color based on instance id number

Posted: Fri Oct 18, 2013 9:29 am
by mark.monroe
You would have to somehow execute code that checks to see what instance you are on. You can execute via a button push or when a screen is opened. Then I would set a tag based on the instance.

The tag could then be used in the Dynamics of a on screen control to change the color.

Re: Changing Text color based on instance id number

Posted: Fri Oct 18, 2013 9:50 am
by jmkowol
Well,
What code checks for the active instance?
Sorry for the stupid question. But I am really new to the iX developer. :)

Re: Changing Text color based on instance id number

Posted: Fri Oct 18, 2013 10:19 am
by mark.monroe
This code gets the active instance: this.InstanceName;

Unfortunately I cannot provide you with C# programming consulting services. I can only help with iX Developer related C# questions. Writing if statements and the such are out of this forums scope.

If you have never programmed in C# I suggest you take a course on it.

Re: Changing Text color based on instance id number

Posted: Fri Oct 18, 2013 10:28 am
by jmkowol
Thank, you . This was what I needed to know.

Re: Changing Text color based on instance id number

Posted: Sun Oct 20, 2013 2:47 am
by Edmund
Hi!

Here is a little example with changing things based on instance with scripts.

The Motor_Faceplate has three instance (Motor_1, Motor_2, Motor_3).

In the example we change the Name, Font Color of the Name, The Fill Color of the Name, The Motor base color and Hide the Analog Setpoint for the Motor 2.
Motor_Popup.png
Motor_Popup.png (80.91 KiB) Viewed 21908 times
The first image from left is the base faceplate, second Motor 1 and so on...

Code: Select all

 public partial class Motor_Faceplate
    {
		
		void Motor_Faceplate_Opened(System.Object sender, System.EventArgs e)
		{
			// Set Instance Name to Header (remove underscore)
			txtMotorName.Text = this.InstanceName.Replace('_', ' ');
			
			
			// Check instance
			switch(this.InstanceName)
			{
				case "Motor_1": 
					txtMotorName.FontColor = new BrushCF(Color.Blue);
					txtMotorName.Fill = new BrushCF(Color.DarkGray);
					recMotorBase.Fill = new BrushCF(Color.Blue);
					break;
				
				case "Motor_2": 
					txtMotorName.FontColor = new BrushCF(Color.Green);
					txtMotorName.Fill = new BrushCF(Color.Red);
					recMotorBase.Fill = new BrushCF(Color.Green);
					txtSetpoint.Visible = false;
					break;
				
				case "Motor_3": 
					txtMotorName.FontColor = new BrushCF(Color.Aqua);
					txtMotorName.Fill = new BrushCF(Color.White);
					recMotorBase.Fill = new BrushCF(Color.Aqua);
					break;
				
			}		
		}
    }
Sorry for the ugly color combinations ;)

Best Regards

Re: Changing Text color based on instance id number

Posted: Wed Oct 23, 2013 7:59 am
by jmkowol
Edmund,
Thanks a lot :D
J