Tech Note 03k: Using PictureBoxJan 2, 2007© NSB Corporation. All rights reserved. |
There is additional documentation on Microsoft's site.
The PictureBox control can be used for a lot more than just displaying pictures. Yes, it can be used to display a .bmp file. But it also supports drawing shapes such as lines and circles, can display text and can detect events such as taps. Picturebox is installed as part of your initial setup of NS Basic/CE. There is no need to install anything extra to use it.
The standard output from your program goes to an object called "Output". In the following examples, we'll demonstrate the various properties, methods and events using the Output Object.
You can also create your own PictureBox objects. These float above the Output Object. Use a command such as
addObject "picturebox.picturebox","pic",0,0,50,50
Notes and Quirks
1. If you want to set the fontsize, set the fontname first.
2. The cls function resets the properties - including things like your font.
3. You need to do a cls to clear the old value before calling DrawText.
4. The default scalemode for pictureboxes is Twips. To change it to pixels, do scalemode=3.
5. Always create your grid object first, including before the Visual Designer code. Otherwise, events coming from the grid object will be lost.
6. On Pocket PC devices, if you have trouble making a Picturebox larger than 100x100, set either the width or height explicitly, and it will be redrawn properly:
AddObject "Picturebox.PictureBox", "PictureBox1", 0, 100, 240, 180 Set Form1(2) = PictureBox1 Form1(2).width=240 Form1(2).height=180
The PictureBox properties, methods, and events listed in the following tables are supported.
Properties
Properties either set or return values. The syntax is
msgbox pic.backcolor 'display the current backcolor
pic.fontsize=10 'set the fontsize to 10
Name |
Description |
|
Color. Integer from 0 to 16,777,215. See color constants. |
|
0 none, 1 single line border |
|
Line width for draw methods |
|
Color, used to fill shapes, circles or boxes. |
|
0 solid, 1 transparent |
|
True/False. |
|
True/False. |
|
String |
|
In points. |
|
True/False. |
|
True/False. Do background graphics show through? |
|
True/False. |
|
color |
|
Height of object |
|
Left edge of object |
|
String with name of .bmp file |
|
Units for height using custom scale |
|
Left edge of object, to scale |
|
0 user defined |
|
returns top of current object |
|
Units for width using custom scale |
|
Use this for whatever you like |
|
Top of the object |
|
width of the object |
Methods
Name |
Arguments |
Description |
|
|
clears text and graphics. |
|
|
|
|
|
Box is true/false. |
|
|
|
|
|
|
|
|
Draws on next line on object. Cannot be positioned. |
|
|
Moves object to new x,y |
|
|
Redraws the object |
|
|
Converts scale of width. |
|
|
Converts scale of height. |
|
|
Use to change scale |
|
|
returns height of text. Embedded CR's OK. |
|
|
returns width of widest line. |
Events
Events cause subroutines in your program to be called, if they exist. You should name the subroutine <objectName>_eventName
.
For example, to capture clicks in the Output Object, you will need
sub output_click
'your code to handle a click
end sub
Name |
Arguments |
Description |
|
|
Called when object changes. |
|
|
Called when object is tapped. |
|
|
Called when object is double tapped. |
|
|
Shift=1, 2=CTRL, 4=ALT |
|
|
|
|
|
Shift=1, 2=CTRL, 4=ALT |
|
|
|
|
|
|
|
|
|
|
|
Called when object minimized/max/resumed |
Sample Code
rem Play around with some picturebox functions
output.backcolor=vbwhite
output.scalemode=3
output.drawpicture "\windows\startup.bmp",300,0
output.drawcircle 150,150,25
output.drawcircle 250,100,25
output.drawText "this is drawtext"
output.drawText "this is some more drawtext"
print
print
addObject "picturebox.picturebox","pic",200,0,50,50
pic.borderstyle=1
sub pic_click
print "pic click"
pic.move 1200,1200
end sub
sub output_click
print "click in Output"
end sub
sub output_mousedown(button, shift, x, y)
print "mouse down: button:" & button & " Shift:" & shift & " X:" & x & " Y:" & y
end sub