Nid*_*ocu 76 wpf pinvoke user-interface resize
WPF不提供允许调整大小但没有最大化或最小化按钮的窗口的功能.我想能够制作这样一个窗口,以便我可以使用可调整大小的对话框.
我知道解决方案意味着使用pinvoke,但我不知道该怎么称呼以及怎么做.一个搜索pinvoke.net的不转了,在我跳了出来,因为我需要什么什么东西,主要是我敢肯定,因为Windows窗体并提供CanMinimize
和CanMaximize
性能上它的窗口.
有人可以指点我或提供代码(C#首选)如何做到这一点?
Mat*_*ton 105
我偷了一些我在MSDN论坛上找到的代码并在Window类上做了一个扩展方法,如下所示:
internal static class WindowExtensions
{
// from winuser.h
private const int GWL_STYLE = -16,
WS_MAXIMIZEBOX = 0x10000,
WS_MINIMIZEBOX = 0x20000;
[DllImport("user32.dll")]
extern private static int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
extern private static int SetWindowLong(IntPtr hwnd, int index, int value);
internal static void HideMinimizeAndMaximizeButtons(this Window window)
{
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle;
var currentStyle = GetWindowLong(hwnd, GWL_STYLE);
SetWindowLong(hwnd, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX));
}
}
Run Code Online (Sandbox Code Playgroud)
唯一要记住的是,由于某种原因,这不适用于窗口的构造函数.通过把它放到构造函数中我解决了这个问题:
this.SourceInitialized += (x, y) =>
{
this.HideMinimizeAndMaximizeButtons();
};
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
Mus*_*o31 84
一种方法是设置你的ResizeMode="NoResize"
.它会表现得像这样.
我希望这有帮助!
Gis*_*shu 21
不知道这是否适用于您的需求.视觉上..这是
<Window x:Class="DataBinding.MyWindow" ...Title="MyWindow" Height="300" Width="300"
WindowStyle="ToolWindow" ResizeMode="CanResizeWithGrip">
Run Code Online (Sandbox Code Playgroud)
如果有人使用Devexpress窗口(DXWindow)接受的答案不起作用.一个丑陋的方法是
public partial class MyAwesomeWindow : DXWindow
{
public MyAwesomeWIndow()
{
Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// hides maximize button
Button button = (Button)DevExpress.Xpf.Core.Native.LayoutHelper.FindElementByName(this, DXWindow.ButtonParts.PART_Maximize.ToString());
button.IsHitTestVisible = false;
button.Opacity = 0;
// hides minimize button
button = (Button)DevExpress.Xpf.Core.Native.LayoutHelper.FindElementByName(this, DXWindow.ButtonParts.PART_Minimize.ToString());
button.IsHitTestVisible = false;
button.Opacity = 0;
// hides close button
button = (Button)DevExpress.Xpf.Core.Native.LayoutHelper.FindElementByName(this, DXWindow.ButtonParts.PART_CloseButton.ToString());
button.IsHitTestVisible = false;
button.Opacity = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
66054 次 |
最近记录: |