当前位置: 首页 > 编程语言 > C#

C#学习教程:.NET中是否有等同于MacOSXDocument的架构表?Share

时间:2023-04-11 11:36:42 C#

.NET中是否有等效于MacOSXDocument的架构表?我的应用程序越来越多地要求某些对话框的行为类似于MacOSX文档模态表功能,其中对话框只是父控件/对话框的模态,而不是整个应用程序(参见http://en.wikipedia.org/维基/Window_dialog)。当前窗口ShowDialog()对我的应用程序来说不够用,因为我需要使一个对话框成为应用程序中另一个对话框的模式,但仍允许用户访问应用程序的其他区域。在C#.NET中是否有等效于DocumentmodalSheet的东西?甚至是某人已经完成的紧密实施,还是我正在尝试自己实施?我试过搜索谷歌和SO无济于事。谢谢,Kyle在重新审视问题之后,我进行了一些挖掘并找到了适合我需要的混合解决方案。我接受了p-daddy的建议:https://stackoverflow.com/a/428782/654244我使用hans-passant的建议修改了32位和64位编译的代码:https://stackoverflow.com/a/3344276/654244结果如下:constintGWL_STYLE=-16;constintWS_DISABLED=0x08000000;publicstaticintGetWindowLong(IntPtrhWnd,intnIndex){if(IntPtr.Size==4){returnGetWindowLong32(hWnd),nIndex;}返回GetWindowLongPtr64(hWnd,nIndex);}publicstaticintSetWindowLong(IntPtrhWnd,intnIndex,intdwNewLong){if(IntPtr.Size==4){returnSetWindowLong32(hWnd,nIndex,dwNewLong);}returnLongSetWindow(hWnd,nIndex,dwNewLong);}[DllImport("user32.dll",EntryPoint="GetWindowLong",CharSet=CharSet.Auto)]privatestaticexternintGetWindowLong32(IntPtrhWnd,intnIndex);[DllImport("user32.dll",EntryPoint="GetWindowLongPtr",CharSet=CharSet.Auto)]privatestaticexternintGetWindowLongPtr64(IntPtrhWnd,intnIndex);[DllImport("user32.dll",EntryPoint="SetWindowLong",CharSet=CharSet。自动)]privatestaticexternintSetWindowLong32(IntPtrhWnd,intnIndex,intdwNewLong);[DllImport("user32.dll",EntryPoint="SetWindowLongPtr",CharSet=CharSet.Auto)]privatestaticexternintSetWindowLongPtr64(IntPtrhWnd,intnIndex,intdwNewLong);publicstaticvoidSetNativeEnabled(IWin32Windowcontrol,boolenabled){if(control==null||control.Handle==IntPtr.Zero)return;NativeMethods.SetWindowLong(control.Handle,NativeMethods.GWL_STYLE,NativeMethods.GetWindowLong(control.Handle,NativeMethods.GWL_STYLE)&~NativeMethods.WS_DISABLED|(enabled?0:NativeMethods.WS_DISABLED));}publicstaticvoidShowChildModalToParent(IWin32Windowparent,Formchild){if(|parent==nullchild==null)return;//禁用父级。SetNativeEnabled(父母,假);child.Closed+=(s,e)=>{//启用父级。SetNativeEnabled(父母,真);};孩子。显示(父母);}Form.ShowDialog方法允许您在调用它时指定所有者。在这种情况下,表单将仅对给定的所有者是模态的。编辑:我试过这个,结果好坏参半。我创建了一个简单的Windows窗体应用程序,其中包含一个主窗体和另外两个窗体。从按钮单击主窗体,我使用Show方法打开Form2。Form2上还有一个按钮,单击时,我使用ShowDialog方法打开Form3,将Form2作为其所有者传递。尽管Form3似乎是Form2的模式,但在关闭Form3之前我无法切换回Form1。以上是C#学习教程:.NET中有没有等同于MacOSXDocument的模式表?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:

最新推荐
猜你喜欢