Display Form through UIPath

Hello all,
Is that Possible to display a Windows form through UIPath?
I tried with Balloon tool tips. its worked.

            var frm = new Form();
            frm.Name = "Hello";
           

            ProgressBar bar = new ProgressBar();
            bar.Location = new System.Drawing.Point(50, 20);
            bar.Name = "progressBar1";
            bar.Size = new System.Drawing.Size(171, 23);
            bar.TabIndex = 0;
            bar.Style = ProgressBarStyle.Marquee;
            bar.Minimum = 0;
            bar.Maximum = 100;
            frm.Controls.Add(bar);
            frm.Show(); 

I need to implement this code in UIPath. can anyone help me?

2 Likes

@Florent_Salendres any way the new Invoke Code activity could support something like this?

Hi Richard,

This would be that way in VB.Net

Dim frm As New System.Windows.forms.form

Dim bar As ProgressBar = New ProgressBar()
bar.Location = New System.Drawing.Point(50, 20)
bar.Name = “progressBar1”
bar.Size = New System.Drawing.Size(171, 23)
bar.TabIndex = 0
bar.Style = ProgressBarStyle.Marquee
bar.Minimum = 0
bar.Maximum = 100
frm.Controls.Add(bar)
frm.Show()

Importing System.windows.Forms first is required, note also that you will get no intelisense from it inside the code activity.

However, once the last step of the workflow will finish, the form will disapear.
to test it you can use a message box activty after the code activity to block the thread.

However to do this kind of thing i would rather strongly recommend either using Custom Activities or even making an .exe with visual studio and starting process using the file path, then killing or close mainwindow from once everything is done.

Cheers.

7 Likes

hi @Florent_Salendres,
thanks for the reply,

i tried to add control to the form using invoke method activity like this.

but i am getting error after add this activity like this,

i tried with add to collection activity. its not accepting to add ProgressBar object. how to over come this with UiPath?

1 Like

Hello,

You would need to use Invoke Code activity rather than Invoke method.
Using is probably possible but would be quite tedious.

Invoke Code activity is available with the last version of the Community version for the time being.

It looks like this.

Once you have it you can copy/paste the VB.Net code from my previous code and it should work.

Cheers.

5 Likes

@Florent_Salendres,
Thanks for your post. I agree that a custom activity is better, but I’m struggling to get Invoke Code to do what I want in UiPath, so this is more an exercise in doing that.
I imported System.Windows.Forms, and pasted your code (without mods) into an Invoke Code window.
I added a message box to block the thread. (When that failed, I tried with System.Reflection, also without success.)
Can you point out to me where I’m going wrong, if you have time? I’ve attached screenshots and the .xaml I used.
Best regards and thanks in advance,
burque505
.xaml: Main.xaml (9.1 KB)

Error without reflection used.

Error with reflection used.

Hello,

You were pretty close, just some small change to make on the code first:

Dim formsA As AssemblyReference=System.Reflection.Assembly.LoadWithPartialName(“System.Windows.Forms”)
Using formsA
Dim frm As Form = New Form
Dim bar As ProgressBar = New ProgressBar()
bar.Location = New System.Drawing.Point(50, 20)
bar.Name = “progressBar1”
bar.Size = New System.Drawing.Size(171, 23)
bar.TabIndex = 0
bar.Style = ProgressBarStyle.Marquee
bar.Minimum = 0
bar.Maximum = 100
frm.Controls.Add(bar)
frm.Show()
End Using

Remove part in bold, We will use another way to import except the New just before progressBar that you will need to add

Then we will need to import Namespace using the “Import” Panel (close to the variable panel on the bottom and look for System.Windows.Forms and click it when it appears on the drop-down.

image

The last step, in order to have it functional, you need to create a variable under the variable panel, with a type coming from WindowsForm namespace (on my example frmOne as System.Windows.Forms.Form)

By doing this, it will say UiPath that it needs to import System.Windows.Forms namespace when it will compile. The same manipulation is done when you want to import external (custom) namespace within UiPath

image

Now you should be able to run it correctly.

In case, Find here the copy of your wf amended

Main.xaml (9.0 KB)

Cheers.

7 Likes

@Florent_Salendres
Florent, thanks a million. It worked perfectly. My main conceptual problem was that I didn’t realize the need to add the variable of type System.Windows.Forms.Form. And now that’s going to help me out tremendously in the future.
Very kind of you indeed!

(By the way, if you have any knowledge of incorporating AutoHotkey.Interop into UiPath I’d really love to hear about it. I was able to compile the package and add it as a Nuget package locally, and I can run scripts. But so far I haven’t been able to get variables or arguments in or out of the AHK scripts except by writing them as a file and then opening them in UiPath, which kind of defeats the purpose. )

Once again, thanks so much for this extremely useful and detailed walkthrough.
Regards,
burque505

Unfortunately, I do not have experience with AHK but the question is, by using AHK engine as it is done here in a .Net app, can you achieve getting your arguments In/Out between engine => .Net => engine?

If yes, I do not see any reason why having a Custom Activity written in .Net would not return or accept your arguments.

Can you share, in MP if you want to, your .cs class inside the custom activity, i could have a look on it later.

Cheers

2 Likes

Thanks, Florent. I’ve been able to get a number of those examples
working in AHK by using the Telerik converter and translating the C# to
VB.Net. I’m working now with Import statements, if I have any luck I’ll
post. I just tried this code below, which works in VB.NET from VS, in an
Invoke Code block and got a late binding error. I’ll see if I can use
reflection, maybe I’ll have better luck

     Dim ahk As Object
     ahk = CreateObject("AutoHotkey.Script")
     ahk.ahktextdll("SetTitleMatchMode, 2" & vbLf & _
                   "Run, notepad.exe" & vbLf & _
                   "Sleep, 1000" & vbLf & _
                   "WinGet, rid , ,Notepad, , , " & vbLf & _
                   "WinActivate, ahk_id %rid%" & vbLf & _
                   "IfWinExist, ahk_id %rid%" & vbLf & _
                   "{" & vbCrLf & _
                   "    WinMove, ahk_id %rid%,, 0, 0, , " & vbLf & _
                   "}" & vbLf & _
                   "Send, Time" & vbCrLf & _
                   "msgbox, Done")
     MsgBox("Works!")

Once again, it’s really kind of you to help.

Regards,

burque505

1 Like

Hello Burque,

I think it might be easier to achieve what you want creating your custom activity as shown on the doc bellow.

later you can import the created custom activity to the studio as follow.

There error you are encoutering come from the fact that you need to be explicit with the objects you are dealing with about their types.

You cannot declare AHK just as object on the Invoke code, you would need to specify its type as follow.

Dim AHK as new AutoHotKeyEngine (i’m not sure this is the correct type). If the type comes from an external dll it would need to be imported to UiPath first.

Cheers

2 Likes

@Florent_Salendres,
Thanks once again, I will try that. I have been trying to get an instance of AutoHotkeyEngine, not via a Custom Activity, but rather using something based on TDagsvik’s workflow below. I’m including my feeble attempt so far as well, which is incomplete and doesn’t work.
regards,
burque505
Turn_ScrollLock_Off.xaml (12.7 KB)
Ahk attempt.xaml (10.1 KB)

I will be sure to post the results of my efforts with a custom activity. I really appreciate you taking the time to help.

I am new to UIPath and tried your code. The main.xaml I download works but when I try the steps in my project it fails. the form does not show and breakpoint does not work either.
please help.