コード例 #1
0
        /// <summary>
        /// Shows meme with provided id
        /// </summary>
        public static void ShowMeme(int id)
        {
            Meme meme = DataAccess.ShowImage(id + memesNotFound);

            while (meme.title == null)
            {
                memesNotFound++;
                meme = DataAccess.ShowImage(id + memesNotFound);
            }

            //Initialize title label
            meme.lblTitle.Text      = meme.title;
            meme.lblTitle.ForeColor = Color.FromArgb(255, 255, 255, 255);
            meme.lblTitle.Font      = new Font("Arial", 30);
            meme.lblTitle.AutoSize  = true;

            ////Initialize meme picturebox
            meme.picBoxImage       = new PictureBox();
            meme.picBoxImage.Image = meme.image;
            Size  size  = meme.picBoxImage.GetPreferredSize(new Size(1000, 500));
            float scale = size.Height / 500f;

            meme.picBoxImage.Height   = 500;
            meme.picBoxImage.Width    = (int)(size.Width / scale);
            meme.picBoxImage.SizeMode = PictureBoxSizeMode.Zoom;

            //Initialize points and comments label
            meme.pointsAndComments = new Label();
            meme.ShowPointsAndComments();
            meme.pointsAndComments.AutoSize = true;
            if (MainPage.darkMode)
            {
                meme.pointsAndComments.ForeColor = Color.FromArgb(150, 255, 255, 255);
            }
            else
            {
                meme.pointsAndComments.ForeColor = Color.FromArgb(150, 0, 0, 0);
            }

            //Initialize upvote button
            meme.upvote.BackgroundImageLayout = ImageLayout.Zoom;
            meme.upvote.Size      = new Size(52, 40);
            meme.upvote.TabStop   = false;
            meme.upvote.FlatStyle = FlatStyle.Flat;
            meme.upvote.FlatAppearance.BorderSize = 0;
            if (meme.pointsAddedByThisUser == 1)
            {
                meme.upvote.BackgroundImage = imgUpvoteClicked;
            }
            else
            {
                meme.upvote.BackgroundImage = imgUpvoteNormal;
            }

            //Initialize downvote button
            meme.downvote.BackgroundImageLayout = ImageLayout.Zoom;
            meme.downvote.Size      = new Size(52, 40);
            meme.downvote.TabStop   = false;
            meme.downvote.FlatStyle = FlatStyle.Flat;
            meme.downvote.FlatAppearance.BorderSize = 0;
            if (meme.pointsAddedByThisUser == -1)
            {
                meme.downvote.BackgroundImage = imgDownvoteClicked;
            }
            else
            {
                meme.downvote.BackgroundImage = imgDownvoteNormal;
            }

            //Initialize comments button
            meme.comments.BackgroundImageLayout = ImageLayout.Zoom;
            meme.comments.Size      = new Size(52, 40);
            meme.comments.TabStop   = false;
            meme.comments.FlatStyle = FlatStyle.Flat;
            meme.comments.FlatAppearance.BorderSize = 0;
            meme.comments.Location        = new Point(800, 400);
            meme.comments.BackgroundImage = imgComments;

            //Handle events
            meme.picBoxImage.MouseWheel       += MouseWheel;
            meme.pointsAndComments.MouseWheel += MouseWheel;
            meme.lblTitle.MouseWheel          += MouseWheel;

            MainPage.mainPage.Controls.Add(meme.lblTitle);
            MainPage.mainPage.Controls.Add(meme.picBoxImage);
            MainPage.mainPage.Controls.Add(meme.pointsAndComments);
            MainPage.mainPage.Controls.Add(meme.upvote);
            MainPage.mainPage.Controls.Add(meme.downvote);
            MainPage.mainPage.Controls.Add(meme.comments);

            meme.lblTitle.BringToFront();
            meme.picBoxImage.BringToFront();
            meme.pointsAndComments.BringToFront();
            meme.upvote.BringToFront();
            meme.downvote.BringToFront();
            meme.comments.BringToFront();
            meme.idInArray = memes.Count;
            memes.Add(meme);
            SetLocation();

            MainPage.mainPage.BringEverythingToFront();

            if (Account.username == "Guest")
            {
                meme.upvote.Visible   = false;
                meme.downvote.Visible = false;
            }
        }