在循环开头写了个readkey 回车来控制每一次重复循环,有没有办法在运行到那的时候让控制台主动转移焦点?谢谢各位了
2条回答 默认 最新
- wanghui0380 2022-07-13 10:43关注
using System.Diagnostics; using System.Runtime.InteropServices; [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); //获取控制台窗体句柄 var handle = GetConsoleWindow(); while (true) { Console.WriteLine("提示:请输入"); //重新设置窗体显示为Normal ShowWindow(handle, 1); //将窗体带回前台激活 SetForegroundWindow(handle); await Task.Delay(10 * 1000); } Console.ReadKey();
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效