private void Form1_Load(object sender, EventArgs e) { // 设置窗口透明 pictureBox1.BackColor = Color.Red; this.TransparencyKey = Color.Red; this.BackColor = Color.Red; this.TopMost = true; // 设置当前窗口为顶层窗口 temp_Height = this.Height; // 保存窗体高度 try { string DingDingPath = Reg.GetDingDingPath(); // 获取钉钉路径 Process.Start(DingDingPath); // 打开钉钉 for (int i = 1; i <= 20; i++) // 寻找钉钉进程 { foreach (Process pro in Process.GetProcesses()) { if (pro.ProcessName.ToLower() == "DingTalk".ToLower()) { i = 999; // 为了跳出外层的for循环 break; } } if (i > 20) { break; } else if (i == 20) { throw new Exception("未找到钉钉进程,请手动打开钉钉后重试!"); } System.Threading.Thread.Sleep(3000);// 如未找到则等待3秒再查找 } } catch (Exception ex) { MessageBox.Show("错误:" + ex.Message, "自动进入钉钉直播间", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } }