我想知道mouseWheel事件在winforms库中是如何工作的。
虽然在2017-01-18 18:10:09.397565 sound attempt 2[533:124220] [DYMTLInitPlatform] platform initialization successful
2017-01-18 18:10:11.058506 sound attempt 2[533:124042] Metal GPU Frame Capture Enabled
2017-01-18 18:10:11.059146 sound attempt 2[533:124042] Metal API Validation Enabled
error: use of undeclared identifier '$r0'
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
我希望你们其中一个人能告诉我。
我正在考虑这样的事情:F#
我知道这是我发布的一些愚蠢的代码,但我确实无法在winforms mousewheelevent上找到任何东西,除了它存在。它的工作原理仍然是一个谜。
提前感谢。
答案 0 :(得分:6)
尝试在f#interactive中运行此功能(由fssnip from Tomas Petricek上的类似示例提供):
open System.Windows.Forms
// Create form, label and add label to form
let form = new Form(Text = "Scroller Test")
let label = new Label()
form.Controls.Add(label)
// register mousewheel event handler and capture scrolling
form.MouseWheel.Add(fun e ->
match e.Delta with
| n when n > 0 -> label.Text <- "Scrolled up"
| n when n < 0 -> label.Text <- "Scrolled down"
| _ -> ()) // making compiler happy even though e.Delta cannot be 0
// Show the form (in F# Interactive)
form.Show()
答案 1 :(得分:4)
如果您正在使用F#interactive,那么您可以编写的最简单的方法来测试MouseWheel
事件的行为方式如下:
open System.Windows.Forms
let frm = new Form(Visible=true)
frm.MouseWheel.Add(fun e ->
printfn "%A" e.Delta
)
当您选择代码并将其发送到F#Interactive(大多数F#编辑器中的 Alt + Enter )时,您应该会看到一个表单。当您滚动时,您会看到Delta
为负数或余量数字,表示您滚动了多少向上或向下。
如果您想将其作为独立应用程序运行,您需要在其他位置显示数字(我猜是使用标签),您需要在末尾添加Application.Run(frm)
以启动应用程序
我同意Anton的看法,WinForms可能不是大多数人用来开发用户界面应用程序的东西,但我认为这不是问题 - 你可以使用WinForms构建完美的应用程序并学习F#。 F# book I wrote some time ago有一堆WinForms示例。