1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876



# POSH GUI Studio

# Design PowerShell GUIs, Export and Import. Supports Custom Code sections to make updating

# previously created GUIs easier (those created with this tool).

# Created by Archi

# Created : 2018-07-16

# Modified: 2018-07-26

# Version 1.0

# Code base: https://gallery.technet.microsoft.com/scriptcenter/Powershell-Form-Builder-3bcaf2c7

# Many Thanks to Z.Alex for providing the foundation upon which to build.

# ===============================================================================================

Add - Type - AssemblyName System.Windows.Forms

Add - Type - AssemblyName System.Drawing

$POSHGUI_MyForm = New-Object System.Windows.Forms.Form

$POSHGUI_MyForm .Text = "PowerShell GUI Studio"

Try { $POSHGUI_MyForm .Icon = "C:\MyIcon\MyIcon.ico" } Catch { }

$POSHGUI_MyForm .AutoSize = "True"

$POSHGUI_MyForm .StartPosition = "CenterScreen"

$POSHGUI_MyForm .Size = New-Object System.Drawing.Size ( 800 , 800 )

$POSHGUI_GB_Controls = New-Object System.Windows.Forms.GroupBox

$POSHGUI_GB_Controls .Top = "20"

$POSHGUI_GB_Controls .Left = "10"

$POSHGUI_GB_Controls .Anchor = "Left,Top"

$POSHGUI_GB_Controls .Parent = ""

$POSHGUI_MyForm .Controls.Add ( $POSHGUI_GB_Controls )

$POSHGUI_GB_Controls .Text = "Controls"

$POSHGUI_GB_Controls .Size = New-Object System.Drawing.Size ( 390 , 445 )

$POSHGUI_CB_Controls = New-Object System.Windows.Forms.ComboBox

$POSHGUI_CB_Controls .Top = "20"

$POSHGUI_CB_Controls .Left = "10"

$POSHGUI_CB_Controls .Anchor = "Left,Top"

$POSHGUI_CB_Controls .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_CB_Controls )

$POSHGUI_CB_Controls .Text = "Select"

$POSHGUI_CB_Controls .Size = New-Object System.Drawing.Size ( 120 , 23 )

$POSHGUI_Btn_ControlsAdd = New-Object System.Windows.Forms.Button

$POSHGUI_Btn_ControlsAdd .Top = "19"

$POSHGUI_Btn_ControlsAdd .Left = "145"

$POSHGUI_Btn_ControlsAdd .Anchor = "Left,Top"

$POSHGUI_Btn_ControlsAdd .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Btn_ControlsAdd )

$POSHGUI_Btn_ControlsAdd .Text = "Add"

$POSHGUI_Btn_ControlsAdd .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_Btn_ControlDelete = New-Object System.Windows.Forms.Button

$POSHGUI_Btn_ControlDelete .Top = "393"

$POSHGUI_Btn_ControlDelete .Left = "43"

$POSHGUI_Btn_ControlDelete .Anchor = "Left,Top"

$POSHGUI_Btn_ControlDelete .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Btn_ControlDelete )

$POSHGUI_Btn_ControlDelete .Text = "Delete Selected"

$POSHGUI_Btn_ControlDelete .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_DGV_Controls = New-Object System.Windows.Forms.DataGridView

$POSHGUI_DGV_Controls .Top = "70"

$POSHGUI_DGV_Controls .Left = "5"

$POSHGUI_DGV_Controls .Anchor = "Left,Top"

$POSHGUI_DGV_Controls .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_DGV_Controls )

$POSHGUI_DGV_Controls .RowHeadersVisible = $False

$POSHGUI_DGV_Controls .Text = "DataGridView1"

$POSHGUI_DGV_Controls .Size = New-Object System.Drawing.Size ( 185 , 320 )

$POSHGUI_DGV_Properties = New-Object System.Windows.Forms.DataGridView

$POSHGUI_DGV_Properties .Top = "70"

$POSHGUI_DGV_Properties .Left = "200"

$POSHGUI_DGV_Properties .Anchor = "Left,Top"

$POSHGUI_DGV_Properties .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_DGV_Properties )

$POSHGUI_DGV_Properties .ColumnHeadersVisible = $true

$POSHGUI_DGV_Properties .RowHeadersVisible = $False

$POSHGUI_DGV_Properties .Text = "DataGridView2"

$POSHGUI_DGV_Properties .Size = New-Object System.Drawing.Size ( 185 , 320 )

$POSHGUI_Label1 = New-Object System.Windows.Forms.Label

$POSHGUI_Label1 .Top = "50"

$POSHGUI_Label1 .Left = "10"

$POSHGUI_Label1 .Anchor = "Left,Top"

$POSHGUI_Label1 .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Label1 )

$POSHGUI_Label1 .Text = "Controls"

$POSHGUI_Label1 .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_Label2 = New-Object System.Windows.Forms.Label

$POSHGUI_Label2 .Top = "50"

$POSHGUI_Label2 .Left = "200"

$POSHGUI_Label2 .Anchor = "Left,Top"

$POSHGUI_Label2 .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Label2 )

$POSHGUI_Label2 .Text = "Properties"

$POSHGUI_Label2 .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_GB_FormProperties = New-Object System.Windows.Forms.GroupBox

$POSHGUI_GB_FormProperties .Top = "470"

$POSHGUI_GB_FormProperties .Left = "10"

$POSHGUI_GB_FormProperties .Anchor = "Left,Top"

$POSHGUI_GB_FormProperties .Parent = ""

$POSHGUI_MyForm .Controls.Add ( $POSHGUI_GB_FormProperties )

$POSHGUI_GB_FormProperties .Text = "Form Properties"

$POSHGUI_GB_FormProperties .Size = New-Object System.Drawing.Size ( 370 , 105 )

$POSHGUI_Label3 = New-Object System.Windows.Forms.Label

$POSHGUI_Label3 .Top = "22"

$POSHGUI_Label3 .Left = "10"

$POSHGUI_Label3 .Anchor = "Left,Top"

$POSHGUI_Label3 .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Label3 )

$POSHGUI_Label3 .Text = "Form Name"

$POSHGUI_Label3 .Size = New-Object System.Drawing.Size ( 75 , 23 )

$POSHGUI_Txt_FormName = New-Object System.Windows.Forms.TextBox

$POSHGUI_Txt_FormName .Top = "18"

$POSHGUI_Txt_FormName .Left = "95"

$POSHGUI_Txt_FormName .Anchor = "Left,Top"

$POSHGUI_Txt_FormName .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Txt_FormName )

$POSHGUI_Txt_FormName .Text = "New Form"

