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
|
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel.Design
Imports System.Drawing.Design
Namespace pF.DesignSurfaceExt
Public Partial Class MainForm
Inherits Form
Private _version As String = String.Empty
Public ReadOnly Property Version As String
Get
If String.IsNullOrEmpty(_version) Then
'- Get the actual version of the file hosted in running assembly
Dim FVI As System.Diagnostics.FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)
_version = FVI.ProductVersion
End If
Return _version
End Get
End Property
Private _listOfDesignSurface As List(Of IDesignSurfaceExt2) = New List(Of IDesignSurfaceExt2)()
Private Function GetCurrentIDesignSurface() As IDesignSurfaceExt2
If Nothing Is _listOfDesignSurface Then Return Nothing
If 0 = _listOfDesignSurface.Count Then Return Nothing
Return _listOfDesignSurface(tabControl1.SelectedIndex)
End Function
#Region "Init"
'- ctor
Public Sub New()
InitializeComponent()
'- Add the toolboxItems to the future toolbox
'- the pointer
Dim toolPointer As ToolboxItem = New ToolboxItem()
toolPointer.DisplayName = "<Pointer>"
toolPointer.Bitmap = New Bitmap(16, 16)
listBox1.Items.Add(toolPointer)
'- the control
listBox1.Items.Add(New ToolboxItem(GetType(Button)))
listBox1.Items.Add(New ToolboxItem(GetType(ListView)))
listBox1.Items.Add(New ToolboxItem(GetType(TreeView)))
listBox1.Items.Add(New ToolboxItem(GetType(TextBox)))
listBox1.Items.Add(New ToolboxItem(GetType(Label)))
listBox1.Items.Add(New ToolboxItem(GetType(TabControl)))
listBox1.Items.Add(New ToolboxItem(GetType(OpenFileDialog)))
listBox1.Items.Add(New ToolboxItem(GetType(CheckBox)))
listBox1.Items.Add(New ToolboxItem(GetType(ComboBox)))
listBox1.Items.Add(New ToolboxItem(GetType(GroupBox)))
listBox1.Items.Add(New ToolboxItem(GetType(ImageList)))
listBox1.Items.Add(New ToolboxItem(GetType(Panel)))
listBox1.Items.Add(New ToolboxItem(GetType(ProgressBar)))
listBox1.Items.Add(New ToolboxItem(GetType(ToolBar)))
listBox1.Items.Add(New ToolboxItem(GetType(ToolTip)))
listBox1.Items.Add(New ToolboxItem(GetType(StatusBar)))
End Sub
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler tabControl1.Selected, New TabControlEventHandler(AddressOf OnTabPageSelected)
End Sub
Private Sub OnTabPageSelected(ByVal sender As Object, ByVal e As TabControlEventArgs)
'- select into the propertygrid the current Form
SelectRootComponent()
End Sub
#End Region
'- When the selection changes this sets the PropertyGrid's selected component
Private Sub OnSelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim isurf As IDesignSurfaceExt = GetCurrentIDesignSurface()
If Nothing IsNot isurf Then
Dim selectionService As ISelectionService = Nothing
selectionService = TryCast(isurf.GetIDesignerHost().GetService(GetType(ISelectionService)), ISelectionService)
propertyGrid.SelectedObject = selectionService.PrimarySelection
End If
End Sub
Private Sub SelectRootComponent()
'- find out the DesignSurfaceExt control hosted by the TabPage
Dim isurf As IDesignSurfaceExt = GetCurrentIDesignSurface()
If Nothing IsNot isurf Then propertyGrid.SelectedObject = isurf.GetIDesignerHost().RootComponent
End Sub
Private Sub undoToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim isurf As IDesignSurfaceExt = GetCurrentIDesignSurface()
If Nothing IsNot isurf Then isurf.GetUndoEngineExt().Undo()
End Sub
Private Sub redoToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim isurf As IDesignSurfaceExt = GetCurrentIDesignSurface()
If Nothing IsNot isurf Then isurf.GetUndoEngineExt().Redo()
End Sub
Private Sub OnAbout(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("Tiny Form IDE coded by Paolo Foti " & Microsoft.VisualBasic.Constants.vbCrLf & "Version is: " & Version, "Tiny Form IDE", MessageBoxButtons.OK, MessageBoxIcon.Question)
End Sub
Private Sub toolStripMenuItemTabOrder_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim isurf As IDesignSurfaceExt = GetCurrentIDesignSurface()
If Nothing IsNot isurf Then isurf.SwitchTabOrder()
End Sub
Private Sub OnMenuClick(ByVal sender As Object, ByVal e As EventArgs)
Dim isurf As IDesignSurfaceExt = GetCurrentIDesignSurface()
If Nothing IsNot isurf Then isurf.DoAction(TryCast(sender, ToolStripMenuItem).Text)
End Sub
Private Sub newFormUseSnapLinesMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim tp As TabPage = New TabPage("Use SnapLines")
tabControl1.TabPages.Add(tp)
Dim iTabPageSelectedIndex As Integer = tabControl1.SelectedIndex
'- steps.1.2.3
Dim surface As DesignSurfaceExt2 = CreateDesignSurface()
'- step.4
'- choose an alignment mode...
CType(surface, DesignSurfaceExt2).UseSnapLines()
'- step.5
'- create the Root compoment, in these cases a Form
Try
Dim rootComponent As Form = Nothing
rootComponent = CType(surface.CreateRootComponent(GetType(Form), New Size(400, 400)), Form)
rootComponent.Text = "Root Component hosted by the DesignSurface N." & iTabPageSelectedIndex
rootComponent.BackColor = Color.Yellow
'-
'-
'- step.4
'- display the DesignSurface
Dim view As Control = surface.GetView()
If Nothing Is view Then Return
'- change some properties
view.Text = "Test Form N. " & iTabPageSelectedIndex
view.Dock = DockStyle.Fill
'- Note these assignments
view.Parent = tp
'- finally enable the Drag&Drop on RootComponent
CType(surface, DesignSurfaceExt2).EnableDragandDrop() 'end_try
Catch ex As Exception
Console.WriteLine(Name & " the DesignSurface N. " & iTabPageSelectedIndex & " has generated errors during loading!Exception: " & ex.Message)
Return
End Try 'end_catch
End Sub
Private Sub newFormUseGridandSnapMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim tp As TabPage = New TabPage("Use Grid (Snap to the grid)")
tabControl1.TabPages.Add(tp)
Dim iTabPageSelectedIndex As Integer = tabControl1.SelectedIndex
'- steps.1.2.3
Dim surface As DesignSurfaceExt2 = CreateDesignSurface()
'- step.4
'- choose an alignment mode...
CType(surface, DesignSurfaceExt2).UseGrid(New Size(32, 32))
'- step.5
'- create the Root compoment, in these cases a Form
Try
Dim rootComponent As Form = Nothing
rootComponent = CType(surface.CreateRootComponent(GetType(Form), New Size(400, 400)), Form)
rootComponent.Text = "Root Component hosted by the DesignSurface N." & iTabPageSelectedIndex
rootComponent.BackColor = Color.YellowGreen
'-
'-
'- step.4
'- display the DesignSurface
Dim view As Control = surface.GetView()
If Nothing Is view Then Return
'- change some properties
view.Text = "Test Form N. " & iTabPageSelectedIndex
view.Dock = DockStyle.Fill
'- Note these assignments
view.Parent = tp 'end_try
Catch ex As Exception
Console.WriteLine(Name & " the DesignSurface N. " & iTabPageSelectedIndex & " has generated errors during loading!Exception: " & ex.Message)
Return
End Try 'end_catch
End Sub
Private Sub newFormUseGridMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim tp As TabPage = New TabPage("Use Grid")
tabControl1.TabPages.Add(tp)
Dim iTabPageSelectedIndex As Integer = tabControl1.SelectedIndex
'- steps.1.2.3
Dim surface As DesignSurfaceExt2 = CreateDesignSurface()
'- step.4
'- choose an alignment mode...
CType(surface, DesignSurfaceExt2).UseGridWithoutSnapping(New Size(16, 16))
'- step.5
'- create the Root compoment, in these cases a Form
Try
Dim rootComponent As Form = Nothing
rootComponent = CType(surface.CreateRootComponent(GetType(Form), New Size(600, 400)), Form)
rootComponent.Text = "Root Component hosted by the DesignSurface N." & iTabPageSelectedIndex
rootComponent.BackColor = Color.LightGreen
'-
'-
'- step.4
'- display the DesignSurface
Dim view As Control = surface.GetView()
If Nothing Is view Then Return
'- change some properties
view.Text = "Test Form N. " & iTabPageSelectedIndex
view.Dock = DockStyle.Fill
'- Note these assignments
view.Parent = tp 'end_try
Catch ex As Exception
Console.WriteLine(Name & " the DesignSurface N. " & iTabPageSelectedIndex & " has generated errors during loading!Exception: " & ex.Message)
Return
End Try 'end_catch
End Sub
Private Sub newFormAlignControlByhandMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim tp As TabPage = New TabPage("Align control by hand")
tabControl1.TabPages.Add(tp)
Dim iTabPageSelectedIndex As Integer = tabControl1.SelectedIndex
'- steps.1.2.3
Dim surface As DesignSurfaceExt2 = CreateDesignSurface()
'- step.4
'- choose an alignment mode...
CType(surface, DesignSurfaceExt2).UseNoGuides()
'- step.5
'- create the Root compoment, in these cases a Form
Try
Dim rootComponent As Form = Nothing
rootComponent = CType(surface.CreateRootComponent(GetType(Form), New Size(400, 400)), Form)
rootComponent.Text = "Root Component hosted by the DesignSurface N." & iTabPageSelectedIndex
rootComponent.BackColor = Color.LightGray
'-
'-
'- step.4
'- display the DesignSurface
Dim view As Control = surface.GetView()
If Nothing Is view Then Return
'- change some properties
view.Text = "Test Form N. " & iTabPageSelectedIndex
view.Dock = DockStyle.Fill
'- Note these assignments
view.Parent = tp 'end_try
Catch ex As Exception
Console.WriteLine(Name & " the DesignSurface N. " & iTabPageSelectedIndex & " has generated errors during loading!Exception: " & ex.Message)
Return
End Try 'end_catch
End Sub
Private Function CreateDesignSurface() As DesignSurfaceExt2
'- step.0
'- create a DesignSurface and put it inside a Form in DesignTime
Dim surface As DesignSurfaceExt2 = New DesignSurfaceExt2()
'-
'-
Dim isurf As IDesignSurfaceExt2 = surface
_listOfDesignSurface.Add(isurf)
'- step.1
'- enable the UndoEngines
isurf.GetUndoEngineExt().Enabled = True
'- step.2
'- try to get a ptr to ISelectionService interface
'- if we obtain it then hook the SelectionChanged event
Dim selectionService As ISelectionService = CType((isurf.GetIDesignerHost().GetService(GetType(ISelectionService))), ISelectionService)
If Nothing IsNot selectionService Then AddHandler selectionService.SelectionChanged, New EventHandler(AddressOf OnSelectionChanged)
'- step.3
'- Select the service IToolboxService
'- and hook it to our ListBox
Dim tbox As ToolboxServiceImp = TryCast(isurf.GetIToolboxService(), ToolboxServiceImp)
If Nothing IsNot tbox Then tbox.Toolbox = listBox1
'-
'- finally return the Designsurface
Return surface
End Function
Private Sub MainForm_Load_1(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Dim rootComponent As Form = Nothing
Dim surface As DesignSurfaceExt2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tp As TabPage = New TabPage("Use SnapLines")
tabControl1.TabPages.Add(tp)
Dim iTabPageSelectedIndex As Integer = tabControl1.SelectedIndex
'- steps.1.2.3
Dim surface As DesignSurfaceExt2 = CreateDesignSurface()
'- step.4
'- choose an alignment mode...
CType(surface, DesignSurfaceExt2).UseSnapLines()
'- step.5
'- create the Root compoment, in these cases a Form
Try
rootComponent = CType(surface.CreateRootComponent(GetType(Form), New Size(400, 400)), Form)
rootComponent.Text = "Root Component hosted by the DesignSurface N." & iTabPageSelectedIndex
rootComponent.BackColor = Color.Yellow
'-
'-
'- step.4
'- display the DesignSurface
Dim view As Control = surface.GetView()
If Nothing Is view Then Return
'- change some properties
view.Text = "Test Form N. " & iTabPageSelectedIndex
view.Dock = DockStyle.Fill
'- Note these assignments
view.Parent = tp
'- finally enable the Drag&Drop on RootComponent
CType(surface, DesignSurfaceExt2).EnableDragandDrop() 'end_try
Catch ex As Exception
Console.WriteLine(Name & " the DesignSurface N. " & iTabPageSelectedIndex & " has generated errors during loading!Exception: " & ex.Message)
Return
End Try 'end_catch
End Sub
End Class
End Namespace |
Partager