C # Powerful WinForm ruler and grid

Source: Internet
Author: User

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.