home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Sudoku_-_T207402752007.psc / Cell.ctl < prev    next >
Text File  |  2007-07-05  |  15KB  |  515 lines

  1. VERSION 5.00
  2. Begin VB.UserControl Cell 
  3.    CanGetFocus     =   0   'False
  4.    ClientHeight    =   735
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   720
  8.    ClipBehavior    =   0  'None
  9.    ClipControls    =   0   'False
  10.    HasDC           =   0   'False
  11.    Picture         =   "Cell.ctx":0000
  12.    ScaleHeight     =   735
  13.    ScaleWidth      =   720
  14.    ToolboxBitmap   =   "Cell.ctx":2376
  15.    Begin VB.Timer tmrHiLight 
  16.       Enabled         =   0   'False
  17.       Interval        =   10
  18.       Left            =   900
  19.       Top             =   120
  20.    End
  21.    Begin VB.Image imgLib 
  22.       Height          =   720
  23.       Index           =   2
  24.       Left            =   1650
  25.       Picture         =   "Cell.ctx":2688
  26.       Top             =   1155
  27.       Width           =   720
  28.    End
  29.    Begin VB.Image imgLib 
  30.       Height          =   720
  31.       Index           =   1
  32.       Left            =   855
  33.       Picture         =   "Cell.ctx":49B4
  34.       Top             =   1140
  35.       Width           =   720
  36.    End
  37.    Begin VB.Image imgLib 
  38.       Height          =   720
  39.       Index           =   0
  40.       Left            =   60
  41.       Picture         =   "Cell.ctx":6CA8
  42.       Top             =   1140
  43.       Width           =   720
  44.    End
  45.    Begin VB.Label lblNote 
  46.       Alignment       =   2  'Center
  47.       BackColor       =   &H00000000&
  48.       BackStyle       =   0  'Transparent
  49.       BeginProperty Font 
  50.          Name            =   "Georgia"
  51.          Size            =   9
  52.          Charset         =   0
  53.          Weight          =   700
  54.          Underline       =   0   'False
  55.          Italic          =   -1  'True
  56.          Strikethrough   =   0   'False
  57.       EndProperty
  58.       ForeColor       =   &H00404040&
  59.       Height          =   260
  60.       Index           =   4
  61.       Left            =   570
  62.       TabIndex        =   4
  63.       Top             =   30
  64.       Visible         =   0   'False
  65.       Width           =   120
  66.    End
  67.    Begin VB.Label lblNote 
  68.       Alignment       =   2  'Center
  69.       BackColor       =   &H00000000&
  70.       BackStyle       =   0  'Transparent
  71.       BeginProperty Font 
  72.          Name            =   "Georgia"
  73.          Size            =   9
  74.          Charset         =   0
  75.          Weight          =   700
  76.          Underline       =   0   'False
  77.          Italic          =   -1  'True
  78.          Strikethrough   =   0   'False
  79.       EndProperty
  80.       ForeColor       =   &H00404040&
  81.       Height          =   260
  82.       Index           =   3
  83.       Left            =   435
  84.       TabIndex        =   3
  85.       Top             =   30
  86.       Visible         =   0   'False
  87.       Width           =   120
  88.    End
  89.    Begin VB.Label lblNote 
  90.       Alignment       =   2  'Center
  91.       BackColor       =   &H00000000&
  92.       BackStyle       =   0  'Transparent
  93.       BeginProperty Font 
  94.          Name            =   "Georgia"
  95.          Size            =   9
  96.          Charset         =   0
  97.          Weight          =   700
  98.          Underline       =   0   'False
  99.          Italic          =   -1  'True
  100.          Strikethrough   =   0   'False
  101.       EndProperty
  102.       ForeColor       =   &H00404040&
  103.       Height          =   260
  104.       Index           =   2
  105.       Left            =   300
  106.       TabIndex        =   2
  107.       Top             =   30
  108.       Visible         =   0   'False
  109.       Width           =   120
  110.    End
  111.    Begin VB.Label lblNote 
  112.       Alignment       =   2  'Center
  113.       BackColor       =   &H00000000&
  114.       BackStyle       =   0  'Transparent
  115.       BeginProperty Font 
  116.          Name            =   "Georgia"
  117.          Size            =   9
  118.          Charset         =   0
  119.          Weight          =   700
  120.          Underline       =   0   'False
  121.          Italic          =   -1  'True
  122.          Strikethrough   =   0   'False
  123.       EndProperty
  124.       ForeColor       =   &H00404040&
  125.       Height          =   260
  126.       Index           =   1
  127.       Left            =   165
  128.       TabIndex        =   1
  129.       Top             =   30
  130.       Visible         =   0   'False
  131.       Width           =   120
  132.    End
  133.    Begin VB.Label lblNote 
  134.       Alignment       =   2  'Center
  135.       BackColor       =   &H00000000&
  136.       BackStyle       =   0  'Transparent
  137.       BeginProperty Font 
  138.          Name            =   "Georgia"
  139.          Size            =   9
  140.          Charset         =   0
  141.          Weight          =   700
  142.          Underline       =   0   'False
  143.          Italic          =   -1  'True
  144.          Strikethrough   =   0   'False
  145.       EndProperty
  146.       ForeColor       =   &H00404040&
  147.       Height          =   260
  148.       Index           =   0
  149.       Left            =   30
  150.       TabIndex        =   0
  151.       Top             =   30
  152.       Visible         =   0   'False
  153.       Width           =   120
  154.    End
  155.    Begin VB.Label lblNumber 
  156.       Alignment       =   2  'Center
  157.       BackStyle       =   0  'Transparent
  158.       Caption         =   "8"
  159.       BeginProperty Font 
  160.          Name            =   "Harrington"
  161.          Size            =   27.75
  162.          Charset         =   0
  163.          Weight          =   700
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       ForeColor       =   &H0000FFFF&
  169.       Height          =   685
  170.       Index           =   1
  171.       Left            =   30
  172.       TabIndex        =   6
  173.       Top             =   45
  174.       Width           =   615
  175.    End
  176.    Begin VB.Label lblNumber 
  177.       Alignment       =   2  'Center
  178.       BackStyle       =   0  'Transparent
  179.       Caption         =   "8"
  180.       BeginProperty Font 
  181.          Name            =   "Harrington"
  182.          Size            =   27.75
  183.          Charset         =   0
  184.          Weight          =   700
  185.          Underline       =   0   'False
  186.          Italic          =   0   'False
  187.          Strikethrough   =   0   'False
  188.       EndProperty
  189.       Height          =   685
  190.       Index           =   0
  191.       Left            =   45
  192.       TabIndex        =   5
  193.       Top             =   60
  194.       Width           =   615
  195.    End
  196. End
  197. Attribute VB_Name = "Cell"
  198. Attribute VB_GlobalNameSpace = False
  199. Attribute VB_Creatable = True
  200. Attribute VB_PredeclaredId = False
  201. Attribute VB_Exposed = False
  202. Option Explicit
  203. '*******************************
  204. '* Title  : Cell               *
  205. '* Type   : ActiveX OCX        *
  206. '* Author : Derio              *
  207. '* Stamp  : 31 Dec 2006        *
  208. '* Desc   : UI for Sudoku Cell *
  209. '*******************************
  210.  
  211. Private vCaption As String
  212. Private vNoteIndex As Integer
  213. Private vCurrentNoteIndex As Integer
  214. Private vForeColor As OLE_COLOR
  215. Private vProtectedColor As OLE_COLOR
  216.  
  217. Public AddNoteSuccess As Boolean
  218.  
  219. Public Enum SUDOKU_MODE
  220.   Protected = 0
  221.   LightButton = 1
  222.   DarkButton = 2
  223. End Enum
  224. Private vMode As SUDOKU_MODE
  225.  
  226. Public Event LeftClick()
  227. Public Event RightClick()
  228. Public Event NoteClick(ByVal LastCaption As String, ByVal NoteList As String)
  229. Public Event NoteRemove(ByVal Note As String)
  230. Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  231.  
  232.  
  233. Private Sub lblNote_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  234.  
  235. Dim NoteList As String
  236. Dim LastCaption As String
  237.  
  238.   'protected cell raises nothing
  239.   If vMode = Protected Then Exit Sub
  240.   
  241.   If Button = vbLeftButton Then
  242.     If lblNote(Index).Caption <> "" Then
  243.       
  244.       NoteList = GetNoteList()
  245.       LastCaption = Me.Caption
  246.       Me.Caption = lblNote(Index).Caption
  247.       Me.ClearNote
  248.       RaiseEvent NoteClick(LastCaption, NoteList)
  249.       
  250.     Else
  251.       RaiseEvent LeftClick
  252.     End If
  253.     
  254.   Else
  255.     If lblNote(Index).Caption <> "" Then
  256.       LastCaption = lblNote(Index).Caption
  257.       Me.RemoveNote lblNote(Index).Caption
  258.       RaiseEvent NoteRemove(LastCaption)
  259.     Else
  260.       RaiseEvent RightClick
  261.     End If
  262.   End If
  263. End Sub
  264.  
  265. Private Sub lblNote_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  266.   If vNoteIndex >= 0 Then
  267.     If vCurrentNoteIndex <> Index Then
  268.       If vCurrentNoteIndex <> -1 Then
  269.         With lblNote(vCurrentNoteIndex)
  270.           .ForeColor = RGB(64, 64, 64)
  271.           .BackStyle = 0 'opaque
  272.         End With
  273.       End If
  274.       
  275.       vCurrentNoteIndex = Index
  276.       With lblNote(vCurrentNoteIndex)
  277.         .ForeColor = vbYellow
  278.         .BackStyle = 1 'Opaque
  279.       End With
  280.       If Not tmrHiLight.Enabled Then tmrHiLight.Enabled = True
  281.     End If
  282.   End If
  283. End Sub
  284.  
  285. Private Sub lblNumber_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  286.   'protected cell raises nothing
  287.   If vMode = Protected Then Exit Sub
  288.   
  289.   If Button = vbLeftButton Then
  290.     RaiseEvent LeftClick
  291.   Else
  292.     RaiseEvent RightClick
  293.   End If
  294. End Sub
  295.  
  296. Private Sub lblNumber_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  297.   'protected cell raises nothing
  298.   If vMode = Protected Then Exit Sub
  299.   
  300.   RaiseEvent MouseMove(Button, Shift, X, Y)
  301. End Sub
  302.  
  303. Private Sub tmrHiLight_Timer()
  304. Dim Cur As POINT
  305.  
  306.   GetCursorPos Cur
  307.   Cur.X = Cur.X - (Extender.Parent.Left + (Extender.Parent.Width - Extender.Parent.ScaleWidth) / 2) \ Screen.TwipsPerPixelX
  308.   Cur.Y = Cur.Y - (Extender.Parent.Top + Extender.Parent.Height - Extender.Parent.ScaleHeight - 30) \ Screen.TwipsPerPixelY
  309.   
  310.   Cur.X = Cur.X * Screen.TwipsPerPixelX - Extender.Left
  311.   Cur.Y = Cur.Y * Screen.TwipsPerPixelY - Extender.Top
  312.   If Not (Cur.X >= lblNote(vCurrentNoteIndex).Left _
  313.           And Cur.X <= lblNote(vCurrentNoteIndex).Left + lblNote(vCurrentNoteIndex).Width _
  314.           And Cur.Y >= lblNote(vCurrentNoteIndex).Top _
  315.           And Cur.Y <= lblNote(vCurrentNoteIndex).Top + lblNote(vCurrentNoteIndex).Height) Then
  316.     tmrHiLight.Enabled = False
  317.     With lblNote(vCurrentNoteIndex)
  318.       .ForeColor = RGB(64, 64, 64)
  319.       .BackStyle = 0
  320.     End With
  321.     
  322.     vCurrentNoteIndex = -1
  323.   End If
  324. End Sub
  325.  
  326. Private Sub UserControl_Initialize()
  327.   vNoteIndex = -1 'no note
  328.   vCurrentNoteIndex = -1 'no selected note
  329.   vProtectedColor = RGB(8 * 16, 4 * 16, 0)
  330.   vForeColor = RGB(255, 255, 0)
  331. End Sub
  332.  
  333. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  334.   'protected cell raises nothing
  335.   If vMode = Protected Then Exit Sub
  336.   
  337.   RaiseEvent MouseMove(Button, Shift, X, Y)
  338. End Sub
  339.  
  340. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  341.   Caption = PropBag.ReadProperty("Caption", "")
  342.   Mode = PropBag.ReadProperty("Mode", SUDOKU_MODE.Protected)
  343.   ForeColor = PropBag.ReadProperty("ForeColor", vbBlack)
  344.   ProtectedColor = PropBag.ReadProperty("ProtectedColor", vbBlack)
  345. End Sub
  346.  
  347. Private Sub UserControl_Resize()
  348.   UserControl.Width = Screen.TwipsPerPixelX * 48
  349.   UserControl.Height = Screen.TwipsPerPixelY * 48
  350. End Sub
  351.  
  352. Public Property Get Caption() As String
  353. Attribute Caption.VB_UserMemId = 0
  354.   Caption = vCaption
  355. End Property
  356.  
  357. Public Property Let Caption(ByVal vNewValue As String)
  358.   vCaption = vNewValue
  359.   UserControl.lblNumber(0).Caption = vCaption
  360.   UserControl.lblNumber(1).Caption = vCaption
  361.   Me.ClearNote
  362.   PropertyChanged "Caption"
  363. End Property
  364.  
  365. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  366.   PropBag.WriteProperty "Caption", vCaption
  367.   PropBag.WriteProperty "Mode", vMode
  368.   PropBag.WriteProperty "ForeColor", vForeColor
  369.   PropBag.WriteProperty "ProtectedColor", vProtectedColor
  370. End Sub
  371.  
  372. Public Sub AddNote(MyNote As String)
  373. '** Add note to Sudoku Cell
  374.  
  375. Dim I As Integer
  376. Dim J As Integer
  377. Dim strTemp As String
  378.  
  379.   AddNoteSuccess = False
  380.   
  381.   'check note capacity
  382.   If vNoteIndex = UserControl.lblNote.Count - 1 Then Exit Sub
  383.   
  384.   'check validitas
  385.   If InStr("123456789", MyNote) = 0 Then Exit Sub
  386.   
  387.   'check if number exist
  388.   If Me.Caption <> "" Then
  389.     strTemp = Me.Caption
  390.     Me.Caption = ""
  391.     Me.AddNote strTemp
  392.   End If
  393.   
  394.   'check if the same note exist
  395.   For I = 0 To vNoteIndex
  396.     If UserControl.lblNote(I).Caption = MyNote Then
  397.       Exit Sub
  398.     End If
  399.   Next I
  400.   
  401.   'check note possition
  402.   For I = 0 To vNoteIndex
  403.     If UserControl.lblNote(I).Caption > MyNote Then
  404.     
  405.       'insert new note if the number smaller than other
  406.       For J = vNoteIndex To I Step -1
  407.         UserControl.lblNote(J + 1).Caption = UserControl.lblNote(J).Caption
  408.         UserControl.lblNote(J + 1).Visible = True
  409.       Next J
  410.       
  411.       Exit For
  412.     End If
  413.   Next I
  414.   
  415.   'insert note
  416.   UserControl.lblNote(I).Caption = MyNote
  417.   UserControl.lblNote(I).Visible = True
  418.   vNoteIndex = vNoteIndex + 1
  419.   AddNoteSuccess = True
  420. End Sub
  421.  
  422. Public Sub RemoveNote(ByVal Note As String)
  423. '** Remove note form Sudoku Cell
  424.  
  425. Dim I As Integer
  426. Dim J As Integer
  427.  
  428.   For I = 0 To vNoteIndex
  429.     If UserControl.lblNote(I).Caption = Note Then
  430.       For J = I To vNoteIndex - 1
  431.         UserControl.lblNote(J).Caption = UserControl.lblNote(J + 1).Caption
  432.       Next J
  433.       UserControl.lblNote(vNoteIndex).Caption = ""
  434.       UserControl.lblNote(vNoteIndex).Visible = False
  435.       vNoteIndex = vNoteIndex - 1
  436.       Exit For
  437.     End If
  438.   Next I
  439. End Sub
  440.  
  441. Public Sub ClearNote()
  442. '** Clear entire note from Sudoku Cell
  443.  
  444. Dim I As Integer
  445.  
  446.   For I = 0 To vNoteIndex
  447.     UserControl.lblNote(I).Caption = ""
  448.     UserControl.lblNote(I).Visible = False
  449.   Next I
  450.   vNoteIndex = -1
  451. End Sub
  452.  
  453. Public Property Get Mode() As SUDOKU_MODE
  454.   Mode = vMode
  455. End Property
  456.  
  457. Public Property Let Mode(ByVal vNewValue As SUDOKU_MODE)
  458.   vMode = vNewValue
  459.   Select Case vMode
  460.   Case SUDOKU_MODE.Protected
  461.     UserControl.Picture = UserControl.imgLib(0).Picture
  462.     UserControl.lblNumber(1).ForeColor = vProtectedColor
  463.     If UserControl.lblNumber(0).Visible Then UserControl.lblNumber(0).Visible = False
  464.   
  465.   Case SUDOKU_MODE.LightButton
  466.     UserControl.Picture = UserControl.imgLib(1).Picture
  467.     UserControl.lblNumber(1).ForeColor = vForeColor
  468.     If Not UserControl.lblNumber(0).Visible Then UserControl.lblNumber(0).Visible = True
  469.   
  470.   Case SUDOKU_MODE.DarkButton
  471.     UserControl.Picture = UserControl.imgLib(2).Picture
  472.     UserControl.lblNumber(1).ForeColor = vForeColor
  473.     If Not UserControl.lblNumber(0).Visible Then UserControl.lblNumber(0).Visible = True
  474.   End Select
  475.   
  476.   PropertyChanged "Mode"
  477. End Property
  478.  
  479. Public Property Get ForeColor() As OLE_COLOR
  480.   ForeColor = vForeColor
  481. End Property
  482.  
  483. Public Property Let ForeColor(ByVal vNewValue As OLE_COLOR)
  484.   vForeColor = vNewValue
  485.   
  486.   If Me.Mode <> Protected Then
  487.     UserControl.lblNumber(1).ForeColor = vNewValue
  488.   End If
  489.   
  490.   PropertyChanged "ForeColor"
  491. End Property
  492.  
  493. Public Property Get ProtectedColor() As OLE_COLOR
  494.   ProtectedColor = vProtectedColor
  495. End Property
  496.  
  497. Public Property Let ProtectedColor(ByVal vNewValue As OLE_COLOR)
  498.   vProtectedColor = vNewValue
  499.   If Me.Mode = Protected Then
  500.     UserControl.lblNumber(1).ForeColor = vProtectedColor
  501.   End If
  502.   
  503.   PropertyChanged "ProtectedColor"
  504. End Property
  505.  
  506. Public Function GetNoteList() As String
  507. Dim I As Integer
  508. Dim NoteList As String
  509.  
  510.   For I = 0 To vNoteIndex
  511.     NoteList = NoteList & UserControl.lblNote(I)
  512.   Next I
  513.   GetNoteList = NoteList
  514. End Function
  515.