WinStudio
This topic gives a simple example of building a .NET WinForms user control and hosting it as a user control component on a WinStudio form. The example illustrates types of communication from a control to WinStudio and from WinStudio to a control. Specifically,
using Mongoose.WinStudio.Runtime;
public partial class UserControl1 : WSUserControlBase
public override bool Invoke( string args )
{
bool success = true;
if ( args.Substring( 0, 8 ) == "SETTEXT " )
this.textBox1.Text = args.Substring( 8, args.Length-8 );
return success;
}
ThisForm.Variables("UserControlValue").Value = textBox1.Text;
ThisForm.GenerateEvent("UserControlClicked");
(Note that IntelliSense is available for the WinStudio API, as it is
when writing client WinStudio scripts.)"SETTEXT P(propname)"specifying the name of a property on the form.
V(UserControlValue): SETPROPVALUES(propname=V(UserControlValue))
The result should be that you can type in a component bound to the property you used on your form and click the button, to display the property's value in your user control, and click on the user control's button to move the text from your user control into the property you used.
NOTE: The steps to create a WinStudio-hostable user control from a specific existing user control are very similar. Rather than derive a new class from WSUserControlBase and IWinStudioUserControl, you add a reference to the existing specific user control and derive from that class and the IWinStudioUserControl interface.
These steps implement the same functionality as in the Windows control above, and assume that you are working in the same form, creating a UserControl component that works both in Windows and the Web.
NOTE: The Web user control should be a project created using .NET 4/Visual Studio 2010.
{
Public Overrides Function Invoke(ByVal args As String) As Boolean
If args = "READY" Then
Me.QueueClientResponse("SETTEXT Server link established.")
ElseIf args.Substring(0, 8) = "SETTEXT " Then
Me.QueueClientResponse(args)
ElseIf args.Substring(0, 8) = "FROMWEB " Then
ThisForm.Variables("UserControlValue").Value =
args.Substring(8, args.Length - 8)
ThisForm.GenerateEvent("UserControlClicked")
End If
Return True
End Function
}
If the assembly must be available to all applications, copy it instead to the Application folder, for example, C:\inetpub\wwwroot\WSWebClient\Application\. If the file exists in both places, the first folder specified above takes precedence.
<html>
<head>
<title>Simple User Control
<script type="text/javascript" src="Scripts/WSUserControl.js">
<script type="text/javascript">
function handleResponse(msg) {
// callback from WinStudioRuntime hosting the server portion of the usercontrol
// Button on parent Form was clicked. Update a field on the Control using passed in values.
// stripping off the leading "SETTEXT "
var newValue = msg.split(" ").slice(1).join(" ");
document.getElementById("MainContent_TextBox").value = newValue;
}
// Clicking link on UserControl fires an event that is passed to the hosted assembly's Invoke
function linkClicked() {
// this will call back into the hosted UserControl assembly's Invoke method
var newValue = document.getElementById("MainContent_TextBox").value;
WSUserControl.generateServerEvent("FROMWEB " + newValue);
}
function pageInit() {
// Register Callback - Parent Form will call this method for all data being passed
WSUserControl.registerCallback(handleResponse);
// When communication has been established, send READY message to server
WSUserControl.onReady(function() {
WSUserControl.generateServerEvent("READY");
});
}
</script>
</head>
<body onload="pageInit()">
<p>
<a href="#" onclick="linkClicked()">To Form
</p>
<p>
Content from Form
<input type="text" id="MainContent_TextBox" />
</p>
</body>
</html>Invoke User Control Response Type