$POSHGUI_Txt_FormName .Size = New-Object System.Drawing.Size ( 125 , 23 )

$POSHGUI_Txt_FormSizeX = New-Object System.Windows.Forms.TextBox

$POSHGUI_Txt_FormSizeX .Top = "45"

$POSHGUI_Txt_FormSizeX .Left = "95"

$POSHGUI_Txt_FormSizeX .Anchor = "Left,Top"

$POSHGUI_Txt_FormSizeX .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Txt_FormSizeX )

$POSHGUI_Txt_FormSizeX .Text = "300"

$POSHGUI_Txt_FormSizeX .Size = New-Object System.Drawing.Size ( 30 , 23 )

$POSHGUI_Txt_FormSizeY = New-Object System.Windows.Forms.TextBox

$POSHGUI_Txt_FormSizeY .Top = "45"

$POSHGUI_Txt_FormSizeY .Left = "157"

$POSHGUI_Txt_FormSizeY .Anchor = "Left,Top"

$POSHGUI_Txt_FormSizeY .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Txt_FormSizeY )

$POSHGUI_Txt_FormSizeY .Text = "300"

$POSHGUI_Txt_FormSizeY .Size = New-Object System.Drawing.Size ( 30 , 23 )

$POSHGUI_Label4 = New-Object System.Windows.Forms.Label

$POSHGUI_Label4 .Top = "50"

$POSHGUI_Label4 .Left = "10"

$POSHGUI_Label4 .Anchor = "Left,Top"

$POSHGUI_Label4 .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Label4 )

$POSHGUI_Label4 .Text = "Form Size"

$POSHGUI_Label4 .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_Label5 = New-Object System.Windows.Forms.Label

$POSHGUI_Label5 .Top = "48"

$POSHGUI_Label5 .Left = "135"

$POSHGUI_Label5 .Anchor = "Left,Top"

$POSHGUI_Label5 .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Label5 )

$POSHGUI_Label5 .Text = "X"

$POSHGUI_Label5 .Size = New-Object System.Drawing.Size ( 20 , 23 )

$POSHGUI_Label6 = New-Object System.Windows.Forms.Label

$POSHGUI_Label6 .Top = "78"

$POSHGUI_Label6 .Left = "10"

$POSHGUI_Label6 .Anchor = "Left,Top"

$POSHGUI_Label6 .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Label6 )

$POSHGUI_Label6 .Text = "Form Icon"

$POSHGUI_Label6 .Size = New-Object System.Drawing.Size ( 81 , 23 )

$POSHGUI_Txt_FormIconPath = New-Object System.Windows.Forms.TextBox

$POSHGUI_Txt_FormIconPath .Top = "75"

$POSHGUI_Txt_FormIconPath .Left = "95"

$POSHGUI_Txt_FormIconPath .Anchor = "Left,Top"

$POSHGUI_Txt_FormIconPath .Parent = "GB_FormProperties"

$POSHGUI_GB_FormProperties .Controls.Add ( $POSHGUI_Txt_FormIconPath )

$POSHGUI_Txt_FormIconPath .Text = "C:\MyIcon\MyIcon.ico"

$POSHGUI_Txt_FormIconPath .Size = New-Object System.Drawing.Size ( 250 , 23 )

$POSHGUI_Btn_AddProp = New-Object System.Windows.Forms.Button

$POSHGUI_Btn_AddProp .Top = "393"

$POSHGUI_Btn_AddProp .Left = "230"

$POSHGUI_Btn_AddProp .Anchor = "Left,Top"

$POSHGUI_Btn_AddProp .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Btn_AddProp )

$POSHGUI_Btn_AddProp .Text = "Add Property"

$POSHGUI_Btn_AddProp .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_Btn_DelProp = New-Object System.Windows.Forms.Button

$POSHGUI_Btn_DelProp .Top = "418"

$POSHGUI_Btn_DelProp .Left = "230"

$POSHGUI_Btn_DelProp .Anchor = "Left,Top"

$POSHGUI_Btn_DelProp .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Btn_DelProp )

$POSHGUI_Btn_DelProp .Text = "Delete Property"

$POSHGUI_Btn_DelProp .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_GB_NewFormWorkSpace = New-Object System.Windows.Forms.GroupBox

$POSHGUI_GB_NewFormWorkSpace .Top = "20"

$POSHGUI_GB_NewFormWorkSpace .Left = "405"

$POSHGUI_GB_NewFormWorkSpace .Anchor = "Left,Top"

$POSHGUI_GB_NewFormWorkSpace .Parent = ""

$POSHGUI_MyForm .Controls.Add ( $POSHGUI_GB_NewFormWorkSpace )

$POSHGUI_GB_NewFormWorkSpace .Text = "New Form"

$POSHGUI_GB_NewFormWorkSpace .Size = New-Object System.Drawing.Size ( 400 , 400 )

$POSHGUI_RTB_CustomCodeView = New-Object System.Windows.Forms.RichTextBox

$POSHGUI_RTB_CustomCodeView .Top = "600"

$POSHGUI_RTB_CustomCodeView .Left = "10"

$POSHGUI_RTB_CustomCodeView .Anchor = "Left,Top"

$POSHGUI_RTB_CustomCodeView .Parent = ""

$POSHGUI_MyForm .Controls.Add ( $POSHGUI_RTB_CustomCodeView )

$POSHGUI_RTB_CustomCodeView .Text = ""

$POSHGUI_RTB_CustomCodeView .Size = New-Object System.Drawing.Size ( 370 , 135 )

$POSHGUI_GB_FileExportImport = New-Object System.Windows.Forms.GroupBox

$POSHGUI_GB_FileExportImport .Top = "739"

$POSHGUI_GB_FileExportImport .Left = "10"

$POSHGUI_GB_FileExportImport .Anchor = "Left,Top"

$POSHGUI_GB_FileExportImport .Parent = ""

$POSHGUI_MyForm .Controls.Add ( $POSHGUI_GB_FileExportImport )

$POSHGUI_GB_FileExportImport .Text = "Script Import"

$POSHGUI_GB_FileExportImport .Size = New-Object System.Drawing.Size ( 370 , 50 )

$POSHGUI_BTN_ExportForm = New-Object System.Windows.Forms.Button

$POSHGUI_BTN_ExportForm .Top = "20"

$POSHGUI_BTN_ExportForm .Left = "45"

$POSHGUI_BTN_ExportForm .Anchor = "Left,Top"

$POSHGUI_BTN_ExportForm .Parent = "GB_FileExportImport"

$POSHGUI_GB_FileExportImport .Controls.Add ( $POSHGUI_BTN_ExportForm )

$POSHGUI_BTN_ExportForm .Text = "Export Form"

