示例#1
0
        private void ReadIcons()
        {
            if (string.IsNullOrEmpty(txtFile.Text))
            {
                return;
            }
            Icon[] icons = IconHandler.IconsFromFile(txtFile.Text, IconSize.Large);
            Label  lab   = null;

            panIcons.Controls.Clear();
            if (icons != null && icons.Length != 0)
            {
                if (this.SelectedIndex == -1)
                {
                    this.SelectedIndex = 0;
                }
                int h = 0;
                int w = 0;
                foreach (Icon icon in icons)
                {
                    h = Math.Max(icon.Height, h);
                    w = Math.Max(icon.Width, w);
                }
                foreach (Icon icon in icons)
                {
                    lab      = new Label();
                    lab.Name = "Icon_" + panIcons.Controls.Count.ToString();
                    //lab.BorderStyle = BorderStyle.FixedSingle;
                    lab.Size         = new Size(w + 10, h + 10);
                    lab.Margin       = new Padding(3);
                    lab.ImageAlign   = ContentAlignment.MiddleCenter;
                    lab.Image        = icon.ToBitmap();
                    lab.TabIndex     = panIcons.Controls.Count;
                    lab.Click       += new EventHandler(Icon_Click);
                    lab.DoubleClick += new EventHandler(Icon_DoubleClick);
                    panIcons.Controls.Add(lab);
                }
                panIcons.Controls["Icon_" + this.SelectedIndex.ToString()].BackColor = SystemColors.Highlight;
            }
        }
示例#2
0
        private void ShowGameList(MenuInfo mi)
        {
            panRight.Hide();
            Application.DoEvents();
            labClass.Text = mi.Name;
            panGame.Controls.Clear();
            Application.DoEvents();
            LinkLabel lnk = new LinkLabel();

            lnk.Name     = "lnkGame";
            lnk.Location = new Point(0, -100);
            lnk.Text     = "None";
            panGame.Controls.Add(lnk);
            GameButton      gb  = null;
            List <GameInfo> lgi = Program.Games.FindAll(gi => gi.MenuID.Equals(mi.ID, StringComparison.OrdinalIgnoreCase));

            lgi.Sort((g1, g2) => g1.Sort.CompareTo(g2.Sort));
            foreach (GameInfo gi in lgi)
            {
                gb             = new GameButton();
                gb.Text        = gi.Name;
                gb.Name        = string.Format("gb_{0}", gi.ID.Replace(" ", "_"));
                gb.MouseEnter += new EventHandler(MenuItem_MouseEnter);
                gb.Font        = _MenuFont;
                gb.ForeColor   = _MenuTextColor;
                gb.BackColor   = _MenuBackColor;
                gb.Click      += new EventHandler(GameButton_Click);
                gb.Dock        = DockStyle.Top;
                gb.Height      = _GameItemHeight;
                gb.Tag         = gi.ID;

                #region 處理圖示
                if (!string.IsNullOrEmpty(gi.Icon))
                {
                    string iconPath  = string.Empty;
                    int    iconIndex = 0;
                    if (gi.Icon.IndexOf(',') != -1)
                    {
                        string[] sp = gi.Icon.Split(',');
                        iconPath = sp[0];
                        int.TryParse(sp[1], out iconIndex);
                    }
                    else
                    {
                        iconPath = gi.Icon;
                    }
                    //iconPath = iconPath.Replace("%Game%", gi.Path);
                    if (!Path.IsPathRooted(iconPath))
                    {
                        iconPath = Path.Combine(_IconPath, iconPath);
                    }
                    Image img = null;
                    if (File.Exists(iconPath))
                    {
                        string[] mime = GameInfo.MimeType(iconPath).ToLower().Split('/');

                        switch (mime[0])
                        {
                        case "application":
                        {
                            Icon[] icons = IconHandler.IconsFromFile(iconPath, IconSize.Large);
                            if (icons != null && icons.Length != 0)
                            {
                                if (icons.Length <= iconIndex)
                                {
                                    img = icons[0].ToBitmap();
                                }
                                else
                                {
                                    img = icons[iconIndex].ToBitmap();
                                }
                            }
                            break;
                        }

                        case "image":
                        {
                            switch (mime[1])
                            {
                            case "x-icon":
                            {
                                Size s = Size.Empty;
                                if (_IconAreaWidth > gb.Height)
                                {
                                    s = new Size(gb.Height, gb.Height);
                                }
                                else
                                {
                                    s = new Size(_IconAreaWidth, _IconAreaWidth);
                                }
                                img = new Icon(iconPath, s).ToBitmap();
                                break;
                            }

                            default:
                                img = Image.FromFile(iconPath);
                                break;
                            }
                            break;
                        }
                        }
                    }
                    if (img != null)
                    {
                        gb.IconWidth = _IconAreaWidth;
                        gb.Icon      = img;
                        gb.ShowIcon  = true;
                    }
                }
                #endregion

                #region 處理上/下傳按鍵
                gb.ShowSaveButton = gi.HasSave;
                if (gi.HasSave)
                {
                    gb.UploadButtonText      = "上傳進度";
                    gb.UploadButtonFont      = new Font("新細明體", 9);
                    gb.UploadButtonImage     = global::SaveCopier.Properties.Resources.Previous;
                    gb.UploadButtonEnabled   = !string.IsNullOrEmpty(_LoginedUserID);
                    gb.UploadClick          += new EventHandler(GameButton_UploadClick);
                    gb.DownloadButtonText    = "下載進度";
                    gb.DownloadButtonFont    = new Font("新細明體", 9);
                    gb.DownloadButtonImage   = global::SaveCopier.Properties.Resources.Next;
                    gb.DownloadButtonEnabled = !string.IsNullOrEmpty(_LoginedUserID);
                    gb.DownloadClick        += new EventHandler(GameButton_DownloadClick);
                    gb.SaveButtonWidth       = _SaveButtonWidth;
                }
                #endregion

                panGame.Controls.Add(gb);
                gb.BringToFront();
                Application.DoEvents();
            }
            panRight.Show();
            Application.DoEvents();
            panGame.Focus();
        }