美好的一天,
我刚刚开始学习视觉F#,它看起来非常有趣.对于我的第一个项目,我立即制作了一个窗体,从页面下载信息并将其显示在表单上的RichTextBox中.问题是,一旦表单显示并下载信息,它立即关闭.如何让我的杰作保持开放以供观看?有什么建议?
我目前有2个文件:
Program.fs应该"创建"表单,其中Script1.fs只是应用程序的入口点.
Program.fs
namespace Program1
open System.Windows.Forms
module public HelloWorld =
let form = new Form(Visible = true, TopMost = true, Text = "Welcome to F#")
let textB = new RichTextBox(Dock = DockStyle.Fill, Text = "Initial Text")
form.Controls.Add textB
open System.IO
open System.Net
/// Get the contents of the URL via a web request
let http (url: string) =
let req = System.Net.WebRequest.Create(url)
let resp = req.GetResponse()
let stream = resp.GetResponseStream()
let reader = new StreamReader(stream)
let html = reader.ReadToEnd()
resp.Close()
html
textB.Text <- http "http://www.google.com"
Run Code Online (Sandbox Code Playgroud)
Script1.fs
open Program1
[<EntryPoint>]
let main argv=
printfn "Running F# App"
HelloWorld.form.Show();
0
Run Code Online (Sandbox Code Playgroud)
我需要重申一下,我从F#开始.这是我写的第一个应用程序.如何保持表格打开?
您需要调用Application.Run并将表单对象传递给它.http://msdn.microsoft.com/en-us/library/system.windows.forms.application.run(v=vs.110).aspx
这将创建一个消息循环,并使您的应用程序保持活动状态,直到表单关闭.
open Program1
[<EntryPoint>]
let main argv=
printfn "Running F# App"
System.Windows.Forms.Application.Run(HelloWorld.form)
0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
762 次 |
| 最近记录: |