$POSHGUI_BTN_ExportForm .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_BTN_ImportForm = New-Object System.Windows.Forms.Button

$POSHGUI_BTN_ImportForm .Top = "20"

$POSHGUI_BTN_ImportForm .Left = "220"

$POSHGUI_BTN_ImportForm .Anchor = "Left,Top"

$POSHGUI_BTN_ImportForm .Parent = "GB_FileExportImport"

$POSHGUI_GB_FileExportImport .Controls.Add ( $POSHGUI_BTN_ImportForm )

$POSHGUI_BTN_ImportForm .Text = "Import Form"

$POSHGUI_BTN_ImportForm .Size = New-Object System.Drawing.Size ( 100 , 23 )

$POSHGUI_Label7 = New-Object System.Windows.Forms.Label

$POSHGUI_Label7 .Top = "583"

$POSHGUI_Label7 .Left = "10"

$POSHGUI_Label7 .Anchor = "Left,Top"

$POSHGUI_Label7 .Parent = ""

$POSHGUI_MyForm .Controls.Add ( $POSHGUI_Label7 )

$POSHGUI_Label7 .Text = "Custom Code"

$POSHGUI_Label7 .Size = New-Object System.Drawing.Size ( 200 , 23 )

$POSHGUI_Label8 = New-Object System.Windows.Forms.Label

$POSHGUI_Label8 .Top = "423"

$POSHGUI_Label8 .Left = "10"

$POSHGUI_Label8 .Anchor = "Left,Top"

$POSHGUI_Label8 .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Label8 )

$POSHGUI_Label8 .Text = "Control Prefix"

$POSHGUI_Label8 .Size = New-Object System.Drawing.Size ( 75 , 20 )

$POSHGUI_Txt_ControlPrefix = New-Object System.Windows.Forms.TextBox

$POSHGUI_Txt_ControlPrefix .Top = "419"

$POSHGUI_Txt_ControlPrefix .Left = "87"

$POSHGUI_Txt_ControlPrefix .Anchor = "Left,Top"

$POSHGUI_Txt_ControlPrefix .Parent = "GB_Controls"

$POSHGUI_GB_Controls .Controls.Add ( $POSHGUI_Txt_ControlPrefix )

$POSHGUI_Txt_ControlPrefix .Text = "POSHGUI_"

$POSHGUI_Txt_ControlPrefix .Size = New-Object System.Drawing.Size ( 100 , 23 )

# Add Custom Code Below - Do NOT Edit This Line!

CLS

$DefaultPath = "$env:USERPROFILE\Documents"

$FormPrefix = "POSHGUI_" # used to identify imported controls - these must be the same, here and in the impoorted PS1 for a working import

# =======================================================================

#

# Change nothing below - unless you really know what you're doing. :D

#

# =======================================================================



function mouseDown {

$Global :mCurFirstX = ( [ System.Windows.Forms.Cursor ] ::Position.X )

$Global :mCurFirstY = ( [ System.Windows.Forms.Cursor ] ::Position.Y )

}



function mouseMove ( $mControlName ) {

$mCurMoveX = ( [ System.Windows.Forms.Cursor ] ::Position.X )

$mCurMoveY = ( [ System.Windows.Forms.Cursor ] ::Position.Y )



if ( $Global :mCurFirstX -ne 0 -and $Global :mCurFirstY -ne 0 ) {



$mDifX = $Global :mCurFirstX - $mCurMoveX

$mDifY = $Global :mCurFirstY - $mCurMoveY



$this .Left = $this .Left - $mDifX

$this .Top = $this .Top - $mDifY



$Global :mCurFirstX = $mCurMoveX

$Global :mCurFirstY = $mCurMoveY

}

}



function mouseUP ( $mControlObj ) {

$mCurUpX = ( [ System.Windows.Forms.Cursor ] ::Position.X )

$mCurUpY = ( [ System.Windows.Forms.Cursor ] ::Position.Y )

$Global :mCurFirstX = 0

$Global :mCurFirstY = 0



Foreach ( $mElement In [ array ] $Global :mFormObj.Elements ) {

if ( $mElement .Name -eq $this .name ) {

foreach ( $mProp in $mElement .Properties ) {

Switch ( $mProp .Name ) {

'Top' { $mProp .Value = $this .Top }

'Left' { $mProp .Value = $this .Left }

}

}

}

}

renewGrids

}

Function renewGrids {



$mList = New-Object System.Collections.ArrayList

[ array ] $mElementsArr = $mFormObj .Elements | select Name , Type

Try { $mList .AddRange ( $mElementsArr ) } Catch { }

$POSHGUI_DGV_Controls .DataSource = $mList

Try { $POSHGUI_DGV_Controls .Columns [ 1 ] .ReadOnly = $true } Catch { }



$mList2 = New-Object System.Collections.ArrayList

Try { [ array ] $mPropertyArr = $mFormObj .Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties } Catch { }

Try { $mList2 .AddRange ( $mPropertyArr ) } Catch { }

$POSHGUI_DGV_Properties .DataSource = $mList2

Try { $POSHGUI_DGV_Properties .Columns [ 0 ] .ReadOnly = $true } Catch { }



}

Function DeletePropertyRow {



$propRowToDelete = $POSHGUI_DGV_Properties .CurrentRow.Index

$PropertyInfo = $POSHGUI_DGV_Properties .Rows.Item ( $propRowToDelete )

$PropertyInfoName = $ ( $PropertyInfo .Cells.Item ( 'Name' ) .Value )

[ array ] $Global :mFormObj.Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties = [ array ] $Global :mFormObj.Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties | Where-Object { .Name -notlike $PropertyInfoName }

$mList2 = New-Object System.Collections.ArrayList

Try { [ array ] $mPropertyArr = $mFormObj .Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties } Catch { }

Try { $mList2 .AddRange ( [ array ] $mPropertyArr ) } Catch { }

$POSHGUI_DGV_Properties .DataSource = $mList2

Try { $POSHGUI_DGV_Properties .Columns [ 0 ] .ReadOnly = $true } Catch { }



}

