Download presentation
Presentation is loading. Please wait.
1
Odds and Ends Component Tray Menu and contextmenu Splash Screen
2
Examples in this show Mainmenu Context menu Errorprovider Splashscreen Cellular automata
3
The component tray contains: Timer Errorhandlers Print capabilities DialogBoxes Menus Context menus
4
Adding a main menu Most apps nowadays have menus – MS powerpoint and the VB IDE both do.
5
Add Mainmenu to component tray from toolbox
6
Selecting the mainmenu control allows you to begin editing the menu
7
and editing…and editing
8
add submenus to a menu item by filling in the little box that appears below or next to it.
9
As with other controls, it is a good idea to rename menu items from MenuItem1,…to mnuFile, …
10
shortcut keys You can add shortcut keys to a menu item by selecting shortcut in the properties for this item. Select the shortcut you wish to associate with the menu item.
11
Ctrl-s for save
12
More about menus Menu items display their submenus automatically if they have them. You add itemclick subs to add functionality to menu items that have no submenu.
13
Save clicked event handler Private Sub mnufilesave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnufilesave.Click MessageBox.Show("save selected", "Menu", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) End Sub
14
Clicking save in debug
15
Context menu A context menu is added (to the form component tray) from the toolbox. When you right-click a control information can be displayed.
16
Context menu
17
Add context menu to a control in properties
18
Add to context menu as you would to a regular menu
19
Add sub code to context
20
Context menu popup code Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup MessageBox.Show("context", "context", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) End Sub
22
Menu example exe In p:\vs\menu
23
Handling errors Handling errors with an errorprovider It is added to the component tray
24
Handling errors
25
Error provider An errorprovider is added to the component tray In this project the “causes validation” property of the two textboxes are both set to true Just the validation code was written – no other processing
26
Build error provider when form is loaded Private Sub frmmain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load errorhandler = New ErrorProvider() End Sub
27
Corrected one error, now have another
28
Another ss entry error
29
Finally: Corrected ss num error
30
Two event handlers provided – the validation for the textboxes Private Sub txtint_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtint.Validating Dim int As Integer errorhandler.SetError(txtint, "")’ clear any old errors Try int = Integer.Parse(txtint.Text) Catch ex As Exception errorhandler.SetError(txtint, "field must be int") e.Cancel = True ‘cancel event End Try End Sub
31
Part of ss validation Private Sub txtss_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtss.Validating ' Me.Refresh() errorhandler.SetError(txtss, "") Dim ss As String ss = txtss.Text If ss = "" Then errorhandler.SetError(txtss, "field required") e.Cancel = True ElseIf ss.Length <> 11 Then e.Cancel = True errorhandler.SetError(txtss, "field must contain 11 chars") ElseIf ss.Substring(3, 1) <> "-" Or ss.Substring(6, 1) <> "-" Then ‘’’’’there’s more End If End sub
32
Errorprovider example In p:\vsp\errorprovider\bin\... There is more to do with this example… like enable navigation and exit without correcting the error.
33
Splash screen: comes up briefly with some info when a form is loaded
34
Splash screens: Create a main form with just a label and exit button Add the exit code (me.close()) Add a second form to the project called frmSplash
35
Splash screens: On frmsplash put: Information about the application, copyright, programmer, date, pictures, whatever.
36
Splash screens: Add a timer with interval 5000 to the frmspash. In the timertick sub put –Me.Close() ‘close form after 5 sec Be sure to start the timer in the frmsplash load sub.
37
Splash screens: set topmost property to true
38
set frmsplash formborderstyle to fixedtool (so it can’t be resized)
39
Back in frmmain Add formload code to create an instance of the frmsplash. Recall this code is: Dim x as frmsplash x.show() When frmsplash loads it will start its timer. Exe in p:\vs\splash\splash.exe
40
Cellular automata: in p drive vb folder
41
Cellular automata There are many examples of uses of cellular automata, from biological modeling to designing fabric patterns. I cover only a little bit about them here. Discussion of 2-d automata Discussion of 1-d automata
42
One dimensional automata The original values are stored in an array. These might be generated randomly, or come from measurements. Display (in VB) might be in a panel. The “first generation” consists of a single set of rectangular colors. Each color represents an integer in the array. The next generation is computed from the first (usually) according to some formula for example: Newvalue(i)=(old(i-1)+old(i)+old(i+1)) mod maxcolors You’ll need two one dimensional arrays, and you’ll have to keep copying the new values back into the old array, and displaying.
43
Two dimensional automata Two d automata are displayed similarly to one-dimensional ones: each value represents a color. But each new generation is computed in two dimensions, often using some rule about how many neighbors a given cell has in the current generation.
44
Two dimensional automata A sketch of the code goes like this: 1.Assign initial values to a fairly large (like 100X100) array. 2.Loop a bunch of times or do on buttonclick: 3.Compute next generation values into a new array 4.Display the current generation 5.Copy next generation into current 6.endloop
45
Example..in p:\vb\twodcellularautomata.exe
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.