打印本文 打印本文 关闭窗口 关闭窗口
Skinning Your Application
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1817  更新时间:2009/4/23 16:38:10  文章录入:mintao  责任编辑:mintao
e inputs to load all of the configuration information.


Note   There are several points in the LoadCoordinates routine where I simply read a line into a variable called strJunk and never do anything further with that line. These correspond to the comments that are embedded into each configuration file.
Sub LoadCoordinates()
Dim intDay As Integer
Dim intLocs As Integer
Dim strJunk As String

'''' Open the configuration file for the current skin.
ceFile.Open App.Path & "\" & strCurrentSkin & ".cfg", fsModeInput, fsAccessRead

'''' Load the heading location.
strJunk = ceFile.LineInputString
intDateLocX = ceFile.LineInputString
intDateLocY = ceFile.LineInputString

'''' Load the item location.
strJunk = ceFile.LineInputString
intAppointmentLocX = ceFile.LineInputString
intAppointmentLocY = ceFile.LineInputString

'''' Load the button locations.
For intDay = 1 To 7
strJunk = ceFile.LineInputString
For intLocs = 1 To 4
intButtons(intDay, intLocs) = CInt(ceFile.LineInputString)
Next intLocs
Next intDay

'''' Load text colors.
strJunk = ceFile.LineInputString
lngTitleColor = ceFile.LineInputString
strJunk = ceFile.LineInputString
lngItemColor = ceFile.LineInputString

'''' Clean up.
ceFile.Close

End Sub

Displaying Appointments for a Given Day


I won''''t dwell much on this section of the Skin Demo application as it mostly handles the displaying of hard-coded content. There are some key points to discuss though. First, the Skin Demo uses the Picture Box control''''s DrawText method to display individual items. This allows us to control exactly where on the skin the content is displayed. Second, the Picture Box control''''s Cls method is used to clear off any previous content that may be displayed before adding new content.

Sub DisplayAppointments()
'''' This routine displays the appointments for the selected date.
Dim strDayOfWeek As String

'''' Clear off previous appointment information.
picSkin.Cls

'''' Display the present date.
picSkin.FontBold = True
picSkin.ForeColor = lngTitleColor
Select Case DatePart("w", datCurrent)
Case 1:
strDayOfWeek = "Sunday"
Case 2:
strDayOfWeek = "Monday"
Case 3:
strDayOfWeek = "Tuesday"
Case 4:
strDayOfWeek = "Wednesday"
Case 5:
strDayOfWeek = "Thursday"
Case 6:
strDayOfWeek = "Friday"
Case 7:
strDayOfWeek = "Saturday"
End Select
picSkin.DrawText strDayOfWeek & ", " & MonthName(Month(datCurrent)) & " " & _
Day(datCurrent) & " " & Year(datCurrent), intDateLocX, intDateLocY

'''' Display the appointments for this date.
'''' NOTE: These are hard-coded just for the purpose of this demo.
picSkin.FontBold = False
picSkin.ForeColor = lngItemColor
Select Case strDayOfWeek
Case "Sunday"
picSkin.DrawText "no appointments today", intAppointmentLocX, intAppointmentLocY
Case "Monday"
picSkin.DrawText "08:00 drop car off", intAppointmentLocX, intAppointmentLocY
Case "Tuesday"
picSkin.DrawText "10:00 status meeting", intAppointmentLocX, intAppointmentLocY
picSkin.DrawText "13:00 presentation to management", _
intAppointmentLocX, intAppointmentLocY + 200
Case "Wednesday"
picSkin.DrawText "09:30 conference call", intAppointmentLocX, intAppointmentLocY
picSkin.DrawText "11:00 interview", intAppointmentLocX, intAppointmentLocY + 200
picSkin.DrawText "14:00 product meeting", intAppointmentLocX, intAppointmentLocY + 400
picSkin.DrawText "15:30 doctor appointment", intAppointmentLocX,_
intAppointmentLocY + 600
Case "Thursday"
picSkin.DrawText "10:00 project meeting", intAppointmentLocX, intAppointmentLocY
picSkin.DrawText "14:00 presentation to management", _
intAppointmentLocX, intAppointmentLocY + 200
Case "Friday"
picSkin.DrawText "12:00 lunch with Lauren", intAppointmentLocX, intAppointmentLocY
Case "Saturday"
picSkin.DrawText "10:00 soccer game", intAppointmentLocX, intAppointmentLocY
End Select

End Sub

Changing Skins


When the user selects a new skin from the menu, the new skin is implemented using the following small bit of code. The name of the skin is passed as an argument to the event procedure. This makes it extremely simple to switch to a new skin.

Private Sub ceMenuBar_MenuClick(ByVal Item As MenuBarLib.Item)

'''' Change the skin.
strCurrentSkin = Item.Caption
picSkin.Picture = App.Path & "\" & strCurrentSkin & ".bmp"
LoadCoordinates
DisplayAppointments

End Sub

Handling Button Taps


All that is left is handling user taps on a button. This is handled through the MouseDown event of the Picture Box control. The essence behind this routine is to take the location that the user tapped, and compare it against the coordinates for each of the buttons on a skin. If a match is found, the appointments for the selected day are displayed.

Private Sub picSkin_MouseDown(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Double, ByVal y As Double)
Dim intCounter As Integer

'''' Uncomment this line to help debug your button locations.
'''' MsgBox "X:" & x & " Y:" & y

'''' Check to see if the user tapped a button.
For intCounter = 1 To 7
If (x >= intButtons(intCounter, 1)) Then
If (y >= intButtons(intCounter, 2)) Then
If (x <= intButtons(intCounter, 3)) Then
If (y <= intButtons(intCounter, 4)) Then
datCurrent = datWeek(intCounter)
DisplayAppointments
End If
End If
End If
End If
Next intCounter

End Sub

Summary of Skinning Your Application


That''''s it, everything that you need to skin-enable your eMbedded Visual Basic applications. The process of creating the skins and the configuration files take a bit of work, but the result is, well, for lack of a better word, just plain cool. Remember, if you are going to have other controls as part of your interface, you have to set the ZOrder property so that they sit on top of the Picture Box control.


Back on the Road


That''''s it for this month. I''''m going to go stare out my window at the ocean. However, from several thousand miles away, I''''ll have a hard time making out details. Until next month, I''''m back on the road.

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口