private void UnListenPropertyChanged(EditorButton btn)
 {
     if (btn != null)
     {
         btn.PropertyChanged -= btn_PropertyChanged;
     }
 }
Example #2
0
 internal static Image GetImage(this EditorButton button)
 {
     if (button.Kind == ButtonPredefines.Glyph)
     {
         return(button.Image);
     }
     return(button.Kind.GetImage());
 }
        private static Rectangle GetTextRectangle(Button btn, EditorButton editorBtn)
        {
            //图片左右偏移量
            var imageMargin = 1;
            //文字高度偏移量
            var textTopMargin = 0;

            var width  = editorBtn.CaptionSize.Width;
            var height = editorBtn.CaptionSize.Height;

            var top  = (btn.ClientSize.Height - height) / 2 + textTopMargin;
            var left = (btn.ClientSize.Width - width) / 2;

            left = left < 0 ? 0 : left;

            //减去图片后的剩余宽度
            var residualWidth = width;

            var btnImg = editorBtn.GetImage();

            if (btnImg != null)
            {
                var imagePoint = btn.GetImageLocation(editorBtn.ImageAlign, btnImg);
                switch (editorBtn.ImageAlign)
                {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.TopCenter:
                    left = top = width = height = residualWidth = 0;
                    break;

                case ContentAlignment.BottomLeft:
                case ContentAlignment.TopLeft:
                case ContentAlignment.MiddleLeft:
                    left = btn.GetImageLocation(editorBtn.ImageAlign, btnImg).X + btnImg.Width + imageMargin;
                    //可用范围
                    residualWidth = btn.ClientSize.Width - (imagePoint.X + btnImg.Width);
                    break;

                case ContentAlignment.BottomRight:
                case ContentAlignment.TopRight:
                case ContentAlignment.MiddleRight:
                    left = 0;
                    //可用范围
                    residualWidth = imagePoint.X - imageMargin;
                    break;
                }
                width = width > residualWidth ? residualWidth : width;
            }

            return(new Rectangle(left, top, width, height));
        }
 private Button FindButton(EditorButton button)
 {
     if (button == null)
     {
         return(null);
     }
     foreach (var kv in _innerButtons)
     {
         if (Equals(kv.Value, button))
         {
             return(kv.Key);
         }
     }
     return(null);
 }
 private static void SyncEditorButtonProperties(EditorButton editorBtn, Button btn)
 {
     if (editorBtn != null && btn != null)
     {
         btn.Enabled = editorBtn.Enabled;
         btn.Width   = editorBtn.Width + btn.Padding.Left + btn.Padding.Right;
         btn.Cursor  = editorBtn.Cursor;
         btn.Visible = editorBtn.Visible;
         if (string.IsNullOrEmpty(editorBtn.Name))
         {
             editorBtn.Name = btn.Name;
         }
         else
         {
             btn.Name = editorBtn.Name;
         }
     }
 }
 /// <summary>
 ///     初始化 <see cref="QGEditors.WinForms.ButtonPressedEventArgs" />  类的新实例。
 /// </summary>
 /// <param name="button"><see cref="QGEditors.WinForms.EditorButton" />实例。</param>
 public ButtonPressedEventArgs(EditorButton button)
 {
     Button = button;
 }