Пример #1
0
        private async void WallpaperStoryForm_Load(object sender, EventArgs e)
        {
            if (image != null)
            {
                this.lblDate.Text     = image.Date;
                this.lblDesc.Text     = image.Description;
                this.lblLocation.Text = image.Locate;
                this.Text             = image.Title;
                this.lblTitle.Text    = image.Title;

                var img = await image.getImage();

                pictureBox1.Image = img;
            }
        }
Пример #2
0
        async void LoadImageAsync()
        {
            if (image != null)
            {
                this.lblDate.Text     = image.Date;
                this.lblDesc.Text     = image.Description;
                this.lblLocation.Text = image.Locate;
                this.Text             = image.Title;
                this.lblTitle.Text    = image.Title;

                try
                {
                    var img = await image.getImage();

                    pictureBox1.Image = img;
                }
                catch
                {
                    pictureBox1.Image = Properties.Resources.error;
                }
            }
        }
Пример #3
0
        public void AddTrayIcons()
        {
            // Create a simple tray menu with only one item.
            _trayMenu = new ContextMenu();

            // Copyright button
            _copyrightLabel        = new MenuItem("Bing每日壁纸");
            _copyrightLabel.Click += (s, e) =>
            {
                //var url = ((MenuItem)s).Tag.ToString();
                //if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                //    System.Diagnostics.Process.Start(url);
            };
            _trayMenu.MenuItems.Add(_copyrightLabel);

            _trayMenu.MenuItems.Add("-");

            _trayMenu.MenuItems.Add("壁纸故事", (s, e) =>
            {
                new WallpaperStoryForm(_currentWallpaper).ShowDialog();
            });

            _trayMenu.MenuItems.Add("强制更新", (s, e) => SetWallpaper());

            _trayMenu.MenuItems.Add("随机切换", (s, e) => SetRandomWallpaper());

            // Save image button
            var save = new MenuItem("保存壁纸");

            save.Click += async(s, e) =>
            {
                if (_currentWallpaper != null)
                {
                    var fileName = string.Join("_", _settings.ImageCopyright.Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
                    var dialog   = new SaveFileDialog
                    {
                        DefaultExt = "jpg",
                        Title      = "保存当前壁纸",
                        FileName   = fileName,
                        Filter     = "Jpeg Image|*.jpg",
                    };
                    if (dialog.ShowDialog() == DialogResult.OK && dialog.FileName != "")
                    {
                        var image = await _currentWallpaper.getImage();

                        image.Save(dialog.FileName, ImageFormat.Jpeg);
                        System.Diagnostics.Process.Start(dialog.FileName);
                    }
                }
            };
            _trayMenu.MenuItems.Add(save);

            // Separator,下面显示设置
            _trayMenu.MenuItems.Add("-");

            var launch = new MenuItem("开机启动");

            launch.Checked = _settings.LaunchOnStartup;
            launch.Click  += OnStartupLaunch;
            _trayMenu.MenuItems.Add(launch);


            var timerChange = new MenuItem("定时切换");

            timerChange.Checked = _settings.AutoChange;
            timerChange.Click  += OnAutoChange;
            _trayMenu.MenuItems.Add(timerChange);

            // Separator
            _trayMenu.MenuItems.Add("-");

            _trayMenu.MenuItems.Add("退出", (s, e) => Application.Exit());

            _trayIcon      = new NotifyIcon();
            _trayIcon.Text = "Bing每日壁纸";
            //_trayIcon.Icon = new Icon("Resources/bing-icon.ico", 40, 40);
            _trayIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);

            // open tray icon on left click
            _trayIcon.MouseUp += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                    mi.Invoke(_trayIcon, null);
                }
            };

            // Add menu to tray icon and show it.
            _trayIcon.ContextMenu = _trayMenu;
            _trayIcon.Visible     = true;
        }