Custom WinForms
WinWrap® Basic is an embedded macro language control available for .NET/COM 32/64 bit Windows applications. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.
Design and create custom .NET forms (WinForms) for use with WinWrap® Basic scripts. Incorporate any WinForm control. Create custom user interfaces for specific clients.
Use Custom WinForms with your WinWrap® Basic Application
- Utilize any WinForm Control
- Show from your COM or .NET application
- Deliver as dynamically compiled dlls
- Implement custom user interfaces for specific clients
- Enable power users to implement custom forms
- Access application specific extensions
- Upgrade your COM application with WinForms
- Create using VB Express or Visual Studio
With WinWrap® Basic Version 10 with Compile Option script developers and end-users now have the ability to create custom WinForms utilizing any available WinForm control. The WinWrap® Basic forms capability is an alternative to the WinWrap® Basic UserDialog functionality. UserDialogs are appropriate for end-users creating simple forms using simple controls.
How a WinWrap® Basic Custom WinForm is Created and Used
There are three scenarios for using custom WinForms in WinWrap® Basic.
- Developer and power user configuration as pictured in the diagram above.
- End-user situation where WinForms can be edited. End-users do not use or need VB Express and Visual Studio VB.NET.
- End-user situation where WinForms are used and not edited.
In the deployed situation, you could allow the end-users to edit the WinForm source or not. Regardless, the WinForms would be used dynamically. VB Express and/or Visual Studio VB.NET are not required at the customer site.
WinWrap® Basic implements the WWB.NET/Compiled language using Microsoft's VB.NET compiler component. A WWB.NET/Compiled project is compiled on demand the first time it is used. Changes to the project cause the code to be recompiled on demand the next time it is used. The compiled code is completely managed by the WinWrap Basic environment. Additionally, the language extensions added by the application are available from a WWB.NET/Compiled project.
Where user input with WinForm controls is desirable, you now have the option of compiling the form as a WWB.NET/Compiled library. Click on one of the links below to evaluate the WinWrap® Basic Compile Option.
WinWrap® Basic WinForms Demo
This demo retrieves "This Date in History" information as directed by the user. The user selects a day via the MonthCalendar control. Then the user selects a source for the "this date in history" information. A web page is then displayed in the WebBrowser control. The RichTextBox control has live links to sites with information about the MonthCalendar, RichTextBox, and WebBrowser controls.
You can download the demo code by clicking this link
WinWrap® Basic WinForms Demo or by clicking on the following WinForm image.
The WinForms Demo Incorporates the Following Powerful Features
- MonthCalendar, RichTextBox, and WebBrowser WinForm controls
- Use of unaltered WinForm source code output by VB Express form designer
- Using a WWB.NET/Compiled project to compile and manage the WinForm code
- Creating the WinForm from WinWrap® Basic script code
- WinForm events fired in WinWrap® Basic script code
- WinForm readonly properties accessed from WinWrap® Basic script code
- WinForm writeonly properties accessed by WinWrap® Basic script code
- Use of the 'Using' statement block to call the WinForm dispose routine
As important as the powerful features demonstrated by the WinForms demo is the auto completion capability available in the WinWrap® Basic editor.
- Auto completion for WinForm object properties from WinWrap® Basic scripts
- Auto completion for WinForm event sinks in WinWrap® Basic scripts
- Auto completion for WinForm controls in the WWB.NET/Compiled code
- Auto completion for any .NET Framework classes
Steps for Creating a WinWrap® Basic WinForms Demo
Using the WinWrap® Director program shipped with WinWrap® Basic COM and .NET Versions follow the instructions below to create a demo program for retrieving date information.
- Download the WinWrap® Basic WinForm demo
- Open WinWrap® Director (shipped with WinWrap® Basic evaluation)
- Open the Day.wwp project with WinWrap® Director
- Run the demo by pressing the Project | Run menu choice
- Choose a day, then choose an information source
- Observe the completely functional user input WinForm and controls
Executable Project Day.wwp
- In the Executable Project Day.wwp (script code) the "EntryPoint Main" command selects the "Sub Main()" subroutine to begin executing.
The "ReferenceProject" command brings the Compiled project symbols into this executable project. The System.Windows.Forms reference enables auto completion for the System.Windows.Forms namespace.
'#Language "WWB.NET"
Project Day
EntryPoint Main
LoadModule "Day-SubMain.wwm"
ReferenceProject "Compiled.wwp"
End Project
- You can use F8 (Step Into) to see Day.wwp "Sub Main" execute line-by-line. The "dayForm.Show" line shows the demo form. The "End Using" line automatically calls dayForm.Dispose.
Imports System.IO
Public Module SubMain
Dim WithEvents dayForm As Compiled.Form1
Sub Main
Using dayFormResource As Compiled.Form1 = New Compiled.Form1
dayForm = dayFormResource
dayForm.RichText = InfoText()
' Show the form to the user
dayForm.Show
' Loop until the form is closed
While dayForm.Visible
Wait .5
End While
End Using ' automatically calls dayFormResource.Dispose
End Sub
' Clicking on the MonthCalendar or a RadioButton
' displays a new page in the WebBrowser
Private Sub dayForm_Changed(ByVal d As Date) Handles dayForm.Changed
Dim mn As String = MonthName(d.Month.ToString)
Dim dy As String = d.Day.ToString
Dim yr As String = d.Year.ToString
Dim mndy As String = mn & "+" & dy
Dim mn_dy As String = mn & "_" & dy
Dim dt As String = mndy & "+" & yr
Dim mon0d As String = LCase(mn.Substring(0, 3)) & Format(CInt(dy),"00")
Dim url As String
Select Case dayForm.Radio()
Case "Bing"
url = "http://www.bing.com/" _
& "search?q=" & dt & "&go=&form=QBLH&qs=n"
Case "Library"
url = "http://memory.loc.gov/" _
& "ammem/today/" & mon0d & ".html"
Case "Google"
url = "http://www.google.com/" _
& "search?hl=en&source=hp&q=" & dt & "&aq=f&oq=&aqi="
Case Else ' Wikipedia
url = "http://en.wikipedia.org/" _
& "wiki/" & mn_dy
End Select
dayForm.Navigate url
End Sub
Private Function InfoText() As String
Using ioFile As New StreamReader(MacroDir & "Day-InfoText.txt")
Return ioFile.ReadToEnd
End Using
End Function
End Module
Compiled Project Compiled.wwp
- A compiled project uses the '#Language "WWB.NET/Compiled" directive, which delivers this WinForm as a dynamically compiled dll available to the WinWrap® Basic script application.
'#Language "WWB.NET/Compiled"
Project Compiled
LoadModule "Compiled-Form1.wwm"
LoadModule "Compiled-Form1 (2).wwm"
End Project
- The 'Compiled-Form1 (2).wwm' code is unaltered source from the VB Express form designer output file "Form1.Designer.vb". The ability to use unaltered source from the VB Express form designer allows the developer or end-user to make iterative improvements and refinements to their custom WinForm.
<global.microsoft.visualbasic.compilerservices.designergenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<system.diagnostics.debuggernonusercode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<system.diagnostics.debuggerstepthrough()> _
Private Sub InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
Me.Panel5 = New System.Windows.Forms.Panel()
Me.Panel4 = New System.Windows.Forms.Panel()
Me.Panel3 = New System.Windows.Forms.Panel()
Me.Panel2 = New System.Windows.Forms.Panel()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.RadioButton4 = New System.Windows.Forms.RadioButton()
Me.RadioButton3 = New System.Windows.Forms.RadioButton()
Me.RadioButton2 = New System.Windows.Forms.RadioButton()
Me.RadioButton1 = New System.Windows.Forms.RadioButton()
Me.MonthCalendar1 = New System.Windows.Forms.MonthCalendar()
Me.WebBrowser1 = New System.Windows.Forms.WebBrowser()
Me.Panel1.SuspendLayout()
Me.Panel2.SuspendLayout()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'Panel1
'
Me.Panel1.Controls.Add(Me.RichTextBox1)
Me.Panel1.Controls.Add(Me.Panel5)
Me.Panel1.Controls.Add(Me.Panel4)
Me.Panel1.Controls.Add(Me.Panel3)
Me.Panel1.Controls.Add(Me.Panel2)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
Me.Panel1.Location = New System.Drawing.Point(0, 0)
Me.Panel1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(757, 171)
Me.Panel1.TabIndex = 0
'
'RichTextBox1
'
Me.RichTextBox1.Dock = System.Windows.Forms.DockStyle.Fill
Me.RichTextBox1.Location = New System.Drawing.Point(431, 14)
Me.RichTextBox1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.ReadOnly = True
Me.RichTextBox1.Size = New System.Drawing.Size(311, 144)
Me.RichTextBox1.TabIndex = 4
Me.RichTextBox1.Text = "This is rich text. www.winwrap.com This is rich text. This is rich text. This is " & _
"rich text. This is rich text. This is rich text. This is rich text. This is rich" & _
" text. "
'
'Panel5
'
Me.Panel5.Dock = System.Windows.Forms.DockStyle.Right
Me.Panel5.Location = New System.Drawing.Point(742, 14)
Me.Panel5.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Panel5.Name = "Panel5"
Me.Panel5.Size = New System.Drawing.Size(15, 144)
Me.Panel5.TabIndex = 3
'
'Panel4
'
Me.Panel4.Dock = System.Windows.Forms.DockStyle.Bottom
Me.Panel4.Location = New System.Drawing.Point(431, 158)
Me.Panel4.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Panel4.Name = "Panel4"
Me.Panel4.Size = New System.Drawing.Size(326, 13)
Me.Panel4.TabIndex = 2
'
'Panel3
'
Me.Panel3.Dock = System.Windows.Forms.DockStyle.Top
Me.Panel3.Location = New System.Drawing.Point(431, 0)
Me.Panel3.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Panel3.Name = "Panel3"
Me.Panel3.Size = New System.Drawing.Size(326, 14)
Me.Panel3.TabIndex = 1
'
'Panel2
'
Me.Panel2.Controls.Add(Me.GroupBox1)
Me.Panel2.Controls.Add(Me.MonthCalendar1)
Me.Panel2.Dock = System.Windows.Forms.DockStyle.Left
Me.Panel2.Location = New System.Drawing.Point(0, 0)
Me.Panel2.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(431, 171)
Me.Panel2.TabIndex = 0
'
'GroupBox1
'
Me.GroupBox1.AutoSize = True
Me.GroupBox1.Controls.Add(Me.RadioButton4)
Me.GroupBox1.Controls.Add(Me.RadioButton3)
Me.GroupBox1.Controls.Add(Me.RadioButton2)
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(237, 11)
Me.GroupBox1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Padding = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.GroupBox1.Size = New System.Drawing.Size(194, 132)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "On This Date in History"
'
'RadioButton4
'
Me.RadioButton4.AutoSize = True
Me.RadioButton4.Location = New System.Drawing.Point(16, 90)
Me.RadioButton4.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.RadioButton4.Name = "RadioButton4"
Me.RadioButton4.Size = New System.Drawing.Size(173, 17)
Me.RadioButton4.TabIndex = 3
Me.RadioButton4.TabStop = True
Me.RadioButton4.Text = "Library of Congress on this date"
Me.RadioButton4.UseVisualStyleBackColor = True
'
'RadioButton3
'
Me.RadioButton3.AutoSize = True
Me.RadioButton3.Location = New System.Drawing.Point(16, 68)
Me.RadioButton3.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(104, 17)
Me.RadioButton3.TabIndex = 2
Me.RadioButton3.TabStop = True
Me.RadioButton3.Text = "Bing on this date"
Me.RadioButton3.UseVisualStyleBackColor = True
'
'RadioButton2
'
Me.RadioButton2.AutoSize = True
Me.RadioButton2.Location = New System.Drawing.Point(16, 46)
Me.RadioButton2.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(117, 17)
Me.RadioButton2.TabIndex = 1
Me.RadioButton2.TabStop = True
Me.RadioButton2.Text = "Google on this date"
Me.RadioButton2.UseVisualStyleBackColor = True
'
'RadioButton1
'
Me.RadioButton1.AutoSize = True
Me.RadioButton1.Checked = True
Me.RadioButton1.Location = New System.Drawing.Point(16, 24)
Me.RadioButton1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(130, 17)
Me.RadioButton1.TabIndex = 0
Me.RadioButton1.TabStop = True
Me.RadioButton1.Text = "Wikipedia on this date"
Me.RadioButton1.UseVisualStyleBackColor = True
'
'MonthCalendar1
'
Me.MonthCalendar1.Location = New System.Drawing.Point(8, 8)
Me.MonthCalendar1.Margin = New System.Windows.Forms.Padding(7, 7, 7, 7)
Me.MonthCalendar1.Name = "MonthCalendar1"
Me.MonthCalendar1.TabIndex = 0
'
'WebBrowser1
'
Me.WebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill
Me.WebBrowser1.Location = New System.Drawing.Point(0, 171)
Me.WebBrowser1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.WebBrowser1.MinimumSize = New System.Drawing.Size(15, 16)
Me.WebBrowser1.Name = "WebBrowser1"
Me.WebBrowser1.Size = New System.Drawing.Size(757, 188)
Me.WebBrowser1.TabIndex = 1
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(757, 359)
Me.Controls.Add(Me.WebBrowser1)
Me.Controls.Add(Me.Panel1)
Me.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.Panel1.ResumeLayout(False)
Me.Panel2.ResumeLayout(False)
Me.Panel2.PerformLayout()
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
End Sub
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Panel2 As System.Windows.Forms.Panel
Friend WithEvents MonthCalendar1 As System.Windows.Forms.MonthCalendar
Friend WithEvents WebBrowser1 As System.Windows.Forms.WebBrowser
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents RadioButton4 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents Panel3 As System.Windows.Forms.Panel
Friend WithEvents Panel5 As System.Windows.Forms.Panel
Friend WithEvents Panel4 As System.Windows.Forms.Panel
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
End Class
- The 'Compiled-Form1.wwm' class is coded by the developer or end-user to
expose aggregated WinForm methods, properties and events.
Public Class Form1
Public Event Changed(ByVal d As Date)
Public Sub New()
InitializeComponent()
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
End Sub
Public Sub Navigate(ByVal Url As String)
WebBrowser1.Url = New System.Uri(Url)
End Sub
Private Sub FireChanged()
Try
RaiseEvent Changed(MonthCalendar1.SelectionStart)
Catch
Finally
End Try
End Sub
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DateRangeEventArgs) _
Handles MonthCalendar1.DateChanged
FireChanged()
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
FireChanged()
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then FireChanged()
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then FireChanged()
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked Then FireChanged()
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked Then FireChanged()
End Sub
ReadOnly Property Radio As String
Get
If RadioButton1.Checked Then Return "Wikipedia"
If RadioButton2.Checked Then Return "Google"
If RadioButton3.Checked Then Return "Bing"
If RadioButton4.Checked Then Return "Library"
End Get
End Property
Private Sub RichTextBox1_LinkClicked(ByVal sender As Object, _
ByVal e As System.Windows.Forms.LinkClickedEventArgs) _
Handles RichTextBox1.LinkClicked
Navigate(e.LinkText)
End Sub
WriteOnly Property RichText As String
Set(ByVal value As String)
RichTextBox1.Text = value
End Set
End Property
End Class
You can download this WinWrap® Basic WinForms demo code by clicking this link
WinWrap® Basic WinForms Demo or by clicking on the following WinForm image. Then open the Day.wwp project with WinWrap® Director.
WinForms with WinWrap® Basic Architectural Demo
You can download this WinWrap® Basic WinForms demo code by clicking this link
WinWrap® Basic WinForms Architectural Demo. Then open the WinForm.wwp project with WinWrap® Director.
This second demo illustrates the simplest possible WinForm UI (a button) in WinWrap® Basic.
Conclusion
You can now design and create custom WinForms for use with WinWrap® Basic scripts. You can incorporate any WinForm control into WinWrap® Basic WinForms. And you can create custom user interfaces for specific clients.
WinWrap® Basic Version 10 with Compile Option gives script developers and end-users the ability to create custom WinForms utilizing any available WinForm control.
Developers with existing COM applications can now upgrade their applications to use WinForms with WinForm controls.
Further Reading: Industry Discussion of Visual Basic Forms
Visual Basic 2008 Express Edition by Microsoft.
Visual Basic on Wikipedia, "VB is considered a relatively easy to learn and use programming language, because of its graphical development features and BASIC heritage. Visual Basic was derived from BASIC and enables the rapid application development (RAD) of graphical user interface (GUI) applications. A programmer can put together an application using the components provided with Visual Basic itself."
Visual Basic Development Center by Microsoft, "The .NET Framework has two main components: the common language runtime and the .NET Framework class library."
Copyright Polar Engineering, Inc.