| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Runtime.CompilerServices;
- using System.Windows.Forms;
- using Microsoft.VisualBasic.CompilerServices;
- namespace Dongke.IBOSS.PRD.Framework.Controls
- {
- [DesignerGenerated]
- [Browsable(false)]
- [ToolboxItem(false)]
- [Description("绘制标尺的控件")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public class Ruler : UserControl
- {
- private IContainer components;
- [AccessedThroughProperty("Label1")]
- private Label _Label1;
- private bool myDirection;
- private float myx;
- private float myy;
- private Color myTextColor;
- private Color myLineColor;
- private int MaxWidth;
- private bool myIsUserCentimeter;
- private int mystep;
- internal virtual Label Label1
- {
- get
- {
- return _Label1;
- }
- [MethodImpl(MethodImplOptions.Synchronized)]
- set
- {
- _Label1 = value;
- }
- }
- public bool IsUserCentimeter
- {
- get
- {
- return myIsUserCentimeter;
- }
- set
- {
- myIsUserCentimeter = value;
- ReDrawLable();
- }
- }
- public bool Direction
- {
- get
- {
- return myDirection;
- }
- set
- {
- myDirection = value;
- if (value)
- {
- Label1.TextAlign = ContentAlignment.TopCenter;
- }
- else
- {
- Label1.TextAlign = ContentAlignment.MiddleLeft;
- }
- Refresh();
- }
- }
- public float GetX => myx;
- public float GetY => myy;
- public Color LineColor
- {
- get
- {
- return myLineColor;
- }
- set
- {
- myLineColor = value;
- Refresh();
- }
- }
- public Color TextColor
- {
- get
- {
- return myTextColor;
- }
- set
- {
- myTextColor = value;
- Refresh();
- }
- }
- [DebuggerNonUserCode]
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (disposing && components != null)
- {
- components.Dispose();
- }
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
- [System.Diagnostics.DebuggerStepThrough]
- private void InitializeComponent()
- {
- this.Label1 = new System.Windows.Forms.Label();
- base.SuspendLayout();
- this.Label1.BackColor = System.Drawing.Color.FromArgb(192, 255, 192);
- this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.Label1.Font = new System.Drawing.Font("宋体", 9f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
- this.Label1.ForeColor = System.Drawing.Color.FromArgb(0, 0, 192);
- System.Windows.Forms.Control label = this.Label1;
- System.Drawing.Point location = new System.Drawing.Point(64, -2);
- label.Location = location;
- this.Label1.Name = "Label1";
- System.Windows.Forms.Control label2 = this.Label1;
- System.Drawing.Size size = new System.Drawing.Size(100, 23);
- label2.Size = size;
- this.Label1.TabIndex = 1;
- this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.Label1.Visible = false;
- System.Drawing.SizeF sizeF = new System.Drawing.SizeF(6f, 12f);
- base.AutoScaleDimensions = sizeF;
- base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.Color.White;
- base.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- base.Controls.Add(this.Label1);
- this.Cursor = System.Windows.Forms.Cursors.Default;
- this.DoubleBuffered = true;
- base.Name = "Ruler";
- size = new System.Drawing.Size(263, 31);
- base.Size = size;
- base.ResumeLayout(false);
- }
- public float ConvertToMM(float tt, bool isX)
- {
- if (isX)
- {
- return (float)((double)(tt / myx) * 2.54 * 10.0);
- }
- return (float)((double)(tt / myy) * 2.54 * 10.0);
- }
- public float ConvertToPoint(float tt, bool isx)
- {
- float num = ConvertToMM(tt, isx);
- return (float)((double)(num * 72f) / 25.4);
- }
- public float ConvertToPointFromMM(float tt)
- {
- return (float)((double)(tt * 72f) / 25.4);
- }
- public float ConvertFromMM(float tt, bool isx)
- {
- if (isx)
- {
- return (float)((double)(tt * myx) / 2.54 / 10.0);
- }
- return (float)((double)(tt * myy) / 2.54 / 10.0);
- }
- private void Ruler_Load(object sender, EventArgs e)
- {
- if (base.Controls.Count >= 5)
- {
- ReDrawLable();
- }
- }
- private void ReDrawLable()
- {
- checked
- {
- try
- {
- if (IsUserCentimeter)
- {
- int num = 0;
- int num2 = (int)Math.Round((double)MaxWidth / 10.0);
- for (int i = num; i <= num2; i++)
- {
- Label label = (Label)base.Controls["t" + Conversions.ToString(i)];
- label.Text = Conversions.ToString(i);
- }
- }
- else
- {
- int num3 = 0;
- int num4 = (int)Math.Round((double)MaxWidth / 10.0);
- for (int j = num3; j <= num4; j++)
- {
- Label label2 = (Label)base.Controls["t" + Conversions.ToString(j)];
- label2.Text = Conversions.ToString(j * 10);
- }
- }
- MyRefresh();
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- }
- }
- private void Ruler_Resize(object sender, EventArgs e)
- {
- checked
- {
- if (Direction)
- {
- Label1.Height = (int)Math.Round((double)base.Height / 3.0 * 1.5);
- Label1.Top = base.Height - Label1.Height;
- }
- else
- {
- Label1.Width = (int)Math.Round((double)base.Width / 3.0 * 1.5);
- Label1.Left = base.Width - Label1.Width;
- }
- if (base.Controls.Count >= 5)
- {
- MyRefresh();
- }
- }
- }
- public void MyRefresh()
- {
- int num = 0;
- Label label = null;
- base.Visible = false;
- num = 0;
- Label label2 = null;
- label = null;
- checked
- {
- try
- {
- if (myDirection)
- {
- label = (Label)base.Controls["t0"];
- label.Left = (int)Math.Round(ConvertFromMM(num, isx: true));
- label.Top = 0;
- label.ForeColor = TextColor;
- label.Visible = true;
- label.BringToFront();
- label2 = (Label)base.Controls["l0"];
- label2.SetBounds(0, 0, 1, base.Height);
- label2.Visible = true;
- label2.BringToFront();
- int num2 = mystep;
- int maxWidth = MaxWidth;
- int num3 = mystep;
- for (num = num2; ((num3 >> 31) ^ num) <= ((num3 >> 31) ^ maxWidth); num += num3)
- {
- label2 = (Label)base.Controls["l" + Conversions.ToString(num)];
- label2.Width = 1;
- if (unchecked(num % 10) == 0)
- {
- label2.SetBounds((int)Math.Round(ConvertFromMM(num, isx: true)), 0, 1, base.Height);
- label = (Label)base.Controls["t" + Conversions.ToString((double)num / 10.0)];
- label.Left = (int)Math.Round(ConvertFromMM(num, isx: true));
- label.Top = 0;
- label.ForeColor = TextColor;
- try
- {
- label.Visible = true;
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- label.BringToFront();
- }
- else if (unchecked(num % 5) == 0)
- {
- label2.SetBounds((int)Math.Round(ConvertFromMM(num, isx: true)), (int)Math.Round((float)base.Height - (float)((double)base.Height / 3.0 * 2.0)), 1, (int)Math.Round((double)base.Height / 3.0 * 2.0));
- }
- else
- {
- label2.SetBounds((int)Math.Round(ConvertFromMM(num, isx: true)), (int)Math.Round((float)base.Height - (float)((double)base.Height / 3.0)), 1, (int)Math.Round((double)base.Height / 3.0));
- }
- label2.Visible = true;
- label2.BringToFront();
- }
- }
- else
- {
- label = (Label)base.Controls["t0"];
- label.Top = (int)Math.Round(ConvertFromMM(num, isx: false));
- label.Left = 0;
- label.ForeColor = TextColor;
- label.Visible = true;
- label.BringToFront();
- label2 = (Label)base.Controls["l0"];
- label2.BringToFront();
- label2.SetBounds(0, 0, base.Width, 1);
- label2.Visible = true;
- int num4 = mystep;
- int maxWidth2 = MaxWidth;
- int num5 = mystep;
- for (num = num4; ((num5 >> 31) ^ num) <= ((num5 >> 31) ^ maxWidth2); num += num5)
- {
- label2 = (Label)base.Controls["l" + Conversions.ToString(num)];
- if (unchecked(num % 10) == 0)
- {
- label2.SetBounds(0, (int)Math.Round(ConvertFromMM(num, isx: true)), base.Width, 1);
- label = (Label)base.Controls["t" + Conversions.ToString((double)num / 10.0)];
- label.Top = (int)Math.Round(ConvertFromMM(num, isx: false));
- label.Left = 0;
- label.ForeColor = TextColor;
- label.Visible = true;
- label.BringToFront();
- }
- else if (unchecked(num % 5) == 0)
- {
- label2.SetBounds((int)Math.Round((double)base.Width - (double)base.Width / 3.0 * 2.0), (int)Math.Round(ConvertFromMM(num, isx: true)), (int)Math.Round((double)base.Width / 3.0 * 2.0), 1);
- }
- else
- {
- label2.SetBounds((int)Math.Round((double)base.Width - (double)base.Width / 3.0), (int)Math.Round(ConvertFromMM(num, isx: true)), (int)Math.Round((double)base.Width / 3.0), 1);
- }
- label2.Visible = true;
- label2.BringToFront();
- }
- }
- }
- catch (Exception projectError2)
- {
- ProjectData.SetProjectError(projectError2);
- ProjectData.ClearProjectError();
- }
- base.Visible = true;
- }
- }
- public void SetLableVisible(bool isvisible)
- {
- Label1.Visible = isvisible;
- }
- public void SetLabelPos(float xory, int widthorheight, bool iswidth, float baseheight)
- {
- checked
- {
- if (Direction)
- {
- Label1.SetBounds((int)Math.Round(xory), Label1.Top, widthorheight, Label1.Height);
- }
- else
- {
- Label1.SetBounds(Label1.Left, (int)Math.Round(baseheight + xory), Label1.Width, widthorheight);
- }
- try
- {
- Label1.Refresh();
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- }
- }
- public Ruler()
- {
- base.Load += Ruler_Load;
- base.Resize += Ruler_Resize;
- myDirection = true;
- myTextColor = Color.Red;
- myLineColor = Color.Blue;
- MaxWidth = 500;
- myIsUserCentimeter = true;
- mystep = 10;
- InitializeComponent();
- SetStyle(ControlStyles.UserPaint, value: true);
- SetStyle(ControlStyles.AllPaintingInWmPaint, value: true);
- SetStyle(ControlStyles.OptimizedDoubleBuffer, value: true);
- UpdateStyles();
- myx = CreateGraphics().DpiX;
- myy = CreateGraphics().DpiY;
- Label1.SendToBack();
- int num = 0;
- int maxWidth = MaxWidth;
- int num2 = mystep;
- checked
- {
- for (int i = num; ((num2 >> 31) ^ i) <= ((num2 >> 31) ^ maxWidth); i += num2)
- {
- Label label = new Label();
- label.Visible = false;
- label.SetBounds(0, 10, 1, 1);
- label.Text = "";
- label.Name = "l" + Conversions.ToString(i);
- label.BorderStyle = BorderStyle.FixedSingle;
- base.Controls.Add(label);
- label.BringToFront();
- }
- int num3 = 0;
- int num4 = (int)Math.Round((double)MaxWidth / 10.0);
- for (int i = num3; i <= num4; i++)
- {
- Label value = new Label
- {
- Visible = false,
- Left = 0,
- AutoSize = true,
- Text = Conversions.ToString(i),
- Name = "t" + Conversions.ToString(i),
- BorderStyle = BorderStyle.None
- };
- base.Controls.Add(value);
- }
- try
- {
- MyRefresh();
- }
- catch (Exception projectError)
- {
- ProjectData.SetProjectError(projectError);
- ProjectData.ClearProjectError();
- }
- }
- }
- }
- }
|