WinForms Reference
WinForms Reference
To pass a value from UiPath to a WinForm, you can use interprocess communication (IPC)
techniques such as named pipes or sockets.
Here's an example of how to use named pipes to pass a value from UiPath to a WinForm:
1. Create a named pipe server in your WinForm application. This can be done using the
NamedPipeServerStream class in C#. Here's an example:
pipeServer.WaitForConnection();
pipeServer.Disconnect();
This code creates a named pipe server with the name "myPipeName", waits for a connection from a
client, reads a string value from the pipe, and then disconnects from the client
2. In your UiPath workflow, create a named pipe client to connect to the named pipe server in
your WinForm application. This can be done using the
System.IO.Pipes.NamedPipeClientStream class. Here's an example:
pipeClient.Connect();
writer.WriteLine("myValue");
writer.Flush();
pipeClient.WaitForPipeDrain();
pipeClient.Close();
This code creates a named pipe client that connects to the named pipe server with the name
"myPipeName" on the local machine, writes a string value "myValue" to the pipe, and then
disconnects from the server.
3. In your WinForm application, read the value passed from UiPath using the named pipe
server code shown in step 1
Note that you should ensure that the named pipe names used in your WinForm and UiPath
applications match, and that your WinForm application is running and listening for connections
before you attempt to pass the value from UiPath
Databinding:
(or)
To change the font size of a WinForm control on runtime using data binding, you can bind the Font
property of the control to a font object and use a converter to modify the font size dynamically. Here
are the steps:
2. Create a data binding object and bind it to the control's Font property:
binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
txtName.DataBindings.Add(binding);
In this example, "MyFont" is a property in your form class that returns the font object you want to
use. The DataSourceUpdateMode property is set to OnPropertyChanged, so the font will be updated
whenever the MyFont property is changed.
3. Create a converter to modify the font size:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
return value;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
This converter takes a font object and a double value representing the font size. It returns a new font
object with the specified size.
4. Set the MyFont property in your form class to update the font size:
set
{
_myFont = (Font)fontSizeConverter.Convert(value, typeof(Font), 16,
CultureInfo.InvariantCulture);
OnPropertyChanged(nameof(MyFont));
In this example, the font size is set to 16, but you can change it to any value you want. The
OnPropertyChanged method is called to notify the data binding system that the MyFont property
has changed.
When the MyFont property is updated, the converter is called to modify the font size, and the new
font object is used to update the Font property of the control. This will update the font size of the
control in real-time.