Tuesday, December 21, 2010

Wednesday 12/21/10

Here is a tutorial on stacks by Wei-Ming Lee

Module Module1

Sub Main()
Dim stack1 As New System.Collections.Stack

'push the items onto the stack
stack1.Push("What ")
stack1.Push("is ")
stack1.Push("the ")
stack1.Push("point ")
stack1.Push("of ")
stack1.Push("using ")
stack1.Push("stacks? ")


'get the item count in the stack

Dim itemCount As Integer = stack1.Count
Console.WriteLine("The stack has {0} items in it", itemCount)

'pop the items out from the stack
For i As Integer = 0 To stack1.Count - 1
MsgBox(stack1.Pop()) 'strings are printed in the reverse order
Next

Console.ReadLine()
End Sub

End Module


Here is a tutorial by Michael Halvorson


Imports System.Drawing.Printing
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
'Print using an error handler to catch problems
Try
AddHandler printdocument1.printpage, AddressOf Me.printgraphic
Catch ex As Exception
MessageBox.Show("Sorry, there was a problem printing", _
ex.ToString())

End Try
End Sub

'Sub for printing graphic
Private Sub PrintGraphic(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
'create the graphic using DrawImage
ev.Graphics.DrawImage(Image.FromFile(TextBox1.Text), _
ev.Graphics.VisibleClipBounds)
'specify that this is the last page to print
ev.HasMorePages = False

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

End Sub
End Class


and here are some tentative things I am doing with event handlers


Public Class MainClass
Private Event firstEvent()

Private Sub MainClass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RaiseEvent firstEvent()
End Sub


Sub TestEvents() Handles Me.firstEvent
MsgBox("First Event Raised")
Me.Name = "MainForm"
MsgBox("The form's name is now " & Me.Name.ToString)
btn = New Button
btn.Location = New Point(80, 70)
btn.Text = "Click me"
Me.Controls.Add(btn)
AddHandler btn.Click, AddressOf btn_click


End Sub


Private WithEvents btn As Button


Private Sub btn_click(ByVal sender As Object, ByVal e As EventArgs)
Dim textbox1 As New tTextbox(Me)
Me.Width = 400
Me.Height = 400
Me.Text = "Enter Text"
End Sub

End Class

Class buttons

End Class
Class tTextbox
Dim tbox As TextBox

Sub New(ByRef form1 As Form)
tBox = New TextBox
tBox.Size = New System.Drawing.Size(300, 300)
tBox.Location = New System.Drawing.Point(20, 20)
form1.Controls.Add(tBox)

End Sub



End Class

No comments: