C # Notes 9--multi-screen, full-screen program based on TableLayoutPanel

Source: Internet
Author: User
C # Notes 9--multi-screen, full-screen program based on TableLayoutPanel

Recently, due to the need for work, you need to set up a multiple-screen window to facilitate multiple-screen playback of the video.
Thinking about it, the general idea is as follows: Use TableLayoutPanel to divide multiple regions, in each area, put a PictureBox, with PictureBox to receive the camera data flow;
Each time you select a different split screen, set the number of rows and columns of TableLayoutPanel according to the number n*n and add PictureBox to it.
Multi-screen effect diagram is as follows:


For multiple split screen, usually need full-screen function, mostly divided into full screen and program form full screen, its corresponding effect is as follows:


The code is as follows:

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;

Using System.Windows; namespace Multicamera {public partial class Form1:form {public Form1 () {Initializ
        Ecomponent ();
            } private void Form1_Load (object sender, EventArgs e) {split_screen (1); Record the original screen size and width high point_old = new System.Drawing.Point (this. Location.x,this. 
            LOCATION.Y); Width_old = this.
            Width; Height_old = this.
        Height;
        private int curscreennum = 0;
        private bool IsFullScreen = false;
        private int row = 0;
        private int col = 0;
        Private picturebox[] PB = new picturebox[25];
        Private point point_old = new System.Drawing.Point ();
        private int width_old;
      private int height_old;  private void split_screen (int num) {tlp_screen.
            Columnstyles.clear (); Tlp_screen. Rowstyles.clear ();
            Clear row and column attributes int i; for (i = 0; i < Curscreennum i++) {Tlp_screen.
            Controls.remove (Pb[i]); } tlp_screen.
            Refresh ();
            int sqrt_num = (int) math.sqrt (num); Tlp_screen.
            ColumnCount = Sqrt_num; Tlp_screen.
            RowCount = Sqrt_num; int pb_width = (tlp_screen. Width-6*sqrt_num)/sqrt_num; You cannot modify the PictureBox margin to 0 (the default is 3), so you can set a space 6* column/row int pb_height = (tlp_screen.
            Height-6*sqrt_num)/sqrt_num;
                for (i = 0; i < num i++) {row = I/sqrt_num;
                Col = i% Sqrt_num;
                Pb[i] = new PictureBox (); Pb[i].
                Tag = i; Pb[i]. Click + + new System.EventHandler (this.
                Picclick); Pb[i]. Padding = new Padding (1, 1, 1, 1);
            Why not?    Tlp_screen.
                Controls.Add (Pb[i],col,row); Pb[i].
                BackColor = Color.FromArgb (row + col), * row, * col); Pb[i].
                Location = new System.Drawing.Point (row * pb_width, col * pb_height); Pb[i].
                Size = new System.Drawing.Size (pb_width,pb_height); Console.WriteLine ("Pb[{0}] w:{1} h:{2} x:{3},y:{4}", I,pb[i]. Width, Pb[i]. Height, Pb[i]. Location.x, Pb[i].
            LOCATION.Y);
        } curscreennum = num;
            } private void Picclick (object sender, EventArgs e) {PictureBox pic = sender as PictureBox; Pic.
            BackColor = Color.Blue; String Pictag = pic.
            Tag.tostring ();
            MessageBox.Show ("I ' m pictruebox[" +pictag+ "]");
            Fullscreen (pic);
                Switch (pictag) {case ' 0 ': break;
                Case "1": Break;
     Case "2": break;           Case "3": break;
                Case "4": break;
                Case "5": break;
                Case "6": break;
                Case "7": break;
                Case "8": break;
                Case "9": break;
                Case "ten": Break;
                Case "one": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
                Case "a": break;
             Case "21":       Break
                Case "a": break;
                Case "a": break;
                Case "a": break;
            Default:break; }} private void Fullscreen (PictureBox pic) {//Form internal full screen/* if
            (!isfullscreen)
                {//full Screen isfullscreen = true; Tlp_screen.
                Controls.remove (pic); Pic.
                Parent = this; Pic.
                BringToFront (); Pic.
                Dock = DockStyle.Fill; Tlp_screen.
            Hide ();
                else {//cancel Full screen isfullscreen = false; Tlp_screen.
                Controls.Add (pic); Pic.
                Parent = Tlp_screen; Pic.
                Dock = DockStyle.Fill; Tlp_screen.
            Show (); * */////* Form Full Screen * * Rectangle rect = new RectanGLE (); Rect = Screen.getbounds (this);//Get screen size if (!isfullscreen) {//full screens ISFULLSC
                Reen = true; This. FormBorderStyle = Formborderstyle.none; Cancel form border this. Width = rect.
                Width; This. Height = rect.
                Height; This.
                Location = new System.Drawing.Point (0, 0); Tlp_screen.
                Controls.remove (pic); Pic.
                Parent = this; Pic.
                BringToFront (); Pic.
                Dock = DockStyle.Fill; Tlp_screen.
            Hide ();
                else {//cancel Full screen isfullscreen = false; This.
                FormBorderStyle = formborderstyle.sizable; This.
                Location = Point_old; This.
                Height = Height_old; This.
                Width = Width_old; Tlp_screen.
                Controls.Add (pic); Pic.
                Parent = Tlp_screen; Pic.
        Dock = DockStyle.Fill;        Tlp_screen.
            Show ();
        }} private void Btn_fp_1_click (object sender, EventArgs e) {split_screen (1);
        } private void Btn_fp_4_click (object sender, EventArgs e) {split_screen (4);
        } private void Btn_fp_9_click (object sender, EventArgs e) {split_screen (9);
        } private void Btn_fp_16_click (object sender, EventArgs e) {split_screen (16);
        } private void Btn_fp_25_click (object sender, EventArgs e) {Split_screen (25);
 }
    }
}

Source Code Connection: http://download.csdn.net/download/u011127242/9777723

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.