コード例 #1
0
        private void LoadFavorites(List <Pairing> pairings)
        {
            Controls.Clear();

            PictureBox pbHeaderFav = new PictureBox
            {
                Width    = 1920,
                Height   = 245,
                Location = new Point(-200, -35),
                Image    = Properties.Resources.FavoritesHeader
            };

            Controls.Add(pbHeaderFav);

            int locationX = 70;
            int locationY = 300;

            foreach (Pairing pairing in pairings)
            {
                Drink drink1 = pairing.Drink1;
                Drink drink2 = pairing.Drink2;

                GroupBox favoriteGroupBox = new GroupBox
                {
                    Width     = padding + imageWidth + imageWidth + textSize + padding,
                    Height    = padding + imageHeight + padding,
                    Location  = new Point(locationX, locationY),
                    BackColor = Color.FromArgb(255, 255, 255),
                    Cursor    = Cursors.Hand
                };

                locationX += padding + imageWidth + imageWidth + textSize + padding + margin;

                if (locationX > 1300)
                {
                    locationX  = 70;
                    locationY += padding + imageHeight + padding + margin;
                }

                PictureBox pbDrink1 = new PictureBox
                {
                    Width    = imageWidth,
                    Height   = imageHeight,
                    Location = new Point(padding, padding),
                    Image    = GetImageById(drink1.Id)
                };

                PictureBox pbDrink2 = new PictureBox
                {
                    Width    = imageWidth,
                    Height   = imageHeight,
                    Location = new Point(padding + imageWidth, padding),
                    Image    = GetImageById(drink2.Id)
                };

                Label label1 = new Label
                {
                    Text         = drink1.Name,
                    Location     = new Point(padding + imageWidth + imageWidth, padding),
                    Font         = new Font("Helvetica", 10, FontStyle.Bold),
                    AutoEllipsis = true,
                    Width        = textSize
                };

                Label label2 = new Label
                {
                    Text         = drink2.Name,
                    Location     = new Point(padding + imageWidth + imageWidth, padding + margin),
                    Font         = new Font("Helvetica", 10, FontStyle.Bold),
                    AutoEllipsis = true,
                    Width        = textSize
                };

                favoriteGroupBox.Controls.Add(pbDrink1);
                favoriteGroupBox.Controls.Add(pbDrink2);
                favoriteGroupBox.Controls.Add(label1);
                favoriteGroupBox.Controls.Add(label2);

                Controls.Add(favoriteGroupBox);

                EventHandler clickHandler = new EventHandler((sender, e) => Favorite_Click(sender, e, drink1, drink2));

                favoriteGroupBox.Click += clickHandler;
                pbDrink1.Click         += clickHandler;
                pbDrink2.Click         += clickHandler;
                label1.Click           += clickHandler;
                label2.Click           += clickHandler;
            }
        }
コード例 #2
0
        private void HandlePageChange(Drink drink)
        {
            switch (currentPage)
            {
            case "MENU":
                ShowMenuButtons();
                break;

            case "DRINKS_1":
                HideMenuButtons();

                if (selectedDrinks.Count > 0)
                {
                    selectedDrinks.Clear();
                }

                LoadDrinks(database.GetAvailableDrinks());
                lblWelcome.Text = "MIX!";
                break;

            case "DRINKS_2":
                LoadDrinks(database.GetPairings(drink.Id));
                break;

            case "FAVORITES":
                HideMenuButtons();
                LoadFavorites(database.GetFavorites(loggedInUser.Id));
                // currentPage = "RESULT";
                break;

            case "RESULT":
                int locationX = (ClientSize.Width / 2) - padding * 4;
                int locationY = (ClientSize.Height / 2) - imageHeight / 2;

                Controls.Clear();

                if (selectedDrinks.Count != 2)
                {
                    MessageBox.Show("Oops verkeerd aantal drankjes");
                }

                foreach (Drink d in selectedDrinks)
                {
                    PictureBox pbDrink = new PictureBox
                    {
                        Width    = imageWidth,
                        Height   = imageHeight,
                        Location = new Point(locationX, locationY),
                        Image    = GetImageById(d.Id)
                    };

                    Controls.Add(pbDrink);
                    locationX += padding * 8;
                }

                pbStar = new PictureBox
                {
                    Width    = 50,
                    Height   = 50,
                    Location = new Point((this.ClientSize.Width / 2) - 25, (this.ClientSize.Height / 2) + 175),
                    Image    = Properties.Resources.FavoriteStarEmpty,
                    Cursor   = Cursors.Hand
                };

                pbStar.Click += PbStar_Click;

                PictureBox pbConfirm = new PictureBox
                {
                    Width    = 156,
                    Height   = 69,
                    Location = new Point((this.ClientSize.Width / 2) - 78, (this.ClientSize.Height / 2) + 50),
                    Image    = Properties.Resources.confirmButton,
                    Cursor   = Cursors.Hand
                };

                pbConfirm.Click += PbConfirm_Click;

                Controls.Add(pbStar);
                Controls.Add(pbConfirm);
                break;

            case "LOGIN":
                this.Hide();
                Form loginForm = new LoginForm();
                loginForm.FormClosed += (s, args) => this.Close();
                loginForm.Show();
                break;

            default:
                return;
            }

            AddBackButton();
        }