'''
''' Specifies the format the temp should be returned in
'''
Public Enum TempFormat
Fahrenheit
Celsius
Kelvin
'''
''' The CPU temp will be returned in it's raw, uncalculated format
'''
Raw
End Enum
'''
''' Gets the current temp of the CPU
'''
'''
The temp scale the value should be returned in
Public Function GetCPUTemp(ByVal Format As TempFormat) As Single
Dim enumerator As System.Management.ManagementObjectCollection.ManagementObjectEnumerator
Dim searcher As New System.Management.ManagementObjectSearcher("root\WMI", "SELECT * FROM MSAcpi_ThermalZoneTemperature")
enumerator = searcher.Get.GetEnumerator()
While enumerator.MoveNext
Dim obj As System.Management.ManagementObject = CType(enumerator.Current, System.Management.ManagementObject)
Select Case format
Case TempFormat.Fahrenheit
Return CSng((obj.Item("CurrentTemperature") / 10 - 273.15) * 9 / 5 + 32)
Case TempFormat.Celsius
Return CSng(obj.Item("CurrentTemperature") / 10 - 273.15)
Case TempFormat.Kelvin
Return CSng(obj.Item("CurrentTemperature") / 10)
Case TempFormat.Raw
Return CSng(obj.Item("CurrentTemperature"))
End Select
End While
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'I have used Button1 as a reference as to where I want the label to appear
animateText("You have gained 5 points", Button1.Location.Y - 20, Button1.Location.Y - 50, Button1.Location.X)
End Sub
Dim blah As New Label 'Makes a new label
Dim maxHeight As Integer
Dim colour As Integer = 255 'This will be used for fading the text from white to black
Public Sub animateText(ByVal text As String, ByVal lowerBounds As Integer, ByVal upperBounds As Integer, ByVal xPos As Integer)
'lowerbounds = where the label gets created
'upperbounds = where the label dissapears
maxHeight = upperBounds 'The variable maxHeight is used in the timer event to tell it where to dissapear, so I populate it using the sub
blah.Text = text
blah.TextAlign = ContentAlignment.MiddleCenter
blah.Location = New Point(xPos, lowerBounds)
blah.Font = New Font(Font.Bold, 20) 'Feel free to customize the font size
blah.AutoSize = True
Me.Controls.Add(blah)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
blah.Location = New Point(blah.Location.X, blah.Location.Y - 1)
blah.ForeColor = Color.FromArgb(colour, colour, colour) 'The variable colour starts out with 255(means label is White) and then slowly decreases to 0(means label is Black)
colour -= 7 'I didn't have time, but I'm sure there is a MUCH more suitable value for this variable
If colour <= 10 Then 'This is just used to prevent 'colour' being less than 0
colour = 10
End If
If blah.Location.Y = maxHeight Then 'Makes the label dissapear
Timer1.Enabled = False
Me.Controls.Remove(blah)
colour = 255
End If
End Sub