During this time, I was busy studying WinForm's scale and grid. The supervisor asked me to do the same thing as PowerDesigner. After some time of research, practice, and modification, I finally reached the standard. The Code is as follows.
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Drawing;
Using System. Data;
Using System. Text;
Using System. Windows. Forms;
Using System. Drawing. PRinting;
Using System. Drawing. Drawing2D;
// Calculate the screen pixel size and mm size reference
Using System. Runtime. InteropServices;
Namespace UntilityControl
{
Public partial class RuleAndGrid: UserControl
{
Public Control useControl;
Private TextBox lineX = new TextBox ();
Private TextBox lineY = new TextBox ();
Private TextBox rectangleX = new TextBox ();
Private TextBox rectangleY = new TextBox ();
Pen penG = new Pen (Color. Black );
Pen penL = new Pen (Color. Red );
Font font = new Font ("", 8 );
Public RuleAndGrid ()
{
InitializeComponent ();
}
Public Panel panel1 = new Panel ();
// Number of workers per millimeter
Float pxwidth;
Private void RulerAndGrid_Paint (object sender, PaintEventArgs e)
{
Graphics PenGraphics = e. Graphics;
InitializeGraph (PenGraphics );
}
Private void RulerAndGrid_Load (object sender, EventArgs e)
{
Panel1.Left = 21;
Panel1.Top = 21;
Panel1.Width = RulerWidth-42;
Panel1.Height = RulerHeight-42;
Panel1.BackColor = Color. White;
Panel1.MouseMove + = new MouseEventHandler (panel?mousemove );
Panel1.MouseUp + = new MouseEventHandler (panel+mouseup );
Panel1.Paint + = new PaintEventHandler (panel+paint );
LineX. Width = 1;
LineX. Height = 14;
LineX. Top = 6;
LineX. BackColor = Color. Red;
LineX. Multiline = true;
LineX. Visible = false;
This. Controls. Add (lineX );
LineY. Width = 14;
LineY. Height = 1;
LineY. Left = 6;
LineY. BackColor = Color. Red;
LineY. Multiline = true;
LineY. Visible = false;
This. Controls. Add (lineY );
RectangleX. Height = 6;
RectangleX. Top = 14;
RectangleX. BackColor = Color. Black;
RectangleX. Multiline = true;
RectangleX. Visible = false;
This. Controls. Add (rectangleX );
RectangleY. Width = 6;
RectangleY. Left = 14;
RectangleY. BackColor = Color. Black;
RectangleY. Multiline = true;
RectangleY. Visible = false;
This. Controls. Add (rectangleY );
This. Controls. Add (panel1 );
Calcsale ();
}
Private void panelappspaint (object sender, PaintEventArgs e)
{
DrawGrid ();
}
Private void panelappsmouseup (object sender, MouseEventArgs e)
{
If (e. Button = MouseButtons. Right)
{
SetProperty sp = new SetProperty ();
Sp. rad = this;
Sp. ShowDialog ();
}
Else
{
If (useControl! = Null)
{
UseControl. MouseClick + = new MouseEventHandler (useControl_MouseClick );
UseControl. Top = e. Y;
UseControl. Left = e. X;
Panel1.Controls. Add (useControl );
Panel1.Cursor = Cursors. Default;