winform 窗体之间切换

 

        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        public static extern int b(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
         public static extern int a(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);

      //点击picturebox事件触发 窗体打开

private void pictureBox2_Click(object sender, EventArgs e)
        {
            OA fm = new OA();

            if (Context.IsHasOpen("OA"))
            {
                a(b(null, "OA"), -1, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
                a(b(null, "Test2"), -2, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
            }
            else
            {
                if (Context.OpenForm.Length > 0)
                {
                    Context.OpenForm += ",";
                }
                Context.OpenForm += "OA";
                fm.Show();
            }
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            Test2 f = new Test2();

            if (Context.IsHasOpen("Test2"))
            {
                a(b(null, "Test2"), -1, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
                a(b(null, "OA"), -2, 0, 0, 0, 0, 0x001 | 0x002 | 0x040);
            }
            else
            {
                if (Context.OpenForm.Length > 0)
                {
                    Context.OpenForm += ",";
                }
                Context.OpenForm += "Test2";
                f.Show();
            }
        }

       //Content 类

 public class Context
    {
        public static string OpenForm = "";

        //记录打开窗体名称

        public static bool IsHasOpen(string newForm)
        {
            bool bR = false;
            string[] arrylist = OpenForm.Split(',');
            if (arrylist.Length > 0)
            {
                foreach (string str in arrylist)
                {
                    if (newForm == str)
                    {
                        bR = true;
                        break;
                    }
                    else
                    {
                        bR = false;
                    }
                }
            }
            return bR;
        }

//窗体关闭触发此事件,清除对应窗体名称

        public static string DeleteOpenFrom(string strForm)
        {
            string[] arrylist = OpenForm.Split(',');

            if (arrylist.Length > 0)
            {
                OpenForm = "";

                foreach (string str in arrylist)
                {
                    if (strForm == str)
                    {

                    }
                    else
                    {
                        if (OpenForm.Length <= 0)
                        {
                            OpenForm += str;
                        }
                        else
                        {
                            OpenForm += "," + str;
                        }
                    }
                }
            }
            return OpenForm;
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值