How can I make image visible within the groupbox?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 859 Views - Last Post: 05 February 2013 - 07:36 PM Rate Topic: ***-- 1 Votes

#1 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

How can I make image visible within the groupbox?

Posted 05 February 2013 - 04:13 AM

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#.
Is This A Good Question/Topic? 0
  • +

Replies To: How can I make image visible within the groupbox?

#2 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 07:06 AM

View PostKirstine, on 05 February 2013 - 06:13 AM, said:

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#.

We're gonna need a little more information. Are you using WinForms or WPF? Can you include your source code?
Was This Post Helpful? 0
  • +
  • -

#3 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 07:32 AM

Here's my code

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 pic = new PictureBox();
        public Game1()
        {
            InitializeComponent();
            pic.BackColor = Color.Red;
            pic.Size = new Size(20, 20);
            pic.Location = new Point(20, 25);
            this.Controls.Add(pic);

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

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

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

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

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

        private void Game1_Load(object sender, EventArgs e)
        {
            List<GroupBox> groupBoxList = new List<GroupBox>();
            groupBoxList.Add(groupBox1a);
            groupBoxList.Add(groupBox1b);
            groupBoxList.Add(groupBox1c);

            foreach (GroupBox box in groupBoxList)
            {
                box.Hide();
            }

            Random r = new Random();
            GroupBox visibleBox = groupBoxList[r.Next(groupBoxList.Count - 1)];

            visibleBox.Show();

        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#4 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 07:47 AM

You need to set the z-index of the PictureBox control you're adding to the form. This revised code works for me.
        public Game1()
        {
            InitializeComponent();
            pic.BackColor = Color.Red;
            pic.Size = new Size(20, 20);
            pic.Location = new Point(20, 25);
            this.Controls.Add(pic);
            this.Controls.SetChildIndex(pic, 1); // Here's where you set the z-index.

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


Was This Post Helpful? 0
  • +
  • -

#5 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 07:59 AM

still doesn't work. :(
Was This Post Helpful? 0
  • +
  • -

#6 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 08:08 AM

Here's my source code.
https://mega.co.nz/#...WaX29ejznByOtGw
Was This Post Helpful? 0
  • +
  • -

#7 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 08:44 AM

I guess you're code was build in newer version, can't open it. I'm using visual studio 2005
Was This Post Helpful? 0
  • +
  • -

#8 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 08:47 AM

You can download a 90 day trial of Visual Studio 2012 from MSDN.
Was This Post Helpful? 0
  • +
  • -

#9 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 08:58 AM

Does the version will affect my installed Visual studio 05?
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3418
  • View blog
  • Posts: 10,523
  • Joined: 05-May 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 09:13 AM

Sort of... It won't affect that installation directly as in it will still work, but it will change some environment variables, and file associations so that VS2012 takes priority.

I recommend that you simply elaborate on "It still doesn't work". What is happening? Are you getting a compile error? Are you getting a runtime error? Are cats coming out of your fireplace?
Was This Post Helpful? 0
  • +
  • -

#11 Kirstine  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 37
  • Joined: 04-February 13

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 09:17 AM

no error at all, but the image still appear behind the groupbox. Even after adding the 'this.Controls.SetChildIndex(pic, 1);' :(
Was This Post Helpful? 0
  • +
  • -

#12 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4404
  • View blog
  • Posts: 7,646
  • Joined: 08-June 10

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 09:19 AM

@bgammillThank you for being willing to assist people with their code. However, in the future, we'd prefer you not provide a full solution ready to run. We believe that members will learn more from examples and specific assistance rather than having completed solutions to run, because it forces them to learn.
Was This Post Helpful? 0
  • +
  • -

#13 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 09:26 AM

View PostCurtis Rutland, on 05 February 2013 - 11:19 AM, said:

@bgammillThank you for being willing to assist people with their code. However, in the future, we'd prefer you not provide a full solution ready to run. We believe that members will learn more from examples and specific assistance rather than having completed solutions to run, because it forces them to learn.

I totally agree with you. However the solution files I provided are completely identical to the answer I provided earlier in the thread. Since the OP didn't include their entire project, I thought it would be more helpful for them to compare theirs to mine.
Was This Post Helpful? 0
  • +
  • -

#14 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3418
  • View blog
  • Posts: 10,523
  • Joined: 05-May 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 09:30 AM

If your groupbox is at index 0, then it will be on top of your picture. You may need to set the child index to 0 rather than 1.

http://msdn.microsof...childindex.aspx
Was This Post Helpful? 0
  • +
  • -

#15 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3076
  • View blog
  • Posts: 10,277
  • Joined: 12-December 12

Re: How can I make image visible within the groupbox?

Posted 05 February 2013 - 09:30 AM

View PostKirstine, on 05 February 2013 - 09:17 AM, said:

no error at all, but the image still appear behind the groupbox. Even after adding the 'this.Controls.SetChildIndex(pic, 1);' :(/>

The number 1 was just an example - try increasing this number.. What's your favourite number?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2