Example of a C # split-screen control usage

Source: Internet
Author: User

The custom class PictureBox in this example inherits from the UserControl, and finally realizes the simple split screen function. Share it for everyone's reference. The specific implementation code is as follows:

Public partial class Picturecontrol:usercontrol{public event MouseEventHandler Piccontrol_doubleclick;    private int picnum;      <summary>////number of screens///</summary> public int Picnum {get {return picnum;} set {if (value = = 4 | | value = = 6 | | value = = 9 | | value = | | | value = = | | value = = 25)/          /can only be 4, 6, 9, 12, 16, 20, picnum = value; This.        Setpicturebox (This.picnum); } else {this.          Picnum = 12; This.        Setpicturebox (This.picnum);      }}} public Picturecontrol () {this.picnum = 4;      InitializeComponent (); This.    Setpicturebox (This.picnum);    }///<summary>///based on number of layouts PictureBox//</summary>/<param name= "num" ></param> private void Setpicturebox (int num) {this.      Controls.clear (); Size size = this.      Size; Switch (num) {case 4:this. Setpicturebox (2, 2, size);        Break Case 6:this. Setpicturebox (2, 3, size);        Break Case 9:this. Setpicturebox (3, 3, size);        Break Case 12:this. Setpicturebox (3, 4, size);        Break Case 16:this. Setpicturebox (4, 4, size);        Break Case 20:this. Setpicturebox (4, 5, size);        Break Case 25:this. Setpicturebox (5, 5, size);      Break    }}///<summary>//Layout PictureBox//</summary>//<param name= "x" > several lines </param> <param name= "Y" > several columns </param>//<param name= "Size" > the size of the current control </param> private void setpictu      Rebox (int x, int y,size Size) {int num = 0; for (int i = 0, i < x; i++) {for (int j = 0; J < y; J + +) {PictureBox pic = new picture          Box (); Pic.                     SizeMode = Pictureboxsizemode.zoom; Sets the auto-scale pic.                          BackColor = Color.White; Sets the background color of pic. Location = new Point (size. width/y) * j, (size. height/x) * i); Set up location pic.                   BorderStyle = BorderStyle.FixedSingle; Sets the border pic.      MouseDoubleClick + = new MouseEventHandler (Pic_mousedoubleclick); Subscription control double-click event pic. size = new Size (size. width/y, size.              height/x); Sets the size of the control pic.                                 Tag = num; Sets the control number, which is the screen number this.                             Controls.Add (pic);        Add num++; }}} void Pic_mousedoubleclick (object sender, MouseEventArgs e) {if (this. Piccontrol_doubleclick = null) {this.      Piccontrol_doubleclick (sender, E);//The double-click event of a dynamically added control is passed outside the control body. }} private void Picturecontrol_sizechanged (object sender, EventArgs e) {this.    Setpicturebox (This.picnum); Private PictureBox getpicbyindex (int index) {foreach (Control C in).        Controls) {if (Convert.ToInt32 (c.tag) = = index) {return (PictureBox) C; }} PictureBox p = new PicTurebox ();      P.tag =-1;    return p; }///<summary>///Set image according to screen number///</summary>//<param name= "index" > Screen number </param>/ <param name= "img" > Images </param> public void setimagebyindex (int index, image img) {Getpicbyindex (i Ndex).    Image = img; }}

I hope that the examples described in this article will help you with C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
Example of a C # split-screen control usage

This address: http://www.paobuke.com/develop/c-develop/pbk23600.html






Related content C # Implementation of an Access database action class full instance of IIS downgrade with certificate exception resolution (C #) C # implementation Win10 UWP right-click flyout Pop-up in click Location application of builder pattern in programming of C # design pattern
Easy to learn C # Read and write operations C # implements a quick read of txt text data into Excel C # processing JSON string Instance Analysis C # WinForm Program Exit Method Tips Summary

Example of a C # split-screen control usage

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.