Controls change with the window size (from the small lottery system), window Lottery

Source: Internet
Author: User

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 );

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.