修订历史 [返回]
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下:
1、打开Visual Studio 2022
2、选择Project Service Extension创建程序
3、在public void Start(IProject context, IBehavior behavior)过程中创建你所需要的事件
4、在触发事件中定义你所需执行的功能
5、最后,不要忘记在public void Stop()中删除你所创建的事件
以下是一个触发事件的代码示例
C#
using System;
using Scada.AddIn.Contracts;
using Scada.AddIn.Contracts.Screen;
using System.Linq;
using System.Diagnostics;
namespace Samples
{
[AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")]
public class EditorWizardExtension_ScreenElement_ScreenElement_Move :IProjectServiceExtension
{
IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events
public void Start(IProject context, IBehavior behavior)
{
screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
}
}
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下:
1、打开Visual Studio 2022
2、选择Project Service Extension创建程序
3、在public void Start(IProject context, IBehavior behavior)过程中创建你所需要的事件
4、在触发事件中定义你所需执行的功能
5、最后,不要忘记在public void Stop()中删除你所创建的事件
以下是一个触发事件的代码示例
C#
using System;
using Scada.AddIn.Contracts;
using Scada.AddIn.Contracts.Screen;
using System.Linq;
using System.Diagnostics;
namespace Samples
{
[AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")]
public class EditorWizardExtension_ScreenElement_ScreenElement_Move :IProjectServiceExtension
{
IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events
public void Start(IProject context, IBehavior behavior)
{
screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
}
}
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下:
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下: 1、打开Visual Studio 2022
2、选择Project Service Extension创建程序
3、在public void Start(IProject context, IBehavior behavior)过程中创建你所需要的事件
4、在触发事件中定义你所需执行的功能
5、最后,不要忘记在public void Stop()中删除你所创建的事件
以下是一个触发事件的代码示例
C#
C#
using System;
System;
using Scada.AddIn.Contracts;
Scada.AddIn.Contracts;
using Scada.AddIn.Contracts.Screen;
Scada.AddIn.Contracts.Screen;
using System.Linq;
System.Linq; using System.Diagnostics;
namespace Samples
{
Samples
{
[AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")]
public class EditorWizardExtension_ScreenElement_ScreenElement_Move EditorWizardExtensionScreenElementScreenElement_Move :IProjectServiceExtension
{
{
IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events
public void Start(IProject context, IBehavior behavior)
{
{
screenCollection = context.ScreenCollection;
context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
} }
}
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下:
1、打开Visual Studio 2022
2022
2、选择Project Service Extension创建程序
Extension创建程序
3、在public void Start(IProject context, IBehavior behavior)过程中创建你所需要的事件
4、在触发事件中定义你所需执行的功能
behavior)过程中创建你所需要的事件 4、在触发事件中定义你所需执行的功能 5、最后,不要忘记在public void Stop()中删除你所创建的事件
以下是一个触发事件的代码示例
C#
using System; using Scada.AddIn.Contracts; using Scada.AddIn.Contracts.Screen; using System.Linq; using System.Diagnostics;
namespace Samples { [AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")] public class EditorWizardExtensionScreenElementScreenElement_Move :IProjectServiceExtension { IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events public void Start(IProject context, IBehavior behavior) { screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
} }
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下: 1、打开Visual Studio 2022 2、选择Project Service Extension创建程序 3、在public void Start(IProject context, IBehavior behavior)过程中创建你所需要的事件 4、在触发事件中定义你所需执行的功能 5、最后,不要忘记在public void Stop()中删除你所创建的事件
以下是一个触发事件的代码示例
在这里输入代码
C#namespace Samples { [AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")] public class EditorWizardExtensionScreenElementScreenElement_Move :IProjectServiceExtension { IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events public void Start(IProject context, IBehavior behavior) { screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
} }
C# using System; using Scada.AddIn.Contracts; using Scada.AddIn.Contracts.Screen; using System.Linq; using System.Diagnostics;
namespace Samples { [AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")] public class EditorWizardExtensionScreenElementScreenElement_Move :IProjectServiceExtension { IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events public void Start(IProject context, IBehavior behavior) { screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
} }
可以使用zenon的AddIn功能来实现创建自定义事件的需求,具体如下: 1、打开Visual Studio 2022 2、选择Project Service Extension创建程序 3、在public void Start(IProject context, IBehavior behavior)过程中创建你所需要的事件 4、在触发事件中定义你所需执行的功能 5、最后,不要忘记在public void Stop()中删除你所创建的事件
以下是一个触发事件的代码示例
在这里输入代码
以下是一个触发事件的代码示例 C# using System; using Scada.AddIn.Contracts; using Scada.AddIn.Contracts.Screen; using System.Linq; using System.Diagnostics;
namespace Samples { [AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")] public class EditorWizardExtensionScreenElementScreenElement_Move :IProjectServiceExtension { IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events public void Start(IProject context, IBehavior behavior) { screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
} }
C# using System; using Scada.AddIn.Contracts; using Scada.AddIn.Contracts.Screen; using System.Linq; using System.Diagnostics;
namespace Samples { [AddInExtension("ScreenElement.ScreenElement.Move", "Moves the Button around", "Samples")] public class EditorWizardExtensionScreenElementScreenElement_Move :IProjectServiceExtension { IScreenCollection screenCollection = null;//we keep a reference of screencolltection so we don't loose the reference to our events public void Start(IProject context, IBehavior behavior) { screenCollection = context.ScreenCollection;
//We look for the Screen named "SIMUL Information"(which may be create with projec wizard)
//and and simulate
if (!screenCollection.Any(item => item.Name == "Start"))
{
//we didn't find the screen return
Debug.Print("Screen not found!");
return;
}
screenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp;
}
private void ScreenCollection_ElementRightButtonUp(object sender, ElementRightButtonUpEventArgs e)
{
//if a element is RightButtonUp we move to upper right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 0, 1700, 110);
}
}
private void ScreenCollection_ElementRightButtonDown(object sender, ElementRightButtonDownEventArgs e)
{
//if a element is RightButtonDown we move to lower right corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 800, 1200, 900);
}
}
private void ScreenCollection_ElementRightButtonDoubleClick(object sender, ElementRightButtonDoubleClickEventArgs e)
{
//if a element is right double clicked we move to middle right
if (e.Element.Name == "MyButton")
{
e.Element.Move(1600, 400, 1700, 500);
}
}
private void ScreenCollection_ElementLeftButtonUp(object sender, ElementLeftButtonUpEventArgs e)
{
//on if a element is LeftButtonUp we move to upper left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 0, 100, 100);
}
}
private void ScreenCollection_ElementLeftButtonDown(object sender, ElementLeftButtonDownEventArgs e)
{
// on if a element is LeftButtonDown we move to lower left corner
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 800, 100, 900);
}
}
private void ScreenCollection_ElementLeftButtonDoubleClick(object sender, ElementLeftButtonDoubleClickEventArgs e)
{
// on if a element is LeftDoubleClicke we move left side
if (e.Element.Name == "MyButton")
{
e.Element.Move(0, 400, 100, 500);
}
}
public void Stop()
{
//Remove all eventhandler
screenCollection.ElementLeftButtonDoubleClick -= ScreenCollection_ElementLeftButtonDoubleClick;
screenCollection.ElementLeftButtonDown -= ScreenCollection_ElementLeftButtonDown;
screenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
screenCollection.ElementRightButtonDoubleClick -= ScreenCollection_ElementRightButtonDoubleClick;
screenCollection.ElementRightButtonDown -= ScreenCollection_ElementRightButtonDown;
screenCollection.ElementRightButtonUp -= ScreenCollection_ElementRightButtonUp;
}
} }