hmmm ich wollte fragen ob es eine bessere lösung als das hier gibt:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
| 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 WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_KeyDown(object sender, KeyEventArgs e) { switch(e.KeyData) { case Keys.Down: if (pictureBox1.Location.Y == 230) { break; } this.pictureBox1.Location = new System.Drawing.Point(pictureBox1.Location.X ,pictureBox1.Location.Y + 10); toolStripStatusLabel1.Text = "Y: " + pictureBox1.Location.Y.ToString(); break; case Keys.Up: if (pictureBox1.Location.Y == 0) { break; } this.pictureBox1.Location = new System.Drawing.Point(pictureBox1.Location.X, pictureBox1.Location.Y - 10); toolStripStatusLabel1.Text = "Y: " + pictureBox1.Location.Y.ToString(); break; case Keys.Left: if (pictureBox1.Location.X == 0) { break; } this.pictureBox1.Location = new System.Drawing.Point(pictureBox1.Location.X - 10, pictureBox1.Location.Y); toolStripStatusLabel2.Text = "X: " + pictureBox1.Location.X.ToString(); break; case Keys.Right: if (pictureBox1.Location.X == 280) { break; } this.pictureBox1.Location = new System.Drawing.Point(pictureBox1.Location.X + 10, pictureBox1.Location.Y); toolStripStatusLabel2.Text = "X: " + pictureBox1.Location.X.ToString(); break; } } } } |
Auf die benamsung jetzt einfach mal nicht achten, da das nur ein test ist
hmmm das x und y ist auch verdreht, da der ausgangspunkt glaube links oben ist...
Aber meine Frage ist hauptsächlich wie man es am besten lösen kann das das bild nicht aus der form raus geht, also dem nach dann mehr oder weniger unsichbar ist. den das if (pictureBox1.Location.X == 280) ist glaube nicht die beste lösung.
Evtl. habt ihr ja eine Idee.
mmfg. TheLol