C# cad secondary development class library dialog box to add the frame interface to the class library

C# cad secondary development class library dialog box to add the frame interface to the class library

using System;
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;

namespace_19 dialog example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

 private void Form1_Load(object sender, EventArgs e)
    {
        this. DrawEentity();
    }

    //Function to draw graphics
    private void DrawEentity()
    {
        int width = picBxDrawMap. Width;
        int height = picBxDrawMap. Height;
        Bitmap bitmap = new Bitmap(width, height);//Create a bitmap object
        Graphics graph = Graphics.FromImage(bitmap); //Create a GDI + object from a bitmap
        Rectangle rect = new Rectangle((int)(width * 0.15), (int)(height * 0.15), (int)(width * 0.8), (int)(height * 0.8));
        
        
        // draw graphics
        Rectangle rectExtends = this.DrawLineAndArc(bitmap, graph, rect);
        // draw annotation
        this.DrawDimension(bitmap, graph, rectExtends);
        //graph.DrawRectangle(new Pen(Brushes.Red), rect);
        picBxDrawMap. Image = bitmap;

    }
    private Rectangle DrawLineAndArc(Bitmap bitmap, Graphics graph, Rectangle rect)
    {
        double ratio = rect.Width * 1.0 / rect.Height;
        double width = (double)numUDlength.Value;//rectangle width
        double height = (double)numUDheight.Value;//height of the rectangle
        Pen pen = new Pen(Brushes. Black);
        Point topLineLeftPoint;
        Point topLineRightPoint;
        Point rightLineTopPoint;
        Point rightLineBottomPoint;
        Point bottomLineLeftPoint;
        Point bottomLineRightPoint;
        Point leftLineTopPoint;
        Point leftLineBottomPoint;
        if (width/height >= ratio)
        {
            //Occupy the drawing area with the length, draw the height and arc proportionally
           // width => rect.Width height = height * rect.Width/wdith
            height = height* rect. Width/width;
            int divHeight = (int)(rect. Height - height)/2;
            topLineLeftPoint = new Point(rect.X, rect.Y + divHeight);
            topLineRightPoint = new Point(rect.X + rect.Width, rect.Y + divHeight);
            rightLineTopPoint = topLineRightPoint;
            rightLineBottomPoint = new Point(rect.X + rect.Width, rect.Y + rect.Height- divHeight);
            bottomLineLeftPoint = new Point(rect.X, rect.Y + rect.Height - divHeight);
            bottomLineRightPoint = rightLineBottomPoint;
            leftLineTopPoint = topLineLeftPoint;
            leftLineBottomPoint = bottomLineLeftPoint;
        }
        else
        {
            //Occupy the drawing area with height, draw length and arc proportionally
            width = width * rect. Height / height;
            int divWidth = (int)(rect.Width - width) / 2;
            topLineLeftPoint = new Point(rect. X + divWidth, rect. Y);
            topLineRightPoint = new Point(rect.X + rect.Width - divWidth, rect.Y);
            rightLineTopPoint = topLineRightPoint;
            rightLineBottomPoint = new Point(rect.X + rect.Width - divWidth, rect.Y + rect.Height);
            bottomLineLeftPoint = new Point(rect. X + divWidth, rect. Y + rect. Height);
            bottomLineRightPoint = rightLineBottomPoint;
            leftLineTopPoint = topLineLeftPoint;
            leftLineBottomPoint = bottomLineLeftPoint;

        }
        // draw the top line
        graph.DrawLine(pen, topLineLeftPoint, topLineRightPoint);
        // draw the bottom line
        graph.DrawLine(pen, bottomLineLeftPoint, bottomLineRightPoint);
        // draw left line
        graph.DrawLine(pen, leftLineTopPoint, leftLineBottomPoint);
        // draw the right line
        graph.DrawLine(pen, rightLineTopPoint, rightLineBottomPoint);
        Rectangle rectExtends = new Rectangle(topLineLeftPoint.X,topLineLeftPoint.Y,topLineRightPoint.X-topLineLeftPoint.X,leftLineBottomPoint.Y-leftLineTopPoint.Y);
        return rectExtends;

    }
    /// <summary>
    /// draw annotation
    /// </summary>
    /// <param name="bitmap"></param>
    /// <param name="graph"></param>
    /// <param name="rect"></param>
    private void DrawDimension(Bitmap bitmap,Graphics graph,Rectangle rect)
    {
        int width = picBxDrawMap. Width;
        int height = picBxDrawMap. Height;
        Pen pen = new Pen(Brushes. LawnGreen);
        string strW = numUDlength.Value.ToString();//Note text in the horizontal direction
        string strH = numUDheight.Value.ToString();//Note text in the vertical direction
         //Annotation text for radius
        #region //Annotation line of horizontal length
        //Point pointHL1 = new Point(rect.X,(int)(height * 0.05));
        //Point pointHL2 = new Point(rect.X,(int)(height * 0.14));
        Point pointHL1 = new Point(rect.X, (int)(height * 0.05));
        Point pointHL2 = new Point(rect.X,rect.Y-4);
        Point pointHR1 = new Point(rect.X + rect.Width, (int)(height * 0.05));
        Point pointHR2 = new Point(rect.X + rect.Width, rect.Y - 4);
        Point PointHH1 = new Point(rect.X, (int)(height * 0.08));
        Point PointHH11 = new Point(rect.X + rect.Width / 2 - 12 * (strW.Length / 2)-6, (int)(height * 0.08));
        Point PointHH2 = new Point(rect.X + rect.Width / 2 + 12 * (strW.Length / 2) + 8, (int)(height * 0.08));
        Point PointHH21 = new Point(rect.X + rect.Width, (int)(height * 0.08));
        graph.DrawString(strW, new Font("宋体", 12), Brushes.LawnGreen, rect.X + rect.Width / 2-12*(strW.Length/2), (int)(height * 0.08)-8 );
        graph.DrawLine(pen, pointHL1, pointHL2);//Left heald line of horizontal label
        graph.DrawLine(pen, pointHR1, pointHR2);//Horizontally labeled left and right heddles
        graph.DrawLine(pen, PointHH1, PointHH11);//The first horizontal line
        graph.DrawLine(pen, PointHH2, PointHH21);//The second horizontal line
        //left arrow
        graph.DrawLine(pen, PointHH1, new Point(PointHH1.X + 12, PointHH1.Y - 3));
        graph.DrawLine(pen, PointHH1, new Point(PointHH1.X + 12, PointHH1.Y + 3));
        //right arrow
        graph.DrawLine(pen, PointHH21, new Point(PointHH21.X - 12, PointHH1.Y - 3));
        graph.DrawLine(pen, PointHH21, new Point(PointHH21.X - 12, PointHH1.Y + 3));

        
        #endregion
        
        #region //Annotation for vertical height
        Point pointVT1 = new Point((int)(width * 0.05), rect.Y);
        Point pointVT2 = new Point(rect.X-4, rect.Y);
        graph.DrawLine(pen,pointVT1, pointVT2); // vertically annotate the horizontal line above
        Point pointVB1 = new Point((int)(width * 0.05), rect. Y + rect. Height);
        Point pointVB2 = new Point(rect.X - 4, rect.Y + rect.Height);
        graph.DrawLine(pen, pointVB1, pointVB2); // horizontal line below the vertical annotation
        graph.DrawString(strH, new Font("宋体", 12), Brushes.LawnGreen,(int)(width * 0.08)-strH.Length*10/2, rect.Y + rect.Height / 2 - 8); //Comment text in vertical direction
        Point pointVV1 = new Point((int)(width * 0.08), rect.Y);
        Point pointVV11 = new Point((int)(width * 0.08), rect.Y + rect.Height/2-8);
        Point pointVV2 = new Point((int)(width * 0.08), rect. Y + rect. Height / 2 + 8);
        Point pointVV21 = new Point((int)(width * 0.08), rect. Y + rect. Height);
        graph.DrawLine(pen, pointVV1, pointVV11); // Vertically annotate the first line
        graph.DrawLine(pen, pointVV2, pointVV21); // vertically annotate the second line
        //up arrow
        graph.DrawLine(pen, pointVV1, new Point(pointVV1.X - 3, pointVV1.Y + 12));
        graph.DrawLine(pen, pointVV1, new Point(pointVV1.X + 3, pointVV1.Y + 12));
        // arrow below
        graph.DrawLine(pen, pointVV21, new Point(pointVV21.X - 3, pointVV21.Y - 12));
        graph.DrawLine(pen, pointVV21, new Point(pointVV21.X + 3, pointVV21.Y - 12));
        #endregion

        //radius comment

        // draw the center line
        #region
        double lengthDiv = (rect. Height + 10) / 39;
        Point firstPoint = new Point(rect. X + rect. Width / 2, rect. Y - 5);
        Point endPoint = new Point((int)(rect.X + rect.Width / 2), (int)(firstPoint.Y + 2 * lengthDiv));
        for (int i = 0; i < 20; i ++ )
        {
            graph.DrawLine(new Pen(Brushes.PaleVioletRed), firstPoint, endPoint);
            firstPoint.Y = endPoint.Y + (int)lengthDiv;
            endPoint = new Point((int)(rect.X + rect.Width / 2), (int)(firstPoint.Y + 2 * lengthDiv));
        }

        lengthDiv = (rect. Width + 10) / 39;
        firstPoint = new Point((int)(rect.X-5),(int)(rect.Y + rect.Height/2));
        endPoint = new Point((int)(firstPoint.X + lengthDiv), (int)(rect.Y + rect.Height / 2));
         for (int i = 0; i < 22; i ++ )
        {
            graph.DrawLine(new Pen(Brushes.PaleVioletRed), firstPoint, endPoint);
            firstPoint.X = endPoint.X + (int)lengthDiv;
            endPoint = new Point((int)(firstPoint.X + lengthDiv), (int)(rect.Y + rect.Height / 2));
        }
        #endregion



    }

    private void numUDlength_ValueChanged(object sender, EventArgs e)
    {
        this. DrawEentity();
    }

    private void numUDheight_ValueChanged(object sender, EventArgs e)
    {
        this. DrawEentity();
    }
}

}