Winforms 在F中以Windows窗体绘制#

Winforms 在F中以Windows窗体绘制#,winforms,f#,drawing,Winforms,F#,Drawing,我试图在F#中绘制一个非定制的(我的意思是,只创建一个默认表单类的实例,而不是我可以创建的派生类的实例)System.Windows.Forms.form 我已经创建了一个自定义表单,但我不需要也不想要这样一个新的复杂结构,所以我删除了它,它大大简化了代码;如此之多,以至于它停止显示图像 问题一定出在我为绘制而创建的函数中,即在另一个F#项目中。我创建了它(函数conect)来按照提供的顺序连接点,而不像系统.Drawing.Graphics.drawines,它以其他顺序在点之间绘制线,为什么

我试图在F#中绘制一个非定制的(我的意思是,只创建一个默认表单类的实例,而不是我可以创建的派生类的实例)
System.Windows.Forms.form

我已经创建了一个自定义表单,但我不需要也不想要这样一个新的复杂结构,所以我删除了它,它大大简化了代码;如此之多,以至于它停止显示图像

问题一定出在我为绘制而创建的函数中,即在另一个F#项目中。我创建了它(函数
conect
)来按照提供的顺序连接点,而不像
系统.Drawing.Graphics.drawines
,它以其他顺序在点之间绘制线,为什么还没有注意到(可能是从右到左,从上到下,如点所示)

Programa.fs相关代码段:

let pen = new Pen(brush = Brushes.Black, width = 1.0f)
let original =            
    ([|new PointF(50.0f, 50.0f); new PointF(100.0f, 50.0f)|])

use form1 = new Form(Width = 400, Height = 400, Text = "Fractais (Teste - Windows Forms)")

form1.Paint.Add(
    fun e -> // (1)
        original
        |> List.ofArray        
        |> Base.applyFractal 1uy Base.fractalFunc1
        |> Base.conect e.Graphics pen)
如果在lambda表达式中,而不是所写的表达式中有
e.Graphics.DrawLines(钢笔,原版)
,则它将在列表中的点之间绘制一条简单的线

下面是整个解决方案中Base.fs中的麻烦制造者方法:

let conect (gr:Graphics) (pen:Pen) (points:PointF list) =
    let rec usefulFunc (gr:Graphics) (pen:Pen) (points:PointF list) prevPoint =
        match points with
        | [] -> ()
        | point :: remainings ->                
            gr.DrawLine (pen, prevPoint, point)
            usefulFunc gr caneta remainings.Tail remainings.Head
    usefulFunc gr pen points.Tail points.Head
以及Base.fsi中调用的(来自表单初始化代码段)和相关方法的签名(我可以为您提供所有完整方法的实现,但这将占用大量空间,这可能已经成为一个很长的问题):

对于这个特定的问题,我的搜索结果是无。我想知道如何使函数
conect
工作


提前感谢。

您在conectar中有一个错误

fUtil gr caneta resto.Tail resto.Head
应该是

fUtil gr caneta resto ponto
您已经在匹配语句中匹配了头和尾

下面的代码为我画了一条线。我不需要修改太多

open System.Drawing
open System.Windows.Forms

let caneta = new Pen(brush = Brushes.Black, width = 1.0f)
let original =            
    ([|new PointF(50.0f, 50.0f); new PointF(100.0f, 50.0f)|])

let form1 = new Form(Width = 400, Height = 400, Text = "Fractais (Teste - Windows Forms)")

let conectar (gr:Graphics) (caneta:Pen) (pontos:PointF list) =
    let rec fUtil (gr:Graphics) (caneta:Pen) (pontos:PointF list) pontoAnt =
        match pontos with
        | [] -> ()
        | ponto :: resto ->                
            gr.DrawLine (caneta, pontoAnt, ponto)
            fUtil gr caneta resto ponto
    fUtil gr caneta pontos.Tail pontos.Head

form1.Paint.Add(
    fun e -> // (1)
        original
        |> List.ofArray        
        //|> aplicFractal 1uy Base.funcFractal1
        |> conectar e.Graphics caneta)

form1.Show()

Application.Run(form1)

你确定在
Base.aplicFractal 1y Base.funcfractal 1
中进行的计算返回了点的正确位置吗。在瓦里瓦维的名字中,以塔姆·瓦伊斯·埃斯特兰哈尔·巴斯坦特(também vais estranhar bastante)的名字为例o@TomasPetricek,确实有一个错误(你是怎么猜到的?)在方法内部,有两个值叫做
theta0
theta00
(这些类似的可能未被推荐的名称有很长的解释),用于在笛卡尔坐标系中变换极坐标。不过现在已经更正了,
System.Drawing.Graphics.drawines
确实有效。@GustavoGuerra,agora,com o Google Tradutor,nãhátanto problema,特别是porque este códigoésimples,e os nomes pouco relates。这是一个非常好的方式,他妈的!我知道这是某种愚蠢的错误,我就是找不到地方!谢谢你指出这一点,从而回答了我的问题。
open System.Drawing
open System.Windows.Forms

let caneta = new Pen(brush = Brushes.Black, width = 1.0f)
let original =            
    ([|new PointF(50.0f, 50.0f); new PointF(100.0f, 50.0f)|])

let form1 = new Form(Width = 400, Height = 400, Text = "Fractais (Teste - Windows Forms)")

let conectar (gr:Graphics) (caneta:Pen) (pontos:PointF list) =
    let rec fUtil (gr:Graphics) (caneta:Pen) (pontos:PointF list) pontoAnt =
        match pontos with
        | [] -> ()
        | ponto :: resto ->                
            gr.DrawLine (caneta, pontoAnt, ponto)
            fUtil gr caneta resto ponto
    fUtil gr caneta pontos.Tail pontos.Head

form1.Paint.Add(
    fun e -> // (1)
        original
        |> List.ofArray        
        //|> aplicFractal 1uy Base.funcFractal1
        |> conectar e.Graphics caneta)

form1.Show()

Application.Run(form1)