• 大小: 50KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: 毫米刻度  像素刻度  

资源简介

使用C# 实现刻度尺,尺子上方刻度为像素,下方刻度为毫米,使用VS2013 编译,尺子是半透明的。dpi是写成固定的,没继续深入进去,一般情况可用

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BeautifulRuler
{
    public partial class Ruler : Form
    {
        private ToolTip   _toolTip = new ToolTip();
        private Point   _offset;
        private Rectangle  _mouseDownRect;
        private int    _resizeBorderWidth = 5;
        private Point   _mouseDownPoint;
        private ResizeRegion _resizeRegion = ResizeRegion.None;
        private ContextMenu  _menu = new ContextMenu();
        private MenuItem  _verticalMenuItem;
        private MenuItem  _toolTipMenuItem;
        private static bool showWidth = true;

        #region ResizeRegion enum
        private enum ResizeRegion
        {
            None N NE E SE S SW W NW
        }
        #endregion

        public Ruler()
        {
            _toolTipMenuItem = new MenuItem();
            _verticalMenuItem = new MenuItem();

            InitializeComponent();

            ResourceManager resources = new ResourceManager(typeof(Ruler));
            Icon = ((Icon)(resources.Getobject(“$this.Icon“)));

            SetUpMenu();

            Text = “Ruler“;
            BackColor = Color.White;
            ClientSize = new Size(400 75);
            FormBorderstyle = FormBorderstyle.None;
            Opacity = 0.75;
            ContextMenu = _menu;
            Font = new Font(“Tahoma“ 10);

   
            Setstyle(Controlstyles.DoubleBuffer | Controlstyles.UserPaint | Controlstyles.AllPaintingInWmPaint true);
            this.TopMost = true;
        }


        private bool IsVertical
        {
            get { return _verticalMenuItem.Checked; }
            set { _verticalMenuItem.Checked = value; }
        }

        private bool ShowToolTip
        {
            get { return _toolTipMenuItem.Checked; }
            set
            {
                _toolTipMenuItem.Checked = value;
                if (value)
                {
                    SetToolTip();
                }
            }
        }

        private void SetUpMenu()
        {
            AddMenuItem(“保持最顶层“);
            _verticalMenuItem = AddMenuItem(“竖向尺子“);
            _toolTipMenuItem = AddMenuItem(“工具提示“);

            //默认光标停留时显示尺寸大小
            _toolTipMenuItem.Checked = true;

            MenuItem opacityMenuItem = AddMenuItem(“透明度“);
            AddMenuItem(“-“);
            AddMenuItem(“退出“);

            for (int i = 10; i <= 100; i += 10)
            {
                MenuItem subMenu = new MenuItem(i + “%“);
                subMenu.Click += new EventHandler(OpacityMenuHandler);
                opacityMenuItem.MenuItems.Add(subMenu);
            }
        }

        private MenuItem AddMenuItem(string text)
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-28 11:38  BeautifulRuler\
     目录           0  2017-11-29 08:51  BeautifulRuler\BeautifulRuler\
     文件         187  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\App.config
     文件        3808  2017-11-29 08:42  BeautifulRuler\BeautifulRuler\BeautifulRuler.csproj
     目录           0  2017-11-29 08:40  BeautifulRuler\BeautifulRuler\bin\
     目录           0  2017-11-29 08:57  BeautifulRuler\BeautifulRuler\bin\Debug\
     文件       15872  2017-11-29 08:54  BeautifulRuler\BeautifulRuler\bin\Debug\BeautifulRuler.exe
     目录           0  2017-11-29 08:40  BeautifulRuler\BeautifulRuler\bin\Release\
     文件       17137  2017-11-29 08:51  BeautifulRuler\BeautifulRuler\Form1.cs
     文件        1161  2017-11-29 08:47  BeautifulRuler\BeautifulRuler\Form1.Designer.cs
     文件        5817  2017-11-28 11:40  BeautifulRuler\BeautifulRuler\Form1.resx
     目录           0  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\obj\
     目录           0  2017-11-29 08:54  BeautifulRuler\BeautifulRuler\obj\Debug\
     文件         807  2017-11-29 08:55  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.csproj.FileListAbsolute.txt
     文件         977  2017-11-28 11:44  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.csproj.GenerateResource.Cache
     文件        2211  2017-11-28 11:44  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.csprojResolveAssemblyReference.cache
     文件       15872  2017-11-29 08:54  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.exe
     文件       38400  2017-11-29 08:54  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.pdb
     文件         180  2017-11-29 08:42  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.Properties.Resources.resources
     文件         180  2017-11-29 08:42  BeautifulRuler\BeautifulRuler\obj\Debug\BeautifulRuler.Ruler.resources
     文件         865  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6995  2017-11-29 08:40  BeautifulRuler\BeautifulRuler\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件           0  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
     文件           0  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
     目录           0  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\obj\Debug\TempPE\
     文件         526  2017-11-28 11:39  BeautifulRuler\BeautifulRuler\Program.cs
     目录           0  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\Properties\
     文件        1370  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\Properties\AssemblyInfo.cs
     文件        2880  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\Properties\Resources.Designer.cs
     文件        5612  2017-11-28 11:38  BeautifulRuler\BeautifulRuler\Properties\Resources.resx
............此处省略4个文件信息

评论

共有 条评论