Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 610451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:40:36+00:00 2026-05-13T17:40:36+00:00

I am translating a C# project into F#. While the logic part is easy,

  • 0

I am translating a C# project into F#. While the logic part is easy, I am confused with the GUI part:

public partial class GomokuGUI : Form {
    private void GomokuGUI_Load(object sender, EventArgs e)
    {
        this.Width = 500;
        this.Height = 550;
        ...
        this.Paint += new PaintEventHandler(GomokuGUI_Paint);
        Graphics gp = this.CreateGraphics();
        DrawChessbord(gp); 
    }

    private void GomokuGUI_Paint(object sender, PaintEventArgs e)
    {
        Graphics gp = e.Graphics;
        DrawChessbord(gp);
    }

    void DrawChessbord(Graphics gp)
    {
        float w, h;
        SolidBrush br = new SolidBrush(linecolor);
        Pen p = new Pen(br, frame);
        gp.DrawLine(p, 20, 45, this.Width - 25, 45);
  ...
    }

   private void Form1_Click(object sender, EventArgs e) {
          Graphics gp = this.CreateGraphics();
                DrawChess(gp);
     ...
}
}

Problem: How to write above C# code in F#…Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:40:37+00:00Added an answer on May 13, 2026 at 5:40 pm

    Note that F# doesn’t have any WinForms designer, so if you have some controls in the Form, you’ll need to create them manually (alternatively you can design the form in C#, compile it and reference it from F#). You could start with something like this:

    type GomokuGUI() as this =
      inherit Form(Width = 300, Height = 550)
    
      let DrawChessbord (gp:Graphics) =
        let br = new SolidBrush(linecolor)
        let p = new Pen(br, frame)
        gp.DrawLine(p, 20, 45, this.Width - 25, 45)
        // ...
    
      let paintGui (e:PaintEventArgs) =
        let gp = e.Graphics
        DrawChessbord(gp)
    
      do 
        this.Paint.Add(paintGui)
        this.Click.Add(fun _ ->
          let gp = this.CreateGraphics()
          DrawChess(gp) 
          (* ... *) )
    

    It uses a couple of interesting things:

    • You can specify some parameters such as Width and Height in the constructor when calling the base class constructor.
    • You need to use as this in the class declaration, so that you can refer to the class in the do code (which is run during construction)
    • You can use Add to register event handler and you can either give it a named function (e.g. patinGui) or a lambda function if you need to do only some simple call (e.g. handling of Click)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 307k
  • Answers 307k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer 1: -sh-3.00$ ps auxww|egrep "(http|apache)" root 8074 0.0 0.3 14236… May 13, 2026 at 9:33 pm
  • Editorial Team
    Editorial Team added an answer I would recommend following approach which I feel is simple… May 13, 2026 at 9:33 pm
  • Editorial Team
    Editorial Team added an answer Instead of doing that you can use the framwework System.Drawing.Text.InstalledFontCollection… May 13, 2026 at 9:33 pm

Related Questions

I'm working on a homework assignment translating a C program we wrote to MIPS.
I have been puzzling over a problem this morning with LinqToSQL. I'll try and
I'm currently on a VB.NET project and wish to use a KeyValuePair to facilitate
Does anyone know the specifics of how to embed the Mono runtime in a
Has anyone come across a framework or library for Delphi to simplify the generation

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.