c#中winform的form窗口互相影响

仅作为记录,游客请跳过。


有改善,但还未解决

背景

博主用c#winform做了界面跳转:
在这里插入图片描述
从form2可分别跳转到form3、form4;form3和form4实现不同的功能;


现问题是:从2→4完成,然后返回2后;
再从2到3的这个过程受到很大影响(基本弹跳不出3的界面):
在这里插入图片描述

初步解决

将form3和form4的返回的代码,

把this.Hide();改为this.Close();

在这里插入图片描述
在这里插入图片描述

这样做仅能够改善一些,即能基本实现2→4、4→2到2→3的功能;

但弹出的窗口无法关闭,没能很好地解决。

解决

再改成以下这样,就可以关闭窗口了:
在这里插入图片描述
在这里插入图片描述


还存在:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的例子,演示了如何在C# WinForm窗口嵌入控制台: ```csharp using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WinFormConsole { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // 启动控制台进程 Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); // 将控制台窗口嵌入到WinForm IntPtr handle = process.MainWindowHandle; SetParent(handle, consolePanel.Handle); // 设置控制台窗口位置和大小 SetWindowLong(handle, GWL_STYLE, WS_VISIBLE | WS_CHILD); MoveWindow(handle, 0, 0, consolePanel.Width, consolePanel.Height, true); } // WinAPI函数 [DllImport("user32.dll")] static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", SetLastError = true)] static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong); [DllImport("user32.dll", SetLastError = true)] static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); const int GWL_STYLE = -16; const uint WS_VISIBLE = 0x10000000; const uint WS_CHILD = 0x40000000; } } ``` 在这个例子,我们创建了一个名为`consolePanel`的`Panel`控件,用于嵌入控制台窗口。在`Form1_Load`事件处理程序,我们启动了一个控制台进程,并将其嵌入到`consolePanel`。 请注意,我们使用了一些WinAPI函数来实现窗口嵌入。这些函数包括`SetParent`、`SetWindowLong`和`MoveWindow`。在这个例子,我们使用了`DllImport`属性来声明这些函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值