Moving controls in a form and store/restore the position
-
Hi, I looking for create dynamically some control in a form with the possibility of moving each control anywhere in the form. I would like to store the position and store it to a xml files. After create some config, I would like to restore a specific config. My question is : How can I moving each control create dynamicaly with the mouse ? How can I retrieve the position of each control in the form ? Best Regards youssef
-
Hi, I looking for create dynamically some control in a form with the possibility of moving each control anywhere in the form. I would like to store the position and store it to a xml files. After create some config, I would like to restore a specific config. My question is : How can I moving each control create dynamicaly with the mouse ? How can I retrieve the position of each control in the form ? Best Regards youssef
In the class level : Point p = new Point(this.button1.Location.X,this.button1.Location.Y); In the mouse down event : void form1_mousedown() { //Write some code to add the point p to the config file ,Ican't remember how right now. this.p = new Point(-e.X,-e.Y); } In the mouse move event : void form1_mousemove() { if (e.Button == MouseButtons.Left) { Point mousepos = Control.MousePosition; mousepos.Offset(this.p.X,this.p.Y); this.button1.Location = mousepos; } }