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

Related Questions

I am taking over a project to replace an ancient legacy system from the
I have an implementation of a Spring AbstractHandlerExceptionResolver in my project. This handler takes
I'm trying out the new LayoutTransition class in Honeycomb. I have set an animation
I have a django project that uses a worker process that sends emails to
Is there a translation/localization sub-project for the JEDI Code Library ? I'm especially looking
I've been looking a lot at Clojure recently and I've been wondering if it
Could someone point out the differences between the open64 and llvm? I know that
Even though I'm not a native English speaker, I try to keep my code
Dear Stack Overflow Community, I am a Java programmer in front of a task
working on an old translation sample code for windows phone 7. Recently, I have

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.