Function AddPropertyRow {



$form = New-Object System.Windows.Forms.Form

$form .Text = 'Input Property Name'

$form .Size = New-Object System.Drawing.Size ( 350 , 200 )

$form .StartPosition = 'CenterScreen'



$OKButton = New-Object System.Windows.Forms.Button

$OKButton .Location = New-Object System.Drawing.Point ( 85 , 130 )

$OKButton .Size = New-Object System.Drawing.Size ( 75 , 23 )

$OKButton .Text = 'Add'

$OKButton .DialogResult = [ System.Windows.Forms.DialogResult ] ::OK

$form .AcceptButton = $OKButton

$form .Controls.Add ( $OKButton )



$CancelButton = New-Object System.Windows.Forms.Button

$CancelButton .Location = New-Object System.Drawing.Point ( 180 , 130 )

$CancelButton .Size = New-Object System.Drawing.Size ( 75 , 23 )

$CancelButton .Text = 'Cancel'

$CancelButton .DialogResult = [ System.Windows.Forms.DialogResult ] ::Cancel

$form .CancelButton = $CancelButton

$form .Controls.Add ( $CancelButton )



$label = New-Object System.Windows.Forms.Label

$label .Location = New-Object System.Drawing.Point ( 40 , 10 )

$label .Size = New-Object System.Drawing.Size ( 280 , 30 )

$label .Text = 'Enter the name of the Property to add. You will add the value later.'

$form .Controls.Add ( $label )



$textBox = New-Object System.Windows.Forms.TextBox

$textBox .Location = New-Object System.Drawing.Point ( 40 , 70 )

$textBox .Size = New-Object System.Drawing.Size ( 260 , 20 )

$form .Controls.Add ( $textBox )



$form .Topmost = $true



$form .Add_Shown ( { $textBox . Select ( ) } )

$result = $form .ShowDialog ( )



if ( $result -eq [ System.Windows.Forms.DialogResult ] ::OK ) {

$x = $textBox .Text

$mFormObj .Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties += AddProperty - mName $x - mValue 'Edit Me'

Try { $POSHGUI_DGV_Properties .Columns [ 0 ] .ReadOnly = $true } Catch { }

renewGrids

repaintForm

}



}

Function DeleteElement {

[ array ] $Global :mFormObj.Elements = [ array ] $mFormObj .Elements | ? { .Name -notlike [ array ] $mFormObj .Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Name }

repaintForm

renewGrids

}



Function ClearForm {

[ array ] $Global :mFormObj.Elements = $null

repaintForm

renewGrids

$POSHGUI_RTB_CustomCodeView . Clear ( )

}



Function AddProperty ( $mName , $mValue ) {

$mPropertyObj = New-Object PSCustomObject

$mPropertyObj | Add-Member -Name 'Name' -MemberType NoteProperty -Value $mName

$mPropertyObj | Add-Member -Name 'Value' -MemberType NoteProperty -Value $mValue

return $mPropertyObj

}



Function ElementsChanged {

$mList2 = New-Object System.Collections.ArrayList

[ array ] $mPropertyArr = [ array ] $Global :mFormObj.Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties

$mList2 .AddRange ( $mPropertyArr )

$POSHGUI_DGV_Properties .DataSource = $mList2

}



function ElementsEndEdit {

$Global :mFormObj.Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Name = $POSHGUI_DGV_Controls .CurrentCell.FormattedValue

repaintForm

}

