Controls change with the window size (from the small lottery system), window Lottery
I. A problem encountered in the lottery system is that the control needs to zoom in with the window, and the position and size also change. I found a lot of information on the Internet, the attribute values of both Anchor and Dock are modified, but they do not match the desired effect. The emperor finally found me (as shown below)
Private float X, Y; private void setTag (Control cons) {foreach (Control con in cons. controls) {con. tag = con. width + ":" + con. height + ":" + con. left + ":" + con. top + ":" + con. font. size; if (con. controls. count> 0) setTag (con) ;}} private void setControls (float newx, float newy, Control cons) {foreach (Control con in cons. controls) {string [] mytag = con. tag. toString (). split (new char [] {':'}); float a = Convert. toSingle (mytag [0]) * newx; con. width = (int) a; a = Convert. toSingle (mytag [1]) * newy; con. height = (int) (a); a = Convert. toSingle (mytag [2]) * newx; con. left = (int) (a); a = Convert. toSingle (mytag [3]) * newy; con. top = (int) (a); Single currentSize = Convert. toSingle (mytag [4]) * newy; con. font = new Font (con. font. name, currentSize, con. font. style, con. font. unit); if (con. controls. count> 0) {setControls (newx, newy, con) ;}} private void FrmClinicalTV_Load (object sender, EventArgs e) {this. resize + = new EventHandler (FrmClinicalTV_Resize); X = this. width; Y = this. height; // y = this. statusStrip1.Height; setTag (this);} private void FrmClinicalTV_Resize (object sender, EventArgs e) {// throw new Exception ("The method or operation is not implemented. "); float newx = (this. width)/X; // float newy = (this. height-this. statusStrip1.Height)/(Y-y); float newy = this. height/Y; setControls (newx, newy, this); // this. text = this. width. toString () + "" + this. height. toString ();}View Code
2. When the winfrom form is started, the interface will flash, which will affect the user experience. Adding a piece of code can reduce this situation.
// This. SetStyle (ControlStyles. OptimizedDoubleBuffer | ControlStyles. AllPaintingInWmPaint | ControlStyles. UserPaint, true );