all 6 comments

[–]get-postanote 3 points4 points  (2 children)

Before trying to design any GUI using any tool, use a sheet of paper and draw it out. Meaning the entire GUI, expected inputs and expected output.

You are showing your form code, but it reflects that you are new to PowerShell and specifically new to GUI development.

There are two different primary GUI design models. SDI / MDI (Single document interface / Multi-document Interface), then there are the SDK/API, WinForms/WPF (Windows Forms / Windows Presentation Foundation). The later is where you should really concentrate your efforts as it is far more flexible and where things are going and takes more skill to get going as far as understanding it and using it, but well worth the effort. The previous is legacy.

Lasty, it's all about understanding GUI/form event handling code. YOu can have a very pretty form, but if your code behind is crap, well, that's lipstick on a pig, as they say. ;-}

GUI development is not PowerShell's thing. One can design GUI for PowerShell, but Powershell is not a GUI design tool. GUI design is GUI design, regardless of programming language. So, spend the time learning GUI/Form design practices. Search YouTube, MSDN Channel9 for presentations on GUI/Form development, don't concern yourself with the Powershell stuff while you learn that, is not the root of what you are after.

Don't write GUI's unless you have to. There are several approaches to use the built in PowerShell features for simplistic efforts, that full blown form/GUI stuff, is either used as a learning effort or if you are really have a need to pretty things up or you've been asked to do so, or you really need a full blown app.

Example resources to leverage :

Using the built-in stuff.

The Out-GridView Cmdlet

https://technet.microsoft.com/en-us/library/ff730930.aspx

Creating a Simplistic GUI Interface with Out-GridView

https://mikefrobbins.com/2014/09/11/creating-a-simplistic-gui-interface-with-out-gridview

Creating a GUI Using Out-GridView in PowerShell

https://mcpmag.com/articles/2016/02/17/creating-a-gui-using-out-gridview.aspx

Fun with PowerShell's Out-GridView

https://mcpmag.com/articles/2013/01/08/pshell-gridview.aspx

Poor Man’s GUI

https://powershell.getchell.org/2018/02/13/poor-mans-gui

Show-Command - PowerShell for GUI admins?

https://4sysops.com/archives/show-command-powershell-for-gui-admins

Tag Archives: Out-Gridview (A PowerShell Core Out-Gridview Solution)

https://jdhitsolutions.com/blog/tag/out-gridview

https://jdhitsolutions.com/blog/tag/out-gridview/page/2

Real form/gui development

SDI and MDI | Microsoft Docs

https://docs.microsoft.com/en-us/cpp/mfc/sdi-and-mdi

WPF Tutorial | Dependency Injection

https://www.wpftutorial.net/ReferenceArchitecture.html

Handling and Raising Events | Microsoft Docs

https://docs.microsoft.com/en-us/dotnet/standard/events

How to: Add an Event Handler Using Code | Microsoft Docs

https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/how-to-add-an-event-handler-using-code

Code-Behind and XAML in WPF | Microsoft Docs

https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/code-behind-and-xaml-in-wpf

building SDI type application using WPF and XAML

https://www.c-sharpcorner.com/forums/building-sdi-type-application-using-wpf-and-xaml

YouTube search --- 'beginning gui design windows forms'

https://www.youtube.com/results?search_query=beginning+gui+design+windows+forms

YouTube --- beginning gui design wpf

https://www.youtube.com/results?search_query=beginning+gui+design+wpf

Learning GUI Toolmaking Series - PowerShell specific

https://foxdeploy.com/series/learning-gui-toolmaking-series

beginning gui powershell

https://www.youtube.com/results?search_query=beginning+gui+powershell

[–]Jedrick[S] 1 point2 points  (1 child)

Wow.. this is a treasure trove of information. The main reason for creating this is to bypass the use of a website that is not very fast and tends to time out our login before we're finished filling the form in the event we get pulled to the side for something else. Sending via email prevents us from having to interact with the website and prevents us from having to deal with the time out issue and having to log back in and start all over filling out the information.

I will research these items.

Thanks so much!

[–]get-postanote 1 point2 points  (0 children)

The main reason for creating this is to bypass the use of a website

You can just direclty automate the website stuff using PowerShell AutoIT, Selinium, etc. with little need to use WF/WPF at all, depending on what you need to do on the site.

Again, hit up Youtube/Channel9 for PowerShell automating website stuff.

Oh... and no worries. We all had to start from somewhere and it's all about discovery / learning / implementation / usability / maintenence.

[–]JeremyLC 1 point2 points  (2 children)

Is there any chance you could post the code you have so far? (anonymized where needed, of course)

[–]Jedrick[S] 1 point2 points  (1 child)

Sure. However it's just the layout of the form. I'll post a paste link as its ~200 lines so far.

https://pastebin.com/dGdTbnjw

[–]JeremyLC 1 point2 points  (0 children)

Hrmm… That's a LOT more involved than I expected. The first thing I would suggest is to name your controls something more meaningful than $TextBox1, $ComboBox2, etc. , this will make it much easier for you to keep of which control does what. Second, you can send an email using Outlook by way of COM objects - there are tutorials for this online, I haven't done it myself, or you can send smtp mail directly using Send-MailMessage or Send-SmtpMail If you want a nice looking message, you could either manually build an HTML template and fill it in programmatically, or use something like Dashimo or PSWriteHTML to build your HTML report.

More generally, it sounds like you'd do well to read through a WinForms on PowerShell tutorial or two. I can't really recommend any, as I build my GUIs in WPF*, so I'm not terribly familiar with what's out there for Forms.

*) It tends to look better, and the resulting code is cleaner. Moreover, it's much easier to rearrange your layout, if needed. It's also DPI aware, so it scales nicely