How to do Dot Indication for Picomouse Simulator?
-
mercoledì 13 giugno 2012 07:13
Hi,
It would be better if dot indicaton is added to the picomouse simulator to allow the user know where the picomouse had walked before. I tried researching for relevant information regarding dot indication but have yet to find any. Is there any advice on this?
Thanks!
Tutte le risposte
-
giovedì 14 giugno 2012 06:35Moderatore
Could you please let me know if each rectangle is a picturebox?
Good day.
Alexander Sun [MSFT]
MSDN Community Support | Feedback to us
-
venerdì 15 giugno 2012 01:43Hi,
Yes, each rectangle is a picturebox.
Regards,
Melsoon -
venerdì 15 giugno 2012 09:05Moderatore
Hi Melsoon,
I think we can store all picture boxes into a list<PictureBox>. Then we need an Int32 array to store the numbers of picture boxes picomouse passed. Next, I think we can add the method for editing image of picture box into the movement event(if you use it). After each movement, you add the number of picture box into array and change the BackgroundImage of picture box (you can prepare the image “dot indicaton” ahead).
Have a nice day.
Alexander Sun [MSFT]
MSDN Community Support | Feedback to us
-
lunedì 18 giugno 2012 07:20Hi,
i don't quite get what you meant. Can you explain it more specifically? Thanks!
Regards,
Melsoon -
mercoledì 20 giugno 2012 08:04Moderatore
Hi Melsoon,
I wrote a simple sample for you. NOTE: this sample is not the best but easy to understand. In this sample, I use 12 picture boxes (four picture boxes a line, three lines in all).
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplicationPictureBoxes { public partial class Form1 : Form { internal Int32[] path = new Int32[1000];//path array stores all the picture boxes picomouse passed. I set the length of thi s array as 1000, which means it can log 1000 steps. You can modify the length of this array to meet your requirements. The number in this array is the index number of listPictureBoxes. private Int32 currentIndex = 0;//This variable mark the index of current picture box. List<PictureBox> listPictureBoxes = new List<PictureBox>();//This list stores all the picture boxes. public Form1() { InitializeComponent(); AddPictureBoxes();//Add all the picture boxes in list. path[0] = 0;//Set the start picture box. pictureBox1.Image = Properties.Resources.What;//Change the imgae of picture box which is arrived. this.KeyUp += new KeyEventHandler(Form1_KeyUp);//Here I use arrow keys to move. You can change it as you wish. } void Form1_KeyUp(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Right: if ((path[currentIndex] + 1) % 4 != 0)//Check if the picture box to move is on the out of boundary. { listPictureBoxes[path[currentIndex] + 1].Image = Properties.Resources.What; path[currentIndex + 1] = path[currentIndex] + 1; currentIndex++; } break; case Keys. if ((path[currentIndex] + 1) % 4 != 1) { listPictureBoxes[path[currentIndex] - 1].Image = Properties.Resources.What; path[currentIndex + 1] = path[currentIndex] - 1; currentIndex++; } break; case Keys.Up: if ((path[currentIndex] + 1) / 4 != 0) { listPictureBoxes[path[currentIndex] - 4].Image = Properties.Resources.What; path[currentIndex + 1] = path[currentIndex] - 4; currentIndex++; } break; case Keys.Down: if ((path[currentIndex] + 1) / 8 != 1) { listPictureBoxes[path[currentIndex] + 4].Image = Properties.Resources.What; path[currentIndex + 1] = path[currentIndex] + 4; currentIndex++; } break; default: break; } } private void AddPictureBoxes() { listPictureBoxes.Add(this.pictureBox1); listPictureBoxes.Add(this.pictureBox2); listPictureBoxes.Add(this.pictureBox3); listPictureBoxes.Add(this.pictureBox4); listPictureBoxes.Add(this.pictureBox5); listPictureBoxes.Add(this.pictureBox6); listPictureBoxes.Add(this.pictureBox7); listPictureBoxes.Add(this.pictureBox8); listPictureBoxes.Add(this.pictureBox9); listPictureBoxes.Add(this.pictureBox10); listPictureBoxes.Add(this.pictureBox11); listPictureBoxes.Add(this.pictureBox12); } } }
Have a nice day.
Alexander Sun [MSFT]
MSDN Community Support | Feedback to us
- Modificato Alexander SunModerator mercoledì 20 giugno 2012 08:14
-
mercoledì 20 giugno 2012 08:17Moderatore
Hi Melsoon,
It seems the code block has some problems. In previous post, it missed “Left” after the "case Keys." in the switch block.
Have a nice day.
Alexander Sun [MSFT]
MSDN Community Support | Feedback to us
- Modificato Alexander SunModerator mercoledì 20 giugno 2012 08:19
-
giovedì 21 giugno 2012 08:21
Hi,
i have tried it with my application but it doesn't seem to work out. Is the method fix? whereby it is in order? For example, PictureBox1,PictureBox2 and so on... Because for my application, the maze is randomly selected. Therefore i can't used fix method. Need some flexible codes. Need help!
Regards,
Melsoon
- Modificato Melsoon giovedì 21 giugno 2012 08:34
-
giovedì 21 giugno 2012 09:24Moderatore
Hi Melsoon,
Could you please let me know the specific error? Or if you do not mind, you can upload your solution to SkyDrive to help me analyze your problems: https://skydrive.live.com/
Good day!
Alexander Sun [MSFT]
MSDN Community Support | Feedback to us
-
martedì 26 giugno 2012 05:35
Hi,
Currently there's no error in my program, but the red dot does not follow the picomouse. Instead, the picomouse changes to the red dot during certain time when it tries to move up direction. My application is not based on a fixed maze. Therefore, I can't put the pictureBox1 to 12 accordingly. Is there any method to use pictureBox1 and pictureBox2 with variable "i" with a "for" or "while" loop? Because the code has to be flexible as there are many maze i can choose from. Need help!
Regards,
Melsoon

