且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows窗体:无法单击以使非TopLevel窗体中的MaskedTextBox集中

更新时间:2023-12-06 11:58:10

这次我尝试了您的代码,并获得了很好的复制.正如我在原始帖子中提到的,这确实是一个窗口激活问题.您可以在Spy ++中看到此消息,请注意WM_MOUSEACTIVATE消息.

I tried your code and got a good repro this time. As I mentioned in my original post, this is indeed a window activation problem. You can see this in Spy++, note the WM_MOUSEACTIVATE messages.

之所以会这样,是因为您显示带有标题栏的表单.这使Windows窗口管理器确信该窗口可以被激活.那实际上是行不通的,它不再是***窗口.从标题栏可见,它永远不会使用窗口激活"颜色进行绘制.

This happens because you display the form with a caption bar. That convinces the Windows window manager that the window can be activated. That doesn't actually work, it is no longer a top-level window. Visible from the caption bar, it never gets drawn with the "window activated" colors.

您将必须从表格中删除标题栏.***在代码中添加以下行:

You will have to remove the caption bar from the form. That's best done by adding this line to your code:

    newReportForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None

将把表单转换成与UserControl不能区分开的控件.您仍然可以通过使用以下代码来使其与众不同:

Which will turn the form into a control that's otherwise indistinguishable from a UserControl. You can still make it distinctive by using this code instead:

    newReportForm.ControlBox = False
    newReportForm.Text = ""

任何一种修复都可以解决鼠标单击问题.

Either fix solves the mouse click problem.