Example code using graphics

Hi how are you all I’m using MapWings 5.3 with higher instruction in Frameworks 4.8 with C# 9 integrated could put the 11 in your code and change to high level instructions, it’s just an instruction.Here I am sharing my experience with everyone to boost your Mapwingis to Gdi plus or +
I am not entirely sure if that’s the snippet of code which produces the top-level statement error. Top-level statement errors usually come from, typically Program.cs, or the code file that contains the Main method.

Top-level statements were introduced with C# 9: MSDN - Top-level statements

In order to enable C# 9.0 in your project, you need to edit your .csproj file and add the following:

<PropertyGroup>
   <LangVersion>9.0</LangVersion>
</PropertyGroup>

Alternatively, you can use the following configuration to target the latest C# version, currently 10.0:

<PropertyGroup>
   <LangVersion>latest</LangVersion>
</PropertyGroup>

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp2.Entities;
using WindowsFormsApp2.Methods;

namespace WindowsFormsApp2
{
public partial class formgraphics : Form
{
public formgraphics()
{
InitializeComponent();
INIT();
}
#region DPI / Pixel /WordPoint
//Get screen DPI
private float DPI
{
get
{
using (var g = CreateGraphics())
return g.DpiX;
}
}
//Convert pixel to milimeters
private float Pixel_to_Mn(float pixel)
{
return pixel * 25.4f / DPI;
}
//Convert system point to word point
private Vector3 PointToCartesian(System.Drawing.Point point)
{
return new Vector3(Pixel_to_Mn(point.X) / (Pixel_to_Mn(point.Y) / Height));
}

    #endregion

    #region Move movObj
    private System.Windows.Forms.Point Firstpoint = new System.Windows.Forms.Point();
    public void INIT()
        {
        movObj.MouseDown += (ss, ee) =>
        {
            if (ee.Button == System.Windows.Forms.MouseButtons.Left) { Firstpoint = Control.MousePosition; }
        };
        movObj.MouseMove += (ss, ee) =>
        {
            if (ee.Button == System.Windows.Forms.MouseButtons.Left)
                {
                System.Windows.Forms.Point temp = Control.MousePosition;
                System.Windows.Forms.Point res = new System.Drawing.Point(Firstpoint.X - temp.X, Firstpoint.Y - temp.Y);
                movObj.Location = new System.Drawing.Point(movObj.Location.X - res.X, movObj.Location.Y - res.Y);
                Firstpoint = temp;
                }
        };
        }

    #endregion

    #region Exite Apllication
    private void fecharToolStripMenuItem_Click(object sender, EventArgs e)
        {
        Application.Exit();
        }
    #endregion

    #region ContextMenus
    private void contextMenuStrip2_Opening(object sender, CancelEventArgs e)
        {

        }

    private void contextMenuStrip9_Opening(object sender, CancelEventArgs e)
        {

        }
    #endregion

    #region "Variables"
    //  Lists
    private List<Entities.Point> points = new List<Entities.Point>();
    private List<Entities.Line> lines = new List<Entities.Line>();
    private List<Entities.Circle> circles = new List<Entities.Circle>();
    private List<Entities.Ellipse> ellipses = new List<Entities.Ellipse>();
    private List<Entities.Arc> arcs = new List<Entities.Arc>();
    private List<Entities.LwPolyline> polylines = new List<Entities.LwPolyline>();
    private LwPolyline temPolyline = new LwPolyline();
    //  vector3    
    private Vector3 currentPosition;
    private Vector3 firstPoint;
    private Vector3 secondPoint;
    // int
    private int DrawIndex = -1;
    private int ClickNum = 1;
    private int direction;
    // float

    //bool
    private bool active_drawing = false;
    #endregion

    #region MouseDown Events

    private void axMap1_MouseDownEvent(object sender, MouseEventArgs E, AxMapWinGIS._DMapEvents_MouseDownEvent e)
        {
        if (E.Button == MouseButtons.Left && active_drawing)
            {
            if (active_drawing)
                {
                switch (DrawIndex)
                    {
                    case 0://Point
                        points.Add(new Entities.Point(currentPosition));
                        break;
                    case 1://line
                        switch (ClickNum)
                            {
                            case 1:
                                firstPoint = currentPosition;
                                points.Add(new Entities.Point(currentPosition));
                                ClickNum++;
                                break;
                            case 2:
                                lines.Add(new Entities.Line(firstPoint, currentPosition));
                                points.Add(new Entities.Point(currentPosition));
                                firstPoint = currentPosition;
                                break;
                            }
                        break;
                    case 2:// circle
                        switch (ClickNum)
                            {
                            case 1:
                                firstPoint = currentPosition;
                                ClickNum++;
                                break;
                            case 2:
                                double r = firstPoint.DistanciaFrom(currentPosition);
                                circles.Add(new Entities.Circle(firstPoint, r));
                                ClickNum = 1;
                                break;
                            }
                        break;
                    case 3:// ellipse
                        switch (ClickNum)
                            {
                            case 1:
                                firstPoint = currentPosition;
                                ClickNum++;
                                break;
                            case 2:
                                secondPoint = currentPosition;
                                ClickNum++;
                                break;
                            case 3:
                                Entities.Ellipse ellipse = Methods.Methods.GetEllipse(firstPoint, secondPoint, currentPosition);
                                ellipses.Add(ellipse);
                                ClickNum = 1;
                                active_drawing = false;
                                axMap1.Cursor = Cursors.Default;
                                break;
                            }
                        break;

                        #endregion



                    }
                }
            }
        }

    private void axMap1_MouseDownEvent(object sender, AxMapWinGIS._DMapEvents_MouseDownEvent e,System.Drawing.Graphics g, PaintEventArgs E)

        {
            {
            E.Graphics.SetParameters( Pixel_to_Mn(axMap1.Height));
            Pen pen = new Pen(Color.Blue, 0);
            Pen extpen = new Pen(Color.Gray, 0);
            extpen.DashPattern = new float[] { 1.0f, 2.0f };

            //Draw all points
            if (points.Count > 0)
                {
                foreach (Entities.Point p in points)
                    {
                    E.Graphics.DrawPoint(new Pen(Color.Red, 0.1f), p);
                    }
                }
            // Draw all lines
            if (lines.Count > 0)
                {
                foreach (Entities.Line l in lines)
                    {
                   E.Graphics.DrawLine(pen, l);
                    }
                }
            //Draw all Circle
            if (circles.Count > 0)
                {
                foreach (Entities.Circle c in circles)
                    {
                    E.Graphics.DrawCircle(pen, c);
                    }
                }
            // Draw all ellipse
            if (ellipses.Count > 0)
                {
                foreach (Entities.Ellipse elp in ellipses)
                    {
                    E.Graphics.DrawEllipse(pen, elp);
                    }
                }
            //Draw all arcs
            if (arcs.Count > 0)
                {
                foreach (Arc a in arcs)
                    {
                    E.Graphics.DrawArc(pen, a);
                    }
                }
            //Draw all Polyline
            if (polylines.Count > 0)
                {
                foreach (LwPolyline lw in polylines)
                    {
                    E.Graphics.DrawLwPolyline(pen, lw);
                    }
                }
            //Draw line extended
            }
        }
}