public GameViewTestForm() { InitializeComponent(); //add Object game vào list gameobject GameObjects.Add(game1); GameObjects.Add(game2); //position này sẽ giúp các GamePreview không bị chồng lên nhau Point position = new Point(0, 0); //vòng lặp add GamePreview foreach (object[] a in GameObjects) { GamePreview temp = new GamePreview(); temp.GameNameText = a[0].ToString(); temp.GamePriceText = a[1].ToString(); //lấy object hình từ resource với tên là thuộc tính thứ 3 của game object, tên phải chính xác //và không có .png, .jpg.v.v... Object bmp = new Object(); bmp = Properties.Resources.ResourceManager.GetObject(a[2].ToString()); temp.GameIcon = (Bitmap)bmp; temp.Location = position; SetDefaultFormat(temp); this.Controls.Add(temp); position = new Point(0, temp.Height); } }
//3 event nay se hien thi chi tiet game khi nguoi choi nhan vao cac phan tu tuong ung' cua gamepreview //do object la khac nhau, nen phai co 3 event xu ly khac nhau, tranh loi public void GamePreviewClick(object sender, EventArgs e) { setStorepanelVisible(false); setGameDetailpanelVisible(true); GamePreview gPre = (GamePreview)sender; currGame = gPre.GetGameObject(); LoadGamePanel(currGame); }
public void GamePreviewDescriptonClick(object sender, EventArgs e) { setStorepanelVisible(false); setGameDetailpanelVisible(true); RichTextBox picbox = (RichTextBox)sender; GamePreview gPre = (GamePreview)picbox.Parent; currGame = gPre.GetGameObject(); LoadGamePanel(currGame); }
public void GamePreviewPicClick(object sender, EventArgs e) { setStorepanelVisible(false); setGameDetailpanelVisible(true); PictureBox picbox = (PictureBox)sender; GamePreview gPre = (GamePreview)picbox.Parent; currGame = gPre.GetGameObject(); LoadGamePanel(currGame); }
public void LoadGamePreview() { int i = 0; int lastY = 0; foreach (GameObject gO in lib_game) { GamePreview temp = new GamePreview(); temp.SetGameObject(gO); temp.GameIcon = gO.Logo.Image; temp.GameNameText = gO.Name; temp.Rating = gO.Rating.ToString(); temp.GameDescription.Text = gO.Content; temp.Click += GamePreviewClick; temp.GamePictureBox.Click += GamePreviewPicClick; //thai.caodu them event khi click cho picture cua game se thuc hien thao tac tuong tu nhu khi click vao control temp.GameDescription.Click += GamePreviewDescriptonClick; temp.Name = gO.Name; if (gO.Price == 0) { temp.GamePriceText = "Free"; } else { temp.GamePriceText = gO.Price.ToString() + " VND"; } if (i == 0) { temp.Location = new System.Drawing.Point(label32.Location.X + 10, label32.Location.Y + (i * temp.Height) + 40); lastY = temp.Location.Y; } else { temp.Location = new System.Drawing.Point(label32.Location.X + 10, lastY + temp.Height + 10); lastY = temp.Location.Y; } i++; store_panel.Controls.Add(temp); } saveGamePreviews = store_panel.Controls.OfType <GamePreview>().ToList(); }
/// <summary> /// Hàm này nên được gọi khi chạy vòng lặp add GamePreview vào control. Nó sẽ set các giá trị mặc định /// như là Font, Kiểu hình Icon, v.v..... Các giá trị có thể edit cho GamePreview bao gồm các giá trị mặc định /// và DockStyle của GameNameText, GamePriceText, GameIcon + kiểu Font của GameNameText, GamePriceText /// Nếu cần thay đổi thêm bất cứ thuộc tính nào, add ở GamePreview.cs rồi sửa lại hàm SetDefaultFormat /// </summary> /// <param name="_input"> là GamePreview sẽ được điều chỉnh </param> public void SetDefaultFormat(GamePreview _input) { _input.GameIconSizeMode = PictureBoxSizeMode.CenterImage; _input.GameNameFont = new Font("Times New Roman", 24, FontStyle.Bold); _input.GamePriceFont = new Font("Times New Roman", 24, FontStyle.Bold); }