home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / bdemo / t (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  18.4 KB  |  454 lines

  1. VERSION 2.00
  2. Begin Form ButtonTest 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Picture-Button Demo"
  5.    ClientHeight    =   4215
  6.    ClientLeft      =   2055
  7.    ClientTop       =   1695
  8.    ClientWidth     =   5190
  9.    Height          =   4620
  10.    Icon            =   BDEMO.FRX:0000
  11.    Left            =   1995
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   281
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   346
  18.    Top             =   1350
  19.    Width           =   5310
  20.    Begin PictureBox ButtonStrip 
  21.       BackColor       =   &H0000FFFF&
  22.       Height          =   645
  23.       Left            =   -45
  24.       ScaleHeight     =   615
  25.       ScaleWidth      =   5205
  26.       TabIndex        =   1
  27.       Top             =   3405
  28.       Width           =   5235
  29.       Begin PictureBox PictureUP 
  30.          BackColor       =   &H0000FFFF&
  31.          BorderStyle     =   0  'None
  32.          Height          =   420
  33.          Left            =   3570
  34.          Picture         =   BDEMO.FRX:0302
  35.          ScaleHeight     =   420
  36.          ScaleWidth      =   570
  37.          TabIndex        =   4
  38.          Top             =   75
  39.          Width           =   570
  40.       End
  41.       Begin PictureBox PictureDN 
  42.          BackColor       =   &H0000FFFF&
  43.          BorderStyle     =   0  'None
  44.          Height          =   435
  45.          Left            =   3570
  46.          Picture         =   BDEMO.FRX:0604
  47.          ScaleHeight     =   435
  48.          ScaleWidth      =   540
  49.          TabIndex        =   5
  50.          Top             =   75
  51.          Visible         =   0   'False
  52.          Width           =   540
  53.       End
  54.       Begin PictureBox PushButton 
  55.          AutoRedraw      =   -1  'True
  56.          BackColor       =   &H00C0C0C0&
  57.          ForeColor       =   &H00FFFFFF&
  58.          Height          =   585
  59.          Index           =   4
  60.          Left            =   4170
  61.          ScaleHeight     =   37
  62.          ScaleMode       =   3  'Pixel
  63.          ScaleWidth      =   52
  64.          TabIndex        =   12
  65.          Top             =   15
  66.          Width           =   810
  67.          Begin PictureBox ButtonPict 
  68.             BackColor       =   &H00C0C0C0&
  69.             BorderStyle     =   0  'None
  70.             Height          =   270
  71.             Index           =   4
  72.             Left            =   75
  73.             Picture         =   BDEMO.FRX:0906
  74.             ScaleHeight     =   270
  75.             ScaleWidth      =   615
  76.             TabIndex        =   13
  77.             Top             =   150
  78.             Width           =   615
  79.          End
  80.       End
  81.       Begin PictureBox PushButton 
  82.          AutoRedraw      =   -1  'True
  83.          BackColor       =   &H00C0C0C0&
  84.          ForeColor       =   &H00FFFFFF&
  85.          Height          =   585
  86.          Index           =   3
  87.          Left            =   2625
  88.          ScaleHeight     =   37
  89.          ScaleMode       =   3  'Pixel
  90.          ScaleWidth      =   52
  91.          TabIndex        =   10
  92.          Top             =   15
  93.          Width           =   810
  94.          Begin PictureBox ButtonPict 
  95.             BackColor       =   &H00C0C0C0&
  96.             BorderStyle     =   0  'None
  97.             Height          =   315
  98.             Index           =   3
  99.             Left            =   135
  100.             Picture         =   BDEMO.FRX:0AD4
  101.             ScaleHeight     =   315
  102.             ScaleWidth      =   510
  103.             TabIndex        =   11
  104.             Top             =   120
  105.             Width           =   510
  106.          End
  107.       End
  108.       Begin PictureBox PushButton 
  109.          AutoRedraw      =   -1  'True
  110.          BackColor       =   &H00C0C0C0&
  111.          ForeColor       =   &H00FFFFFF&
  112.          Height          =   585
  113.          Index           =   2
  114.          Left            =   1830
  115.          ScaleHeight     =   37
  116.          ScaleMode       =   3  'Pixel
  117.          ScaleWidth      =   52
  118.          TabIndex        =   8
  119.          Top             =   15
  120.          Width           =   810
  121.          Begin PictureBox ButtonPict 
  122.             BackColor       =   &H00C0C0C0&
  123.             BorderStyle     =   0  'None
  124.             Height          =   420
  125.             Index           =   2
  126.             Left            =   150
  127.             Picture         =   BDEMO.FRX:0D06
  128.             ScaleHeight     =   420
  129.             ScaleWidth      =   510
  130.             TabIndex        =   9
  131.             Top             =   45
  132.             Width           =   510
  133.          End
  134.       End
  135.       Begin PictureBox PushButton 
  136.          AutoRedraw      =   -1  'True
  137.          BackColor       =   &H00C0C0C0&
  138.          ForeColor       =   &H00FFFFFF&
  139.          Height          =   585
  140.          Index           =   1
  141.          Left            =   1035
  142.          ScaleHeight     =   37
  143.          ScaleMode       =   3  'Pixel
  144.          ScaleWidth      =   52
  145.          TabIndex        =   6
  146.          Top             =   15
  147.          Width           =   810
  148.          Begin PictureBox ButtonPict 
  149.             BackColor       =   &H00C0C0C0&
  150.             BorderStyle     =   0  'None
  151.             Height          =   450
  152.             Index           =   1
  153.             Left            =   210
  154.             Picture         =   BDEMO.FRX:1008
  155.             ScaleHeight     =   100
  156.             ScaleMode       =   0  'User
  157.             ScaleWidth      =   405
  158.             TabIndex        =   7
  159.             Top             =   45
  160.             Width           =   405
  161.          End
  162.       End
  163.       Begin PictureBox PushButton 
  164.          AutoRedraw      =   -1  'True
  165.          BackColor       =   &H00C0C0C0&
  166.          ForeColor       =   &H00FFFFFF&
  167.          Height          =   585
  168.          Index           =   0
  169.          Left            =   240
  170.          ScaleHeight     =   37
  171.          ScaleMode       =   3  'Pixel
  172.          ScaleWidth      =   52
  173.          TabIndex        =   2
  174.          Top             =   15
  175.          Width           =   810
  176.          Begin PictureBox ButtonPict 
  177.             BackColor       =   &H00C0C0C0&
  178.             BorderStyle     =   0  'None
  179.             Height          =   405
  180.             Index           =   0
  181.             Left            =   165
  182.             Picture         =   BDEMO.FRX:130A
  183.             ScaleHeight     =   405
  184.             ScaleMode       =   0  'User
  185.             ScaleWidth      =   405
  186.             TabIndex        =   3
  187.             Top             =   75
  188.             Width           =   510
  189.          End
  190.       End
  191.    End
  192.    Begin PictureBox Picture1 
  193.       BackColor       =   &H00FFFFFF&
  194.       FontBold        =   -1  'True
  195.       FontItalic      =   0   'False
  196.       FontName        =   "MS Sans Serif"
  197.       FontSize        =   13.5
  198.       FontStrikethru  =   0   'False
  199.       FontUnderline   =   0   'False
  200.       ForeColor       =   &H00FFFFFF&
  201.       Height          =   3105
  202.       Left            =   165
  203.       Picture         =   BDEMO.FRX:160C
  204.       ScaleHeight     =   3075
  205.       ScaleWidth      =   4830
  206.       TabIndex        =   0
  207.       Top             =   165
  208.       Width           =   4860
  209.    End
  210. 'The main procedures in this program are the general
  211. 'procedures ButtonUp and ButtonDown. Form_Load initializes
  212. 'the buttons in the up position and stores the locations
  213. 'of their pictures.
  214. 'To use these procedures in your program:
  215. '   1.  Create a picture box control with the CtlName set
  216. '       to "PushButton"
  217. '   2.  Create a picture box control on top of the PushButtton
  218. '       picture box and set the CtlName to "ButtonPict".
  219. '   3.  Copy both picture boxes by selecting the PushButton
  220. '       picture box and executing the "Edit-Copy" command.
  221. '   4.  Paste a copy for each button you want to create and
  222. '       create the control arrays PushButton() and ButtonPict().
  223. '       These procedures were obviously designed to control
  224. '       more than one button. You can, however, modify them
  225. '       if you need only one simulated button.
  226. '   6.  Adjust the buttons to the sizes you want. Although the
  227. '       routines should work with any size buttons, there is
  228. '       a practical limit because of the time it takes for VB
  229. '       to draw the lines on them.
  230. '   5.  Load your pictures (icon, bmp, etc) into the picture
  231. '       boxes on top of your buttons (ButtonPict()), size and
  232. '       position them as necessary.
  233. '   6.  Copy the subs ButtonUp and ButtonDown into the
  234. '       (general) (declarations) section for your form and the
  235. '       initializing routine into your Form_Load procedure.
  236. '   7.  Put a CALL to ButtonDown in your PushButton_MouseDown and
  237. '       ButtonPict_MouseDown event procedures. Likewise, put calls
  238. '       to ButtonUp in your PushButton_MouseUp and ButtonPict_
  239. '       MouseUp event procedures.
  240. '   8.  Copy the declarations below into your program and change
  241. '       the value of NumButtons% to the number of simulated
  242. '       buttons on your form.
  243. 'That is all there is to it. See the comments in ButtonUp and
  244. 'ButtonDown for more information.
  245. 'The camera button (the camera that is a button) is handled differently.
  246. 'it is simply two separate pictures (not an array). The picture
  247. 'that represents the object in the up position is called PictureUp and
  248. 'is placed over the other (PictureDn). Your code only needs to
  249. 'handle the MouseUp and MouseDown events for the top picture, since
  250. 'the user cannot access the bottom picture. In your mouse event
  251. 'handlers, you just have to switch visibility between the two pictures.
  252. 'You could, of course, do all of your buttons this way by making
  253. 'two control arrays for the pictures, just like the other buttons,
  254. 'but this method requires a little more manual work, because you have
  255. 'to create both up and down representations of each picture. The camera
  256. 'was first drawn (using Iconwrks) in the up position with shadows on the
  257. 'right and bottom. Then the icon was copied and pasted into another
  258. 'icon - offset one pixel to the right and one pixel down from the original.
  259. 'The shadow was removed from the right and bottom and shadow was added
  260. 'to the top and left. You can load both icons into Icon Works to see
  261. 'what I mean.
  262. 'Change the Constant NumButtons% to the actual number of simulated
  263. 'buttons on your form.
  264. Const NumButtons% = 5
  265. Dim ix As Integer 'used to pass the index to the general procedures
  266. Dim x1 As Integer 'These are used for
  267. Dim x2 As Integer '   coordinates when
  268. Dim y1 As Integer '   moving the pictures
  269. Dim y2 As Integer '   on the buttons.
  270. Dim ButtPictTop() As Single   'These will store the locations
  271. Dim ButtPictLeft() As Single  '   of the button pictures when
  272.                               '   the form is loaded.
  273. Sub ButtonDown (ix As Integer)
  274. 'This procedure draws the button in the down position.
  275. 'Remember ScaleMode must be set to 3 (pixels) on PushButton()
  276. 'for this to work properly.
  277. PushButton(ix).DrawWidth = 1  'Set line width to one pixel
  278. '=========================================================
  279. '*** First draw a black box around the button          ***
  280. '---------------------------------------------------------
  281. x1 = 0
  282. x2 = PushButton(ix).ScaleWidth - 1
  283. y1 = 0
  284. y2 = PushButton(ix).ScaleHeight - 1
  285. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(0), B
  286. '=========================================================
  287. '*** Next erase the white and dark inside lines and    ***
  288. '*** change the white outside lines to dark grey.      ***
  289. '---------------------------------------------------------
  290. x1 = 1
  291. x2 = PushButton(ix).ScaleWidth - 2
  292. Y = PushButton(ix).ScaleHeight - 2
  293. PushButton(ix).Line (x1, Y)-(x2, Y), QBColor(7)
  294. Y = 1
  295. PushButton(ix).Line (x1, Y)-(x2, Y), QBColor(8)
  296. X = 1
  297. y1 = 1: y2 = PushButton(ix).ScaleHeight
  298. PushButton(ix).Line (X, y1)-(X, y2), QBColor(8)
  299. X = PushButton(ix).ScaleWidth - 2
  300. y1 = 2: y2 = PushButton(ix).ScaleHeight
  301. PushButton(ix).Line (X, y1)-(X, y2), QBColor(7)
  302. '=========================================================
  303. '*** Move the picture down and right 1 pixel           ***
  304. '---------------------------------------------------------
  305. mx! = ButtPictLeft(ix) + 1
  306. my! = ButtPictTop(ix) + 1
  307. ButtonPict(ix).Move mx!, my!
  308. '***********************************************************
  309. '** The following code puts the demo text on the picture. **
  310. '** You could process your button commands here or in the **
  311. '** ButtonUP procedure.  Processing in the ButtonUP pro-  **
  312. '** cedure would act like a Command_Click event.          **
  313. '***********************************************************
  314. Select Case ix              'ix is the button index
  315.     Case 0
  316.         a$ = "Camera"
  317.     Case 1
  318.         a$ = "Apple"
  319.     Case 2
  320.         a$ = "Folder"
  321.     Case 3
  322.         a$ = "Test"
  323.     Case 4
  324.         a$ = "Quit"
  325. End Select
  326. a$ = a$ + " Button"
  327. picture1.CurrentX = 100
  328. picture1.CurrentY = 100
  329. picture1.Print a$
  330. End Sub
  331. Sub ButtonPict_MouseDown (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  332. '===========================================================
  333. '*** This is necessary in case someone presses the mouse ***
  334. '*** button while the pointer is over the picture on the ***
  335. '*** button instead of the button itself.                ***
  336. '-----------------------------------------------------------
  337. Call ButtonDown(index)
  338. End Sub
  339. Sub ButtonPict_MouseUp (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  340. '===========================================================
  341. '*** This is necessary in case someone pressed the mouse ***
  342. '*** button while the pointer was over the picture on    ***
  343. '*** the button instead of the button itself.            ***
  344. '-----------------------------------------------------------
  345. Call ButtonUP(index)
  346. If index = 4 Then End
  347. End Sub
  348. Sub ButtonUP (ix As Integer)
  349. PushButton(ix).DrawWidth = 1
  350. '=========================================================
  351. '*** Draw 2 white lines accross the top of the button. ***
  352. '*** The second is 1 pixel shorter than the first.     ***
  353. '---------------------------------------------------------
  354. x1 = 0: x2 = PushButton(ix).ScaleWidth - 1
  355. y1 = 0: y2 = 0
  356. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(15)
  357. x1 = 0: x2 = PushButton(ix).ScaleWidth - 2
  358. y1 = 1: y2 = 1
  359. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(15)
  360. '=========================================================
  361. '***  Draw 2 dark lines on the left side of the button. **
  362. '***  The second is 2 pixels shorter than the first.    **
  363. '---------------------------------------------------------
  364. x1 = PushButton(ix).ScaleWidth - 1: x2 = x1
  365. y1 = 1: y2 = PushButton(ix).ScaleHeight - 1
  366. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(8)
  367. x1 = PushButton(ix).ScaleWidth - 2: x2 = x1
  368. y1 = 2: y2 = PushButton(ix).ScaleHeight - 2
  369. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(8)
  370. '=========================================================
  371. '*** Draw 2 white lines down the left side of the button *
  372. '*** The second is 2 pixels shorter than the first.      *
  373. '---------------------------------------------------------
  374. x1 = 0: x2 = x1
  375. y1 = 1: y2 = PushButton(ix).ScaleHeight - 1
  376. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(15)
  377. x1 = 1: x2 = x1
  378. y1 = 2: y2 = PushButton(ix).ScaleHeight - 2
  379. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(15)
  380. '=========================================================
  381. '*** Draw 2 dark lines at the bottom of the button.    ***
  382. '*** The second is 2 pixels longer than the first.     ***
  383. '---------------------------------------------------------
  384. x1 = 1: x2 = PushButton(ix).ScaleWidth - 1
  385. y1 = PushButton(ix).ScaleHeight - 2: y2 = y1
  386. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(8)
  387. x1 = 0: x2 = PushButton(ix).ScaleWidth
  388. y1 = PushButton(ix).ScaleHeight - 1: y2 = y1
  389. PushButton(ix).Line (x1, y1)-(x2, y2), QBColor(8)
  390. '=========================================================
  391. '*** Move the picture up and left 1 pixel              ***
  392. '---------------------------------------------------------
  393. mx! = ButtPictLeft(ix)
  394. my! = ButtPictTop(ix)
  395. ButtonPict(ix).Move mx!, my!
  396. '*******************************************************
  397. '**  You could put your button processing code here   **
  398. '**  to look like a Command_Click event.              **
  399. '*******************************************************
  400. picture1.Refresh    'For this demo just erase the text
  401.                     'on the picture.
  402. End Sub
  403. Sub Form_Load ()
  404. ReDim ButtPictTop(NumButtons - 1)
  405. ReDim ButtPictLeft(NumButtons - 1)
  406. For ix = 0 To NumButtons - 1    'Display all the buttons
  407.     ButtPictTop(ix) = ButtonPict(ix).Top
  408.     ButtPictLeft(ix) = ButtonPict(ix).Left
  409.     Call ButtonUP(ix)           'in the up position.
  410. Next ix
  411. End Sub
  412. Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  413. picture1.CurrentX = 100
  414. picture1.CurrentY = 100
  415. picture1.Print "This picture is just for decoration."
  416. End Sub
  417. Sub Picture1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  418. picture1.Refresh
  419. End Sub
  420. Sub PictureUP_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  421. '=======================================================
  422. '*** This handles the camera that is not on a button ***
  423. '=======================================================
  424. PictureDN.Visible = -1
  425. PictureUP.Visible = 0
  426. '********************************************************
  427. '**  Process code here - just like a command_MouseDown **
  428. '**  event. Or you could put your code in the MouseUP  **
  429. '**  procedure to make it look like a Command_Click.   **
  430. '********************************************************
  431. picture1.CurrentX = 100
  432. picture1.CurrentY = 100
  433. picture1.Print "You're holding the camera down."
  434. End Sub
  435. Sub PictureUP_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  436. '******************************************************
  437. '** This procedure handles the camera that is not on **
  438. '** a button.                                        **
  439. '******************************************************
  440. PictureUP.Visible = -1
  441. PictureDN.Visible = 0
  442. '******************************************************
  443. '**  Process code here - just like a command button  **
  444. '******************************************************
  445. picture1.Refresh
  446. End Sub
  447. Sub PushButton_MouseDown (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  448. Call ButtonDown(index)
  449. End Sub
  450. Sub PushButton_MouseUp (index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  451. Call ButtonUP(index)
  452. If index = 4 Then End
  453. End Sub
  454.