Function AddElement {



# Ensure we're using a listed control, not a manually entered bogus control



$mPropertiesArr [email protected] ( )

$mSameType = ( $mFormObj .Elements | ? { $_ . Type -like $POSHGUI_CB_Controls .SelectedItem } )

If ( $mSameType .count -ne $NUll -and $mSameType -ne $null ) {

$mControlName = '' + $POSHGUI_CB_Controls .SelectedItem + ( $mSameType .count + 1 )

} ElseIf ( $mSameType .Count -eq $null -and $mSameType -ne $null ) {

$mControlName = '' + $POSHGUI_CB_Controls .SelectedItem + '2'

} Else {

$mControlName = '' + $POSHGUI_CB_Controls .SelectedItem + '1'

}



# Generic control properties

$mPropertiesArr += AddProperty 'SizeX' 100

$mPropertiesArr += AddProperty 'SizeY' 23

$mPropertiesArr += AddProperty 'Top' 5

$mPropertiesArr += AddProperty 'Left' 5

$mPropertiesArr += AddProperty 'Anchor' 'Left,Top'



# Add control specific properties

# Each one is split out so we can add particular properties to one control but not all.

switch ( $POSHGUI_CB_Controls .SelectedItem ) {



"TextBox" { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName ;

<# # We could pull in all properties for a control, but ehhh it's messy. Tackle another day...

ForEach ($cProp in [System.Windows.Forms.TextBox]::new() | Get-Member | Where {$_.MemberType -eq 'Property' -and $_.Name -ne 'Size' -and $_.Name -ne 'Anchor' -and $_.Name -ne 'Top' -and $_.Name -ne 'Left' -and $_.Name -ne 'Text' -and $_.Name -ne 'Parent' -and $_.Definition -like "*set*"} ){

#$cProp.ToString()

$cValue = ""

Try{$cValue = New-Object $($cProp.ToString())}Catch{}

$def = $cProp.Definition.Split(' ')

#write-host "Property $($cProp.Name ) Value: $($cValue) "

$mPropertiesArr+= AddProperty $cProp.Name $cValue

}

#>

}

"Button" { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

"Label" { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'PictureBox' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'CheckBox' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

"ComboBox" { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'ListView' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

"ListBox" { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'RadioButton' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'Panel' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'GroupBox' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'MaskedTextBox' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName ;

$mPropertiesArr += AddProperty 'Mask' $null



}

'ProgressBar' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

"DataGridView" { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'DateTimePicker' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'RichTextBox' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'TreeView' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'TabControl' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'TabPage' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

'WebBrowser' { $mPropertiesArr += AddProperty 'Parent' $null ;

$mPropertiesArr += AddProperty 'Text' $mControlName



}

"default" { write-host 'Red Alert! Red Alert!' ; break }



}



$mElementsObj = New-Object PSCustomObject

$mElementsObj | Add-Member -Name 'Name' -MemberType NoteProperty -Value $mControlName

$mElementsObj | Add-Member -Name 'Type' -MemberType NoteProperty -Value ( $POSHGUI_CB_Controls .SelectedItem )

$mElementsObj | Add-Member -Name 'Properties' -MemberType NoteProperty -Value $mPropertiesArr

[ array ] $Global :mFormObj.Elements += $mElementsObj

renewGrids

repaintForm



}

function AddControl ( $mControl ) {



$mReturnControl = $null



switch ( $mControl . Type ) {



"TextBox" { $mReturnControl = New-Object System.Windows.Forms.TextBox }

"Button" { $mReturnControl = New-Object System.Windows.Forms.Button }

"Label" { $mReturnControl = New-Object System.Windows.Forms.Label }

'PictureBox' { $mReturnControl = New-Object System.Windows.Forms.PictureBox }

'CheckBox' { $mReturnControl = New-Object System.Windows.Forms.CheckBox }

"ComboBox" { $mReturnControl = New-Object System.Windows.Forms.ComboBox }

'ListView' { $mReturnControl = New-Object System.Windows.Forms.ListView }

"ListBox" { $mReturnControl = New-Object System.Windows.Forms.ListBox }

'RadioButton' { $mReturnControl = New-Object System.Windows.Forms.RadioButton }

'Panel' { $mReturnControl = New-Object System.Windows.Forms.Panel }

'GroupBox' { $mReturnControl = New-Object System.Windows.Forms.GroupBox }

'MaskedTextBox' { $mReturnControl = New-Object System.Windows.Forms.MaskedTextBox }

'ProgressBar' { $mReturnControl = New-Object System.Windows.Forms.ProgressBar }

"DataGridView" { $mReturnControl = New-Object System.Windows.Forms.DataGridView }

'DateTimePicker' { $mReturnControl = New-Object System.Windows.Forms.DateTimePicker }

'RichTextBox' { $mReturnControl = New-Object System.Windows.Forms.RichTextBox }

'TreeView' { $mReturnControl = New-Object System.Windows.Forms.TreeView }

'WebBrowser' { $mReturnControl = New-Object System.Windows.Forms.WebBrowser }

'TabControl' { $mReturnControl = New-Object System.Windows.Forms.TabControl }

'TabPage' { $mReturnControl = New-Object System.Windows.Forms.TabPage }

"default" { $mReturnControl = $null ; break }



}



If ( $mReturnControl -eq $null ) {

Write-Host "Invalid Control Type"

break

}

$mReturnControl .Name = $mControl .Name



$mSizeX = $null

$mSizeY = $null



foreach ( $mProperty in $mControl .Properties ) {



switch ( $mProperty .Name ) {

'Text' { Try { $mReturnControl .Text = $mProperty .Value } Catch { } }

'SizeX' { $mSizeX = $mProperty .Value }

'SizeY' { $mSizeY = $mProperty .Value }

'Top' { $mReturnControl .Top = $mProperty .Value }

'Left' { $mReturnControl .Left = $mProperty .Value }

'Anchor' { $mReturnControl .Anchor = $mProperty .Value }

'Parent' { $mReturnControl .Parent = $mProperty .Value }

Default { Try { $mReturnControl .$ ( $mProperty .Name ) = $mProperty .Value } Catch { Write-Warning "$($PSItem.Exception.Message)" } }

}



}



$mReturnControl .Size = New-Object System.Drawing.Size ( $mSizeX , $mSizeY )

$mReturnControl .Add_MouseDown ( { MouseDown } )

$mReturnControl .Add_MouseMove ( { MouseMove ( $mControl .Name ) } )

$mReturnControl .Add_MouseUP ( { MouseUP } )

Return $mReturnControl



}

function PropertiesEndEdit {

foreach ( $mProperty in [ array ] $Global :mFormObj.Elements [ $POSHGUI_DGV_Controls .CurrentRow.Index ] .Properties ) {



if ( $mProperty .Name -eq $POSHGUI_DGV_Properties .currentrow.Cells [ 0 ] .FormattedValue ) {

$mProperty .Value = $POSHGUI_DGV_Properties .currentrow.Cells [ 1 ] .FormattedValue

}

}

repaintForm

}

Function FindParent {

# This was the key to the nesting! Recusive search for the defined parent.

param (

$ParentName ,

$BaseControls

)



ForEach ( $childControl in $BaseControls ) {

If ( $childControl .Name -eq $ParentName ) {

$FoundParent = $childControl

Return $FoundParent

} Else {

FindParent - ParentName $ParentName - BaseControls $childControl .controls

}

}

}



Function repaintForm {



$POSHGUI_GB_NewFormWorkSpace .Size = New-Object System.Drawing.Size ( ( $mFormObj .SizeX ) , ( $mFormObj .SizeY ) )

$POSHGUI_GB_NewFormWorkSpace .controls. clear ( )



ForEach ( $mElement in [ array ] $Global :mFormObj.Elements ) {

$Parent = ( $mElement .Properties | Where-Object { .Name -eq 'Parent' } ) .value

If ( $Parent -ne $null -and $Parent .length -gt 0 -and $Parent -eq $mElement .Name ) {

write-host "Parent cannot be self!"

} ElseIf ( $Parent -ne $null -and $Parent .length -gt 0 -and $Parent -ne $mElement .Name ) {

$Parent = ( $mElement .Properties | Where-Object { .Name -eq 'Parent' } ) .value

$FoundParent = FindParent - ParentName $Parent - BaseControls $ ( $POSHGUI_GB_NewFormWorkSpace .Controls )

If ( $FoundParent ) {

$FoundParent .controls.add ( ( AddControl $mElement ) )

} Else {

Write-Host "ERROR: Unable to find specified Parent '$($Parent)' for $($mElement.Name)"

}

} Else {

$POSHGUI_GB_NewFormWorkSpace .controls.add ( ( AddControl $mElement ) )

}

}

}



Function EditFormSize ( $x , $y ) {

$Global :mFormObj.SizeX = $X

$Global :mFormObj.SizeY = $Y

repaintForm

}



Function ExportForm {



$mExportString = 'Add-Type -AssemblyName System.Windows.Forms' + " `r `n "

$mExportString += 'Add-Type -AssemblyName System.Drawing' + " `r `n "

$mExportString += '$' + $FormPrefix + 'MyForm = New-Object System.Windows.Forms.Form' + " `r `n "

$mExportString += '$' + $FormPrefix + 'MyForm.Text="' + $Global :mFormName + '"' + " `r `n "

$mExportString += 'Try{$' + $FormPrefix + 'MyForm.Icon="' + $POSHGUI_Txt_FormIconPath .Text + '"}Catch{}' + " `r `n "

$mExportString += '$' + $FormPrefix + 'MyForm.AutoSize="True"' + " `r `n "

$mExportString += '$' + $FormPrefix + 'MyForm.StartPosition = "CenterScreen"' + " `r `n "

$mExportString += '$' + $FormPrefix + 'MyForm.Size = New-Object System.Drawing.Size(' + $mFormObj .SizeX + ',' + $mFormObj .SizeY + ')' + " `r `n "



ForEach ( $mElement in $mFormObj .Elements ) {



$mExportString += '$' + $FormPrefix + $mElement .Name + ' = New-Object System.Windows.Forms.' + $mElement . Type + '' + " `r `n "

$mPrSizeX = ''

$mPrSizeY = ''



ForEach ( $mProperty in $mElement .Properties ) {



#Write-Host "Property: $($mProperty.Name) Value: $($mProperty.Value)"



If ( $mProperty .Name -eq 'SizeX' ) {

$mPrSizeX = $mProperty .Value

} elseIf ( $mProperty .Name -eq 'SizeY' ) {

$mPrSizeY = $mProperty .Value

} elseIf ( $mElement . Type -eq 'DateTimePicker' -and $mProperty .Name -eq 'Text' ) {



} elseIf ( ( $mProperty .Value -eq " `$ true" ) -or ( $mProperty .Value -eq " `$ false" ) ) {

$mExportString += '$' + $FormPrefix + $mElement .Name + '.' + $mProperty .Name + '=' + $mProperty .Value + '' + " `r `n "

} else {

$mExportString += '$' + $FormPrefix + $mElement .Name + '.' + $mProperty .Name + '="' + $mProperty .Value + '"' + " `r `n "

}



If ( $mProperty .Name -eq 'Parent' ) {

If ( $mProperty .Value -eq $null -or $mProperty .Value -le 0 ) {

$mExportString += '$' + $FormPrefix + 'MyForm.Controls.Add($' + $FormPrefix + $mElement .Name + ')' + " `r `n "

} Else {

$mExportString += '$' + $FormPrefix + $mProperty .Value + '.Controls.Add($' + $FormPrefix + $mElement .Name + ')' + " `r `n "

}

}



}



$mExportString += '$' + $FormPrefix + $mElement .Name + '.Size = New-Object System.Drawing.Size(' + $mPrSizeX + ',' + $mPrSizeY + ')' + " `r `n "



}



$mExportString += '# Add Custom Code Below - Do NOT Edit This Line!' + " `r `n "



If ( $Global :CustomCode -ne $null ) {

$mExportString += $Global :CustomCode

}



$mExportString += '# Add Custom Code Above - Do NOT Edit This Line!' + " `r `n "

$mExportString += '$null = $' + $FormPrefix + 'MyForm.ShowDialog()' + " `r `n "



$mFileName = ''

$mFileName = Get - FileNameExport $DefaultPath

If ( $mFileName -notlike '' ) {

$mExportString | Out -File $mFileName

}

}



Function Get - FileNameExport ( $initialDirectory ) {

$SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog

$SaveFileDialog .initialDirectory = $initialDirectory

$SaveFileDialog . filter = “Powershell Script ( * .ps1 ) |* .ps1 | All files ( * . * ) |* . * ”

$SaveFileDialog .ShowDialog ( ) | Out-Null

$SaveFileDialog .filename

}



Function Get - FileNameImport ( $initialDirectory ) {

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog

$OpenFileDialog .initialDirectory = $initialDirectory

$OpenFileDialog . filter = “Powershell Script ( * .ps1 ) |* .ps1 | All files ( * . * ) |* . * ”

$OpenFileDialog .ShowDialog ( ) | Out-Null

$OpenFileDialog .filename

}



Function Import - Control {

param (

$controlType ,

$ImportedData ,

$tempControl

)



$mPropertiesArr [email protected] ( )



$regExControlPropString = "(\$tempControl\.\w+)\s*=\s*(\S+\s{0,1}[\w|\.|\(|\)|,| `" ]+)"

$regExControlProps = [ regex ] ::Matches ( $ImportedData , $regExControlPropString )



ForEach ( $controlProp in $regExControlProps ) {

If ( $controlProp .Captures.groups [ 2 ] .value -like "*system.drawing.size*" ) {

$regExSize = 'New\-Object\sSystem\.Drawing\.Size\((\d+),(\d+)\)'

$controlSize = [ regex ] ::Match ( $controlProp .Captures.groups [ 2 ] .value , $regExSize )

$controlSizeX = $controlSize .Captures.Groups [ 1 ] .Value

$controlSizeY = $controlSize .Captures.Groups [ 2 ] .Value



$mPropertiesArr += AddProperty 'SizeX' $controlSizeX

$mPropertiesArr += AddProperty 'SizeY' $controlSizeY



} Else {

$PropSplit = $controlProp .Captures.groups [ 1 ] .value.split ( '.' )

$Prop = $PropSplit [ 1 ]

$PropValue = $controlProp .Captures.groups [ 2 ] .value.replace ( '"' , '' )

$mPropertiesArr += AddProperty $Prop $PropValue

}

}



$mControlName = $tempControl .Replace ( " `$ $FormPrefix" , '' )

$mElementsObj = New-Object PSCustomObject

$mElementsObj | Add-Member -Name 'Name' -MemberType NoteProperty -Value $mControlName

$mElementsObj | Add-Member -Name 'Type' -MemberType NoteProperty -Value $controlType

$mElementsObj | Add-Member -Name 'Properties' -MemberType NoteProperty -Value $mPropertiesArr

If ( [ array ] $Global :mFormObj.Elements += $mElementsObj ) {

#Write-Host "ImportControl:: Successful"

} Else {

#wirte-host "ImportControl:: Failed"

}



renewGrids

repaintForm

}

Function ImportForm {



$mFileName = ''

$mFileName = Get - FileNameImport $DefaultPath

if ( $mFileName -notlike '' ) {



ClearForm

$ImportedData = Get-Content $mFileName

# Pull in custom code to add back on export

$customCodeStart = $ImportedData .IndexOf ( "# Add Custom Code Below - Do NOT Edit This Line!" )

$customCodeEnd = $ImportedData .IndexOf ( "# Add Custom Code Above - Do NOT Edit This Line!" )



for ( $i = ( $customCodeStart + 1 ) ; $i -lt $customCodeEnd ; $i ++ ) {

$Global :CustomCode += $ImportedData [ $i ] + " `r `n "

}

$POSHGUI_RTB_CustomCodeView .Text = $Global :CustomCode

#Write-Host $Global:CustomCode

$ImportedDataWOcustomCode = $null

ForEach ( $line in $ImportedData ) {

If ( ( $ImportedData .IndexOf ( $line ) -le $customCodeStart ) -or ( $ImportedData .IndexOf ( $line ) -ge $customCodeEnd ) ) {

$ImportedDataWOcustomCode += $line + " `r `n "

}

}



#Get and configure Form Size

$regExFormSize = '\$' + $FormPrefix + 'MyForm\.Size\s\=\sNew\-Object\sSystem\.Drawing\.Size\((\d+),(\d+)\)'

$formSize = [ regex ] ::Match ( $ImportedDataWOcustomCode , $regExFormSize )

$formX = $formSize .Captures.Groups [ 1 ] .Value

$formY = $formSize .Captures.Groups [ 2 ] .Value

$POSHGUI_Txt_FormSizeX .Text = $formX

$POSHGUI_Txt_FormSizeY .Text = $formY



EditFormSize $POSHGUI_Txt_FormSizeX .Text $POSHGUI_Txt_FormSizeY .Text



renewGrids

repaintForm



# Form Controls

$regExControls = "(\ `$ $($FormPrefix)[a-zA-Z0-9-_]+)\s\=\sNew\-Object\sSystem\.Windows\.Forms\.(\b(?!Form\b)\w+)"

$formControls = [ regex ] ::Matches ( $ImportedDataWOcustomCode , $regExControls )

ForEach ( $controlMatch in $formControls ) {

$controlType = $controlMatch .Groups [ 2 ] .Value

$tempControl = $controlMatch .Groups [ 1 ] .Value

If ( $controlType -ne 'Form' ) {

Import - Control - controlType $controlType - ImportedData $ImportedDataWOcustomCode - tempControl $tempControl

}

}



# Form Name

$regExFormName = "\ `$ $($FormPrefix)MyForm\.Text\s*\=\s* `" (.+) `" "

$formName = [ regex ] ::Match ( $ImportedDataWOcustomCode , $regExFormName )

$getFormName = $formName .Captures.Groups [ 1 ] .Value #$Matches[1].ToString()

$Global :mFormName = $getFormName

$mFormNameTextBox .Text = $Global :mFormName

$POSHGUI_GB_NewFormWorkSpace .Text = $Global :mFormName

$POSHGUI_Txt_FormName .Text = $Global :mFormName

}

}



Function UpdateFormName {

$Global :mFormName = $POSHGUI_Txt_FormName .Text

$POSHGUI_GB_NewFormWorkSpace .Text = $Global :mFormName

}



$Global :mFormName = "New Form"

$Global :CustomCode = $null

$Global :mFormObj = New-Object PSCustomObject

$Global :mFormObj | Add-Member -Name 'SizeX' -MemberType NoteProperty -Value 400

$Global :mFormObj | Add-Member -Name 'SizeY' -MemberType NoteProperty -Value 400

$Global :mFormObj | Add-Member -Name 'Elements' -MemberType NoteProperty -Value @ ( )

$Global :mCurFirstX = 0

$Global :mCurFirstY = 0



$null = $POSHGUI_CB_Controls .Items.Add ( "TextBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "Button" )

$null = $POSHGUI_CB_Controls .Items.Add ( "Label" )

$null = $POSHGUI_CB_Controls .Items.Add ( "PictureBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "CheckBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "ComboBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "ListView" )

$null = $POSHGUI_CB_Controls .Items.Add ( "ListBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "RadioButton" )

$null = $POSHGUI_CB_Controls .Items.Add ( "Panel" )

$null = $POSHGUI_CB_Controls .Items.Add ( "GroupBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "MaskedTextBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "ProgressBar" )

$null = $POSHGUI_CB_Controls .Items.Add ( "DataGridView" )

$null = $POSHGUI_CB_Controls .Items.Add ( "DateTimePicker" )

$null = $POSHGUI_CB_Controls .Items.Add ( "RichTextBox" )

$null = $POSHGUI_CB_Controls .Items.Add ( "TreeView" )

$POSHGUI_CB_Controls .Sorted = $true



# Control Events

$POSHGUI_Btn_ControlsAdd .Add_Click ( { AddElement } )

$POSHGUI_Txt_FormSizeX .Add_TextChanged ( { EditFormSize $POSHGUI_Txt_FormSizeX .Text $POSHGUI_Txt_FormSizeY .Text } )

$POSHGUI_Txt_FormSizeY .Add_TextChanged ( { EditFormSize $POSHGUI_Txt_FormSizeX .Text $POSHGUI_Txt_FormSizeY .Text } )

$POSHGUI_Btn_AddProp .Add_Click ( { AddPropertyRow } )

$POSHGUI_Btn_DelProp .Add_Click ( { DeletePropertyRow } )

$POSHGUI_Txt_FormName .Add_TextChanged ( { UpdateFormName } )

$POSHGUI_DGV_Controls .Add_CellContentClick ( { ElementsChanged } )

$POSHGUI_DGV_Controls .Add_CellEndEdit ( { ElementsEndEdit } )

$POSHGUI_DGV_Properties .Add_CellEndEdit ( { PropertiesEndEdit } )

$POSHGUI_Btn_ControlDelete .Add_Click ( { DeleteElement } )

$POSHGUI_BTN_ExportForm .Add_Click ( { ExportForm } )

$POSHGUI_BTN_ImportForm .Add_Click ( { ImportForm } )

$POSHGUI_Txt_ControlPrefix .Add_TextChanged ( { $FormPrefix = $POSHGUI_Txt_ControlPrefix .Text } )

$POSHGUI_RTB_CustomCodeView .Add_TextChanged ( {

$Global :CustomCode = $null

ForEach ( $line in $POSHGUI_RTB_CustomCodeView .Lines ) {

$Global :CustomCode += $line + " `r `n "

}

} )



# Add Custom Code Above - Do NOT Edit This Line!

$null = $POSHGUI_MyForm .ShowDialog ( ) AddAssemblyName System.Windows.FormsAddAssemblyName System.DrawingSystem.Windows.Forms.Form.TextTry.IconCatch.AutoSize.StartPosition.SizeSystem.Drawing.SizeSystem.Windows.Forms.GroupBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.ComboBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Button.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Button.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.DataGridView.Top.Left.Anchor.Parent.Controls.Add.RowHeadersVisible.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.DataGridView.Top.Left.Anchor.Parent.Controls.Add.ColumnHeadersVisible.RowHeadersVisible.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.GroupBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.TextBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.TextBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.TextBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.TextBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Button.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Button.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.GroupBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.RichTextBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.GroupBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Button.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Button.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.Label.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizeSystem.Windows.Forms.TextBox.Top.Left.Anchor.Parent.Controls.Add.Text.SizeSystem.Drawing.SizemouseDown:mCurFirstXSystem.Windows.Forms.Cursor::Position.X:mCurFirstYSystem.Windows.Forms.Cursor::Position.YmouseMoveSystem.Windows.Forms.Cursor::Position.XSystem.Windows.Forms.Cursor::Position.Y:mCurFirstX:mCurFirstY:mCurFirstX:mCurFirstY.Left.Left.Top.Top:mCurFirstX:mCurFirstYmouseUPSystem.Windows.Forms.Cursor::Position.XSystem.Windows.Forms.Cursor::Position.Y:mCurFirstX:mCurFirstY:mFormObj.Elements.Name.name.Properties.Name.Value.Top.Value.LeftrenewGridsrenewGridsSystem.Collections.ArrayList.ElementsNameTry.AddRangeCatch.DataSourceTry.Columns.ReadOnlyCatchSystem.Collections.ArrayListTry.Elements.CurrentRow.Index.PropertiesCatchTry.AddRangeCatch.DataSourceTry.Columns.ReadOnlyCatchDeletePropertyRow.CurrentRow.Index.Rows.Item.Cells.Item.Value:mFormObj.Elements.CurrentRow.Index.Properties:mFormObj.Elements.CurrentRow.Index.Properties $_ .NameSystem.Collections.ArrayListTry.Elements.CurrentRow.Index.PropertiesCatchTry.AddRangeCatch.DataSourceTry.Columns.ReadOnlyCatchAddPropertyRowSystem.Windows.Forms.Form.Text.SizeSystem.Drawing.Size.StartPositionSystem.Windows.Forms.Button.LocationSystem.Drawing.Point.SizeSystem.Drawing.Size.Text.DialogResultSystem.Windows.Forms.DialogResult::OK.AcceptButton.Controls.AddSystem.Windows.Forms.Button.LocationSystem.Drawing.Point.SizeSystem.Drawing.Size.Text.DialogResultSystem.Windows.Forms.DialogResult::Cancel.CancelButton.Controls.AddSystem.Windows.Forms.Label.LocationSystem.Drawing.Point.SizeSystem.Drawing.Size.Text.Controls.AddSystem.Windows.Forms.TextBox.LocationSystem.Drawing.Point.SizeSystem.Drawing.Size.Controls.Add.Topmost.Add_Shown.ShowDialogSystem.Windows.Forms.DialogResult::OK.Text.Elements.CurrentRow.Index.PropertiesAddPropertymNamemValueTry.Columns.ReadOnlyCatchrenewGridsrepaintFormDeleteElement:mFormObj.Elements.Elements $_ .Name.Elements.CurrentRow.Index.NamerepaintFormrenewGridsClearForm:mFormObj.ElementsrepaintFormrenewGridsAddPropertyPSCustomObjectNotePropertyNotePropertyElementsChangedSystem.Collections.ArrayList:mFormObj.Elements.CurrentRow.Index.Properties.AddRange.DataSourceElementsEndEdit:mFormObj.Elements.CurrentRow.Index.Name.CurrentCell.FormattedValuerepaintFormAddElement.Elements.SelectedItem.count.SelectedItem.count.Count.SelectedItem.SelectedItemAddPropertyAddPropertyAddPropertyAddPropertyAddProperty.SelectedItemAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyAddPropertyPSCustomObjectNotePropertyNoteProperty.SelectedItemNoteProperty:mFormObj.ElementsrenewGridsrepaintFormAddControlSystem.Windows.Forms.TextBoxSystem.Windows.Forms.ButtonSystem.Windows.Forms.LabelSystem.Windows.Forms.PictureBoxSystem.Windows.Forms.CheckBoxSystem.Windows.Forms.ComboBoxSystem.Windows.Forms.ListViewSystem.Windows.Forms.ListBoxSystem.Windows.Forms.RadioButtonSystem.Windows.Forms.PanelSystem.Windows.Forms.GroupBoxSystem.Windows.Forms.MaskedTextBoxSystem.Windows.Forms.ProgressBarSystem.Windows.Forms.DataGridViewSystem.Windows.Forms.DateTimePickerSystem.Windows.Forms.RichTextBoxSystem.Windows.Forms.TreeViewSystem.Windows.Forms.WebBrowserSystem.Windows.Forms.TabControlSystem.Windows.Forms.TabPage.Name.Name.Properties.NameTry.Text.ValueCatch.Value.Value.Top.Value.Left.Value.Anchor.Value.Parent.ValueDefaultTry.$.Name.ValueCatch.SizeSystem.Drawing.Size.Add_MouseDownMouseDown.Add_MouseMoveMouseMove.Name.Add_MouseUPMouseUPPropertiesEndEdit:mFormObj.Elements.CurrentRow.Index.Properties.Name.currentrow.Cells.FormattedValue.Value.currentrow.Cells.FormattedValuerepaintFormFindParent.NameFindParentParentNameBaseControls.controlsrepaintForm.SizeSystem.Drawing.Size.SizeX.SizeY.controls.:mFormObj.Elements.Properties $_ .Name.value.length.Name.length.Name.Properties $_ .Name.valueFindParentParentNameBaseControls $.Controls.controls.addAddControl.controls.addAddControlEditFormSize:mFormObj.SizeX:mFormObj.SizeYrepaintFormExportForm:mFormName.Text.SizeX.SizeY.Elements.Name.Properties.Name.Value.Name.Value.Name.Value.Value.Name.Name.Value.Name.Name.Value.Name.Value.Value.Name.Value.Name.Name:CustomCode:CustomCodeGetFileNameExportGetFileNameExportSystem.Windows.Forms.SaveFileDialog.initialDirectory“Powershell Script.ps1.ps1All files.ShowDialog.filenameGetFileNameImportSystem.Windows.Forms.OpenFileDialog.initialDirectory“Powershell Script.ps1.ps1All files.ShowDialog.filenameImportControl::Matches.Captures.groups.value::Match.Captures.groups.value.Captures.Groups.Value.Captures.Groups.ValueAddPropertyAddProperty.Captures.groups.value.split.Captures.groups.value.replaceAddProperty.ReplacePSCustomObjectNotePropertyNotePropertyNoteProperty:mFormObj.ElementsrenewGridsrepaintFormImportFormGetFileNameImportClearForm.IndexOf.IndexOf:CustomCode.Text:CustomCode.IndexOf.IndexOf::Match.Captures.Groups.Value.Captures.Groups.Value.Text.TextEditFormSize.Text.TextrenewGridsrepaintForm::Matches.Groups.Value.Groups.ValueImportControlcontrolTypeImportedDatatempControl::Match.Captures.Groups.Value:mFormName.Text:mFormName.Text:mFormName.Text:mFormNameUpdateFormName:mFormName.Text.Text:mFormName:mFormName:CustomCode:mFormObjPSCustomObject:mFormObjNoteProperty:mFormObjNoteProperty:mFormObjNoteProperty:mCurFirstX:mCurFirstY.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Items.Add.Sorted.Add_ClickAddElement.Add_TextChangedEditFormSize.Text.Text.Add_TextChangedEditFormSize.Text.Text.Add_ClickAddPropertyRow.Add_ClickDeletePropertyRow.Add_TextChangedUpdateFormName.Add_CellContentClickElementsChanged.Add_CellEndEditElementsEndEdit.Add_CellEndEditPropertiesEndEdit.Add_ClickDeleteElement.Add_ClickExportForm.Add_ClickImportForm.Add_TextChanged.Text.Add_TextChanged:CustomCode.Lines:CustomCode.ShowDialog