第一次入住園子,第一次寫博客好緊張:)
最近在做關於一個視頻監控的項目涉及到分屏顯示功能。下載了幾個網上的例子看下都不是太符合要求,所以只能自己動手改造一下
首先定義好要分屏樣式的數組:
//X,Y,row(第幾行) ,col(第幾列) /// <summary> /// * X Y row col /// </summary> public int[, , ,] split1x1 = new int[,,,] { { { { 0, 0, 1, 1 } } } }; /// <summary> /// ** /// ** /// </summary> public int[, , ,] split2x2 = new int[,,,] { {{{ 0, 0,1,1 }}},{{{1,0,1,1}}}, {{{ 0, 1,1,1 }}},{{{1,1,1,1}}} }; /// <summary> /// * /// * /// *** /// </summary> public int[, , ,] split1x5 = new int[,,,] { {{{ 0, 0,2,2}}},{{{ 2, 0,1,1}}}, {{{ 2, 1,1,1}}}, {{{ 0, 2,1,1}}},{{{ 1, 2,1,1}}},{{{ 2, 2,1,1}}} }; /// <summary> /// * /// * /// * ///**** /// </summary> public int[, , ,] split1x7 = new int[,,,] { {{{ 0, 0,3,3 }}},{{{3,0,1,1}}}, {{{3,1,1,1}}}, {{{3,2,1,1}}}, {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}} }; /// <summary> /// *** /// *** /// *** /// </summary> public int[, , ,] split3x3 = new int[,,,] { {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},{{{ 2, 0,1,1 }}}, {{{ 0, 1,1,1 }}},{{{1,1,1,1}}},{{{ 2, 1,1,1 }}}, {{{ 0, 2,1,1 }}},{{{1,2,1,1}}},{{{ 2, 2,1,1 }}}, {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}} }; /// <summary> /// * * /// * * /// **** /// **** /// </summary> public int[, , ,] split2x8 = new int[,,,] { {{{ 0, 0,1,1 }}},{{{1,0,2,2}}},{{{3,0,1,1}}}, {{{ 0, 1,1,1 }}},{{{3,1,1,1}}}, {{{ 0, 2,1,1 }}},{{{1,2,1,1}}},{{{ 2, 2,1,1 }}},{{{3,2,1,1}}}, {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}} }; /// <summary> /// **** /// * * /// * * /// **** /// </summary> public int[, , ,] split1x8 = new int[,,,] { {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},{{{ 2, 0,1,1 }}},{{{3,0,1,1}}}, {{{ 0, 1,1,1 }}},{{{1,1,2,2}}},{{{3,1,1,1}}}, {{{ 0, 2,1,1 }}},{{{3,2,1,1}}}, {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}} }; /// <summary> /// **** /// **** /// **** /// **** /// </summary> public int[, , ,] split4x4 = new int[,,,] { {{{ 0, 0,1,1 }}},{{{1,0,1,1}}},{{{ 2, 0,1,1 }}},{{{3,0,1,1}}}, {{{ 0, 1,1,1 }}},{{{1,1,1,1}}},{{{ 2, 1,1,1 }}},{{{3,1,1,1}}}, {{{ 0, 2,1,1 }}},{{{1,2,1,1}}},{{{ 2, 2,1,1 }}},{{{3,2,1,1}}}, {{{ 0, 3,1,1 }}},{{{1,3,1,1}}},{{{ 2, 3,1,1 }}},{{{3,3,1,1}}} };
最后分屏的代碼也很簡單
/// <summary> /// 顯示分屏 /// </summary> /// <param name="row">行</param> /// <param name="value">顯示樣式</param> public void ShowControl(int row, int[, , ,] value) { //this.row = row; //array = value; this.Controls.Clear(); int itemWidth = this.Width / row; int itemHeight = this.Height / row; // int length = value.Length == 4 ? value.Length : value.Length / 2; for (int i = 0; i < value.Length / 4; i++) { PlayItem item = new PlayItem() { Width = itemWidth * value[i, 0, 0, 2], Height = itemHeight * value[i, 0, 0, 3] }; item.Location = new Point(value[i, 0, 0, 0] * itemWidth, value[i, 0, 0, 1] * itemHeight); this.Controls.Add(item); } }
再來幾張圖片吧


本來想把示例上傳上來的但找不到地方:(
