LunarMind/Adorners/PictureBoxBorderAdorner.cs

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using SHomeWorkshop.LunarTools;

namespace SHomeWorkshop.LunarMind.Adorners
{
    public class PictureBoxBorderAdorner : Adorner
    {
        // Be sure to call the base class constructor.
        /// <summary>
        /// 用以表示PictureBox选取状态的装饰器。
        /// </summary>
        /// <param name="adornedElement">应传入PictureBox的“Image”主子元素。</param>
        public PictureBoxBorderAdorner(UIElement adornedElement, PictureBox masterPictureBox)
            : base(adornedElement)
        {
            this.masterPictureBox = masterPictureBox;

            //终于解决了选取装饰器中线条宽度为2而不是1像素的问题!!!
            this.SnapsToDevicePixels = true;
            this.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
            this.MouseDown += new System.Windows.Input.MouseButtonEventHandler(PictureBoxBorderAdorner_MouseDown);
            this.MouseRightButtonUp += new System.Windows.Input.MouseButtonEventHandler(PictureBoxBorderAdorner_MouseRightButtonUp);
        }

        void PictureBoxBorderAdorner_MouseRightButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            PictureBox.S_ContextMenu.IsOpen = true;
            e.Handled = true;
        }

        void PictureBoxBorderAdorner_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (masterPictureBox != null)
            {
                masterPictureBox.SelectOnlySelf();
                e.Handled = true;
            }
        }

        private PictureBox masterPictureBox;

        public PictureBox MasterPictureBox
        {
            get { return masterPictureBox; }
        }

        // A common way to implement an adorner's rendering behavior is to override the OnRender
        // method, which is called by the layout system as part of a rendering pass.
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (masterPictureBox == null) return;

            Rect adornedElementRect = new Rect(this.AdornedElement.RenderSize);

            //先画线。
            Pen linePen = null;

            if (this.masterPictureBox != null && this.masterPictureBox.Editor != null)
后面还有 88 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。