PictureBox goes out from the form c# -
i need move picturebox inside form. picturebox fantasma1.
this when timer (which moves picturebox) ticks:
private void move_tick(object sender, eventargs e) { completamento.increment(1); while (fantasma1.location.x < max.x) fantasma1.location = new system.drawing.point(fantasma1.location.x + 1, fantasma1.location.y); move.stop(); messagebox.show("location: " + fantasma1.location.x + ";" + fantasma1.location.y + ", larghezza del form: " + this.width + ", dimensione della picture: " + fantasma1.width); } in constructor of form have done:
max.x = this.width - fantasma1.size.width; i think solution correct, picturebox goes out form. can me?
first of all, fantasma run end without seeing move because of this:
while (fantasma1.location.x < max.x) fantasma1.location = new system.drawing.point(fantasma1.location.x + 1, fantasma1.location.y); that loop move ghost end without visible change, think want move 1 pixel move_tick call , if gets limit stop timer, , stoped timer @ first tick, error.
so, if want ghost moving pixel on each tick , don't out of screen should trick:
private void move_tick(object sender, eventargs e) { int max = this.width - fantasma1.width; if(fantasma.left < max) fantasma1.left++; else move.stop(); } in case way of testing max position right, i'm sure trying size before picturebox loads picture (and set autosize in order allow picturebox adjust it's size it's content) avoid errors added max calculation on formula, it's subtraction, not consume any* process.
*: any, line of code costs cpu subtract can less nanosecond, not noticeable.
Comments
Post a Comment