How to use HTML Editor in PowerShell Studio

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
PGomersall
Posts: 131
Last visit: Thu Feb 15, 2024 12:14 pm

How to use HTML Editor in PowerShell Studio

Post by PGomersall »

Product, version and build: PowerShell Studio 2018 v5.5.152
32 or 64 bit version of product: 64
Operating system: Windows 10 17134
32 or 64 bit OS: 64
I am not sure if this should go in the GUI forum, but since I am trying to do this in PSS I place it here.
I am trying to find a way of creating an editor for email body editing. Searching the web I found a webpage describing a tool based on some opensource C# code. On that page there is afor download link for the compiled dll provided and also information on how to use in a raw GUI PowerShell form. There is also a link to the original code.
Is there any way to incorporate this into a PowerShell Studio form? Any help would be appreciated if you could look at this.
If it is possible, it may be a useful add-in for PSS like you used my suggestion for what became your modern browser dialog.
http://hillside.no/rich-text-editor-in- ... -winforms/
Regards,
Pete
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: How to use HTML Editor in PowerShell Studio

Post by davidc »

PowerShell Studio's designer doesn't support third party controls, but that doesn't mean you can't use them in your GUI scripts. You will just need to dynamically add the custom control within the script.

To add a custom control, do the following:

1. Use the Add-Type cmdlet to add the assembly to your script or add it to the psf file via Ribbon->Home->Editor->Assemblies.
Note: You will need to distribute the assembly with your script.

2. Add a placeholder control, such as a picture box to the designer. This step isn't necessary but makes it easier design the GUI around the custom control.

3. In the form’s Load event, instantiate the custom control and replace the place holder control with the custom control. I highly recommend looking at the Element Host - WPF Control control set to see how this is done. The control set includes a function that will replace the placeholder control during runtime.
David
SAPIEN Technologies, Inc.
User avatar
PGomersall
Posts: 131
Last visit: Thu Feb 15, 2024 12:14 pm

Re: How to use HTML Editor in PowerShell Studio

Post by PGomersall »

David, Thanks for this help; I have it working the way you describe.
One question I have is related to adding the assembly to the form. If I add in this case a dll via the browse button, how is this referenced in the form\psf? Is there anyway to specify this reference to use the folder where the script\executables is run from; i.e. as long as the dll and script or exe are the same folder it will work? Similar to using the built in $PSScriptRoot variable.
Regards,
Pete
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: How to use HTML Editor in PowerShell Studio

Post by davidc »

I recommend using Add-Type over the assembly form for custom assemblies. The assemblies dialog works best with assemblies in the Global Assembly Cache. If it isn't in the cache, it will specify the absolute path of the assembly.
David
SAPIEN Technologies, Inc.
User avatar
PGomersall
Posts: 131
Last visit: Thu Feb 15, 2024 12:14 pm

Re: How to use HTML Editor in PowerShell Studio

Post by PGomersall »

Thank you David, I will change to this method.
Pete
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.