Playing Animated GIFs in PictureBox
To play an animated GIF file in Wise SCADA, you must load the image at runtime using a small C# script triggered by the screen’s Load event.
Implementation Steps for This Script
Sample Script Structure
The following code block locates the GIF file at the specified path when the screen opens and loads it “live” into the PictureBox:
To ensure this specific script works correctly, please follow these steps:
- Standard File Path: Place the GIF file in a permanent directory that Wise SCADA can access.
- Critical Note: The imagePath variable defined in the script must exactly match the physical location of the file (e.g., C:\Wise_Images\animation.gif).
- If you migrate your project to another computer, remember to move this folder and the GIF file to the same directory structure.
- Object Identity (Name): Check the Name property of the PictureBox object you added via the screen editor.
- Since this script searches for the object by its name, it must be exactly “PictureBox_0” (or whatever name you specified in the code). If the names do not match, the object will not be found, and the script will stop without executing.
- Event Assignment: This script must be defined within the screen’s Load event.
- Click on an empty area of the screen and navigate to the Events tab in the properties panel.
- Double-click the box next to the Load event.
- Select the script you created. The system will automatically redirect you to the script editor and generate the Screen_Load method correctly assigned to the screen.
/* SCADA tags can be accessed in two ways:
1. Define tags as public fields in MainClass. Values are read before the script runs and written back after execution.
2. Use TagRead and TagSet methods to read/write values dynamically during script execution.
Read Example: INT Value = (INT)TagRead("Tag_0"); If the tag doesn't exist, TagRead returns null. If null or incorrect type, the script will not run.
Write Example: BOOL Result = TagSet("Tag_0", 123); If successful, Result will be true; otherwise, it will be false.
Note: You can access the last read and last write times of tags within scripts, as well as SCADA functions. For more information, refer to the help pages.
*/
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.CSharp;
public class MainClass
{
// Define SCADA tags here, for example: public BOOL Tag_1; You can use 'CTRL + Add' to add a Tag.
public void Main()
{
}
public void Screen_Load(Object sender, EventArgs e)
{
Form form = (Form)sender;
// Accessing the PictureBox object on the form by its name.
PictureBox pictureBox = form.Controls["PictureBox_0"] as PictureBox;
if (pictureBox == null)
{
MessageBox.Show("PictureBox_0 was not found on the form.");
return;
}
// Full path of the GIF file (The file must exist in this directory on the target computer.)
string imagePath = @"C:\Wise_Images\animation.gif";
if (System.IO.File.Exists(imagePath))
{
pictureBox.Image = System.Drawing.Image.FromFile(imagePath);
}
else
{
MessageBox.Show("GIF file not found: " + imagePath);
}
}
}
Important Tips and Considerations
- Object Name: If you intend to use multiple PictureBox objects, remember to update the form.Controls[“PictureBox_Name”] section for each one.
- Performance: Using very large GIF files or a high number of animated GIFs simultaneously may affect screen transition speeds on low-end hardware.
