Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Question: How to make picturebox appear in the groupbox.

$
0
0
Hello i have an image that can be move using arrow keys.
Problem is image is behind the group box.
Question: How can I make this image visible within the group box?
HELP. c#.
I only use the toolbox to make my groupbox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CheeseMaze
{
    public partial class Game1 : Form
    {
        PictureBox mouse = new PictureBox();
        public Game1()
        {
            InitializeComponent();
            mouse.BackColor = Color.Red;
            //mouse.ImageLocation = "rat.png";
            mouse.Size = new Size(20, 20);
            mouse.Location = new Point(20, 25);
            this.Controls.Add(mouse);

            this.KeyDown += new KeyEventHandler(Game1_KeyDown);
        }

        void Game1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Left)
            {
                mouse.Location = new Point(mouse.Location.X - 1, mouse.Location.Y);
            }

            if (e.KeyData == Keys.Right)
            {
                mouse.Location = new Point(mouse.Location.X + 1, mouse.Location.Y);
            }

            if (e.KeyData == Keys.Up)
            {
                mouse.Location = new Point(mouse.Location.X, mouse.Location.Y - 1);
            }

            if (e.KeyData == Keys.Down)
            {
                mouse.Location = new Point(mouse.Location.X, mouse.Location.Y + 1);
            }
        }


    }
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>