コード例 #1
0
ファイル: ImageList.xaml.cs プロジェクト: HaiqTop/HWallpaper
        /// <summary>
        /// 壁纸上动态显示的按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn == null)
            {
                return;
            }
            ImgInfo imgInfo;

            if ((btn.Parent as StackPanel).Tag is ImgInfo info)
            {
                imgInfo = info;
            }
            else
            {
                imgInfo = this.GetimgInfo((btn.Parent as StackPanel).Tag);
            }
            switch (btn.Name)
            {
            case "btn_down":
            {
                if (btn.Foreground == Brushes.White)
                {
                    btn.IsEnabled = false;
                    string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName());
                    if (!System.IO.File.Exists(imgFullName))
                    {
                        System.Drawing.Image img = WebHelper.GetImage(imgInfo.url);
                        img.Save(imgFullName);
                        img.Dispose();
                    }
                    btn.Foreground = Brushes.Red;
                    btn.IsEnabled  = true;
                    Growl.Success("下载成功。");
                    UserDataManage.SetDown(imgFullName, imgInfo);
                    if (btn_love.Foreground == Brushes.White)
                    {
                        UserDataManage.SetLove(LoveType.Love, imgInfo);
                        btn_love.Foreground    = Brushes.Red;
                        btn_dislike.Foreground = Brushes.White;
                    }
                }
            }
            break;

            case "btn_wallpaper":
            {
                if (btn.Foreground == Brushes.White)
                {
                    btn.IsEnabled = false;
                    string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName());
                    if (!System.IO.File.Exists(imgFullName))
                    {
                        System.Drawing.Image img = WebHelper.GetImage(imgInfo.url);
                        img.Save(imgFullName);
                        img.Dispose();
                    }
                    if (System.IO.File.Exists(imgFullName))
                    {
                        WinApi.SetWallpaper(imgFullName);
                        btn.Foreground = Brushes.Red;
                        Growl.Success("壁纸设置成功。");
                        btn.IsEnabled = true;
                        UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo);
                    }
                    else
                    {
                        Growl.Error("未找到壁纸文件,壁纸设置失败。");
                    }
                }
            }
            break;

            case "btn_love":
            {
                if (btn.Foreground == Brushes.White)
                {
                    UserDataManage.SetLove(LoveType.Love, imgInfo);
                    btn.Foreground         = Brushes.Red;
                    btn_dislike.Foreground = Brushes.White;
                }
            }
            break;

            case "btn_dislike":
            {
                if (btn.Foreground == Brushes.White)
                {
                    UserDataManage.SetLove(LoveType.Dislike, imgInfo);
                    btn.Foreground      = Brushes.Red;
                    btn_love.Foreground = Brushes.White;
                }
            }
            break;
            }
        }
コード例 #2
0
        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn == null)
            {
                return;
            }
            ImgInfo imgInfo = (btn.Parent as StackPanel).Tag as ImgInfo;

            switch (btn.Name)
            {
            case "btn_down":
            {
                if (btn.Foreground == Brushes.White)
                {
                    string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName());
                    if (!System.IO.File.Exists(imgFullName))
                    {
                        System.Drawing.Image img = WebHelper.GetImage(imgInfo.url);
                        img.Save(imgFullName);
                        img.Dispose();
                    }
                    btn.Foreground = Brushes.Red;
                    UserDataManage.SetDown(imgFullName, imgInfo);
                    Growl.Success("下载成功。");

                    if (btn_love.Foreground == Brushes.White)
                    {
                        UserDataManage.SetLove(LoveType.Love, imgInfo);
                        btn_love.Foreground    = Brushes.Red;
                        btn_dislike.Foreground = Brushes.White;
                    }
                }
            }
            break;

            case "btn_wallpaper":
            {
                if (btn.Foreground == Brushes.White)
                {
                    string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName());
                    if (!System.IO.File.Exists(imgFullName))
                    {
                        System.Drawing.Image img = WebHelper.GetImage(imgInfo.url);
                        img.Save(imgFullName);
                        img.Dispose();
                    }
                    WinApi.SetWallpaper(imgFullName);
                    btn.Foreground = Brushes.Red;
                    Growl.Success("壁纸设置成功。");
                    UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo);
                }
            }
            break;

            case "btn_love":
            {
                if (btn.Foreground == Brushes.White)
                {
                    UserDataManage.SetLove(LoveType.Love, imgInfo);
                    btn.Foreground         = Brushes.Red;
                    btn_dislike.Foreground = Brushes.White;
                }
            }
            break;

            case "btn_dislike":
            {
                if (btn.Foreground == Brushes.White)
                {
                    UserDataManage.SetLove(LoveType.Dislike, imgInfo);
                    btn.Foreground      = Brushes.Red;
                    btn_love.Foreground = Brushes.White;
                    this.EffectPicture(null, null);
                }
            }
            break;
            }
        }