VB.NET GDI+ 天气预报

最近闲来无事,想起天气预报那个工具很不好用,所以想自己做一个。

于是顺便体验下WPF的魅力,就用WPF开始动工了。进度很快,技术上不是很难摸,

一天吧就完成了决大部分主要功能 。其实就是一个显示界面加城市选择设置部分。

这里也大概贴一下代码

    Private Sub MainWindow_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
        Me.DragMove()

    End Sub
    Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

        'Dim desktopHwnd As IntPtr = GetDesktopPtr()
        'Dim ownHwnd As IntPtr = New WindowInteropHelper(Me).Handle
        'Dim result As IntPtr = SetParent(ownHwnd, desktopHwnd)
      
        Dim address As String = ""
        address = GetAddress()

        'Dim weather() As String = ws.getWeatherbyCityName(address)
        'LoadData(weather)
    End Sub
    Function LoadData(ByVal weather() As String) As Boolean
        Try

            Dim Today_ImageStream, Tomorrow_ImageStream, AfterTomorrow_ImageStream As FileStream
            Dim Today_Image, Tomorrow_Image, AfterTomorrow_Image As New BitmapImage()
            Dim gifLen As Integer
            Dim gifName As String
            Dim filePath As String

            'today
            lblTime.Content = Now.Year & "年" & Now.Month & "月" & Now.Day & "日             星期" & ConvertToChinese(Now.DayOfWeek)
            lblAddress.Content = weather(1).ToString
            Dim len As Integer = weather(10).ToString.IndexOf("℃") - 9
            lblNow.Content = weather(10).ToString.Substring(10, len)
            lblWind.Content = weather(6).ToString.Substring(weather(6).ToString.IndexOf(" "))

            gifLen = weather(9).ToString.Length
            If gifLen = 5 Then
                gifName = "0" & weather(9).ToString.Replace("gif", "png")
            Else
                gifName = weather(9).ToString.Replace("gif", "png")
            End If

            filePath = path & "images\"
            Today_ImageStream = New FileStream(filePath & gifName, FileMode.Open)
            Today_Image.BeginInit()
            Today_Image.StreamSource = Today_ImageStream
            Today_Image.EndInit()
            ImgNow.Source = Today_Image

            lblTodayTemp.Content = weather(5).ToString.Replace("/", "--")
            ImgToday.Source = Today_Image
            lblToday.Content = weather(6).ToString.Substring(0, weather(6).ToString.IndexOf(" "))

            'tomorrow
            If weather(9).ToString = weather(16).ToString Then
                ImgTomo.Source = Today_Image
            Else

                gifLen = weather(16).ToString.Length
                If gifLen = 5 Then
                    gifName = "0" & weather(16).ToString.Replace("gif", "png")
                Else
                    gifName = weather(16).ToString.Replace("gif", "png")
                End If
                Tomorrow_Image = New BitmapImage()
                Tomorrow_ImageStream = New FileStream(filePath & gifName, FileMode.Open)
                Tomorrow_Image.BeginInit()
                Tomorrow_Image.StreamSource = Tomorrow_ImageStream
                Tomorrow_Image.EndInit()
                ImgTomo.Source = Tomorrow_I
  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值