home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / FYI__Trans2024101092006.psc / frmTPB.frm < prev    next >
Text File  |  2006-10-09  |  8KB  |  239 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTPB 
  3.    BackColor       =   &H00FFFFC0&
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   3870
  6.    ClientLeft      =   60
  7.    ClientTop       =   450
  8.    ClientWidth     =   7500
  9.    LinkTopic       =   "Form1"
  10.    Picture         =   "frmTPB.frx":0000
  11.    ScaleHeight     =   3870
  12.    ScaleWidth      =   7500
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.CheckBox Check1 
  15.       Caption         =   "Partialy ""Transparent"""
  16.       Height          =   540
  17.       Index           =   1
  18.       Left            =   1935
  19.       Style           =   1  'Graphical
  20.       TabIndex        =   8
  21.       Top             =   45
  22.       Width           =   1860
  23.    End
  24.    Begin VB.CheckBox Check1 
  25.       Caption         =   "100% ""Transparent"""
  26.       Height          =   540
  27.       Index           =   0
  28.       Left            =   30
  29.       Style           =   1  'Graphical
  30.       TabIndex        =   7
  31.       Top             =   45
  32.       Width           =   1875
  33.    End
  34.    Begin VB.CommandButton Command4 
  35.       Caption         =   "Move Image"
  36.       Height          =   495
  37.       Left            =   5055
  38.       TabIndex        =   6
  39.       Top             =   2520
  40.       Width           =   1215
  41.    End
  42.    Begin VB.CommandButton Command3 
  43.       Caption         =   "No Bubbles"
  44.       Height          =   495
  45.       Left            =   1080
  46.       TabIndex        =   5
  47.       Top             =   2535
  48.       Width           =   1215
  49.    End
  50.    Begin VB.CommandButton Command2 
  51.       Caption         =   "Chg Lbl Text"
  52.       Height          =   495
  53.       Left            =   3705
  54.       TabIndex        =   4
  55.       Top             =   2535
  56.       Width           =   1215
  57.    End
  58.    Begin VB.CommandButton Command1 
  59.       Caption         =   "Chg BkgColor"
  60.       Height          =   495
  61.       Left            =   2400
  62.       TabIndex        =   3
  63.       Top             =   2535
  64.       Width           =   1215
  65.    End
  66.    Begin VB.PictureBox Picture1 
  67.       Height          =   2070
  68.       Left            =   840
  69.       ScaleHeight     =   2010
  70.       ScaleWidth      =   5760
  71.       TabIndex        =   1
  72.       Top             =   1110
  73.       Width           =   5820
  74.       Begin VB.Image Image1 
  75.          Height          =   1305
  76.          Left            =   480
  77.          Top             =   390
  78.          Visible         =   0   'False
  79.          Width           =   4650
  80.       End
  81.    End
  82.    Begin prjTPB.ucTransPicBox UserControl11 
  83.       Height          =   750
  84.       Left            =   6765
  85.       TabIndex        =   0
  86.       Top             =   3090
  87.       Width           =   660
  88.       _ExtentX        =   1164
  89.       _ExtentY        =   1323
  90.    End
  91.    Begin VB.Image Image2 
  92.       Height          =   1440
  93.       Left            =   4245
  94.       Picture         =   "frmTPB.frx":101C6
  95.       Top             =   285
  96.       Width           =   1245
  97.    End
  98.    Begin VB.Label Label1 
  99.       BackColor       =   &H00000000&
  100.       Caption         =   "Label1"
  101.       BeginProperty Font 
  102.          Name            =   "Tahoma"
  103.          Size            =   8.25
  104.          Charset         =   0
  105.          Weight          =   700
  106.          Underline       =   0   'False
  107.          Italic          =   0   'False
  108.          Strikethrough   =   0   'False
  109.       EndProperty
  110.       ForeColor       =   &H0000FFFF&
  111.       Height          =   375
  112.       Left            =   1890
  113.       TabIndex        =   2
  114.       Top             =   1800
  115.       Width           =   2700
  116.    End
  117. End
  118. Attribute VB_Name = "frmTPB"
  119. Attribute VB_GlobalNameSpace = False
  120. Attribute VB_Creatable = False
  121. Attribute VB_PredeclaredId = True
  122. Attribute VB_Exposed = False
  123. Option Explicit
  124.  
  125. ' Test form for this approach to a transparent picture box
  126.  
  127. ' Note that this is NOT a true transparent picturebox. Any background graphics that
  128. ' are displayed on the picturebox are not clickable. In otherwords, if you place a
  129. ' label or image behind the picture box, it will show thru, but will not be interactive
  130.  
  131. ' See the usercontrol for more comments.
  132.  
  133.  
  134.  
  135. Private Sub Check1_Click(Index As Integer)
  136.  
  137.     If Check1(Index).Value = 0 Then ' not checked
  138.         If Check1(Abs(Index - 1)).Value = 0 Then ' also not checked, so check it
  139.             Check1(Abs(Index - 1)).Value = 1
  140.             Exit Sub
  141.         End If
  142.     Else
  143.         Check1(Abs(Index - 1)).Value = 0    ' uncheck the other checkbox
  144.         SetUpExample Index
  145.     End If
  146.             
  147. End Sub
  148.  
  149. ' some simple test routines
  150. Private Sub Command1_Click()
  151.     ' make form bkcolor change which should update the "transparent" picturebox too
  152.     Me.BackColor = vbBlue
  153. End Sub
  154.  
  155. Private Sub Command2_Click()
  156.     ' make label behind picbox change, which should update the "transparent" picturebox too
  157.     Label1.AutoSize = True
  158.     Label1.BackStyle = 0
  159.     Label1.Caption = "This label is actually behind the picture box"
  160. End Sub
  161.  
  162. Private Sub Command3_Click()
  163.     ' remove the form's picture property, which should update the "transparent" picturebox too
  164.     Set Me.Picture = Nothing
  165. End Sub
  166.  
  167. Private Sub Command4_Click()
  168.     ' move the foxhead image around the back of the picture box,  which should update the "transparent" picturebox too
  169.     Dim X As Long, Y As Long
  170.     X = CLng(Rnd * ScaleX(Picture1.Width, Picture1.ScaleMode, Me.ScaleMode))
  171.     Y = CLng(Rnd * ScaleY(Picture1.Height, Picture1.ScaleMode, Me.ScaleMode))
  172.     
  173.     Image2.Move X, Y
  174.     
  175. End Sub
  176.  
  177. Private Sub Form_Load()
  178.  
  179.     Picture1.AutoRedraw = True
  180.     Check1(0).Value = 1
  181.     
  182. End Sub
  183.  
  184.  
  185. Private Sub SetUpExample(Index As Integer)
  186.  
  187.     Dim X As Long, Y As Long
  188.  
  189.     ' call routine to give us a top,left coordinate to place the usercontrol and
  190.     ' also associate this usercontrol with a control (Picture1).
  191.     ' The routine will calculate the top,left and take into account the control's
  192.     ' borders, if applicable. The usercontrol needs to be placed exactly under the
  193.     ' picturebox's client area (not the area that includes the borders)
  194.     
  195.     
  196.     ' excuse the ScaleX/Y calcs below. This is used only so you can change scalemodes
  197.     ' in this sample project and also maintain the correct coordinates.
  198.     
  199.     If Index = 1 Then ' partial transparency example
  200.     
  201.         Image1.Visible = True
  202.         Set Image1.Picture = Nothing
  203.         
  204.         Picture1.BackColor = vbWhite
  205.         Set Picture1.Picture = Nothing
  206.         Picture1.Cls
  207.         
  208.         ' get the Image1 Top,Left in pixels
  209.         X = ScaleX(Image1.Left, Picture1.ScaleMode, vbPixels)
  210.         Y = ScaleY(Image1.Top, Picture1.ScaleMode, vbPixels)
  211.         ' associate with Image1
  212.         UserControl11.Initialize Me.hwnd, Picture1.hwnd, X, Y, Image1
  213.         ' position usercontrol exactly under Image1
  214.         With Picture1
  215.             UserControl11.Move ScaleX(X, vbPixels, Me.ScaleMode), ScaleY(Y, vbPixels, Me.ScaleMode), _
  216.                 ScaleX(Image1.Width, .ScaleMode, Me.ScaleMode), ScaleY(Image1.Height, .ScaleMode, Me.ScaleMode)
  217.         End With
  218.         Set Image1.Picture = UserControl11.Image
  219.         
  220.     Else            ' 100% transparent
  221.     
  222.         Image1.Visible = False
  223.         Picture1.BackColor = vbButtonFace
  224.         ' associate with Picture1
  225.         UserControl11.Initialize Me.hwnd, Picture1.hwnd, X, Y, Picture1
  226.         ' position usercontrol exactly under Picture1, shifting for borders if needed
  227.         With Picture1
  228.             UserControl11.Move ScaleX(X, vbPixels, Me.ScaleMode), ScaleY(Y, vbPixels, Me.ScaleMode), _
  229.                 ScaleX(.ScaleWidth, .ScaleMode, Me.ScaleMode), ScaleY(.ScaleHeight, .ScaleMode, Me.ScaleMode)
  230.         End With
  231.         ' set our PictureBox's Picture property to the usercontrol's Image
  232.         Set Picture1.Picture = UserControl11.Image
  233.     End If
  234.  
  235.     ' ensure our usercontrol is top most; this also triggers a repaint if needed
  236.     UserControl11.ZOrder
  237.  
  238. End Sub
  239.