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(); } } } } }