[英]How to hide close button with WPF & F#
I'm posting this question and i hope to find out the responds. 我发布了这个问题,我希望找到答案。 My question is: How can i make the code below functional in F# : 我的问题是:如何在F#中使代码功能正常:
First, add these declarations to your Window class: 首先,将这些声明添加到Window类:
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
Then put this code in the Window's Loaded event: 然后将此代码放入Window的Loaded事件中:
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
Translation code from tom.maruska to F# will look as follows: 从tom.maruska到F#的翻译代码如下:
type HideCloseButtonOnWindow() =
inherit Behavior<Window>()
let GWL_STYLE = -16;
let WS_SYSMENU = 0x80000;
[<DllImport("user32.dll", SetLastError = true)>]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[<DllImport("user32.dll")>]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
override x.OnAttached() =
base.OnAttached()
x.AssociatedObject.Loaded.AddHandler(fun s e -> x.OnLoaded(s,e))
override x.OnDetaching() =
x.AssociatedObject.Loaded.RemoveHandler(fun s e -> x.OnLoaded(s,e))
base.OnDetaching()
member x.OnLoaded(sender:obj, e:RoutedEventArgs) =
let hwnd = (new WindowInteropHelper(x.AssociatedObject)).Handle
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) &&& ~~~WS_SYSMENU)
|> ignore
You should open: 你应该打开:
open System.Windows.Interactivity
open System.Runtime.InteropServices
open System.Windows.Interop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.