C# DevExpress WinForm编程 针对一些控件重复度高的属性设置问题的解决方案

问题描述

我在使用DevExpress控件时经常会需要先将控件设置成自己需要的样式或者取消控件的一部分功能(可删除、可拖曳之类的)。这种行为本身并没什么问题,问题在于DevExpress控件的属性实在是太多了,多到我每次打开属性界面都会头痛。

解决方案

为了解决这个问题我使用了工具类提取控件属性的方法。
如下图,我将XtraForm传入了ZXtraFormTools这个工具类,也将菜单Bar对象传入了ZXtraBarTools工具类进行常用属性的设置。
这里写图片描述

这两个工具类的属性视图只保留了我要用的属性。
这里写图片描述 这里写图片描述

能看到这里的大家应该都懂了,下面直接放代码。

ZXtraFormTools.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using DevExpress.XtraEditors;


namespace ZDevExpressTools {
    public class ZXtraFormTools : ZComponentTools<XtraForm> {

        [Browsable(true), DefaultValue(null), DXCategory("对象引用")]
        public XtraForm XtraForm {
            get {
                return this.OperationObject;
            }
            set {
                this.OperationObject = value;
            }
        }

        [Browsable(true), DXCategory("视图选项")]
        public bool ShowIcon {
            get {
                if (this.XtraForm != null) {
                    return this.XtraForm.ShowIcon;
                }
                return false;
            }
            set {
                if (this.XtraForm != null) {
                    this.XtraForm.ShowIcon = value;
                }
            }
        }

        [AmbientValue("")]
        [Localizable(true)]
        [Browsable(true), DXCategory("视图选项")]
        public Icon Icon {
            get {
                if (this.XtraForm != null) {
                    return this.XtraForm.Icon;
                }
                return null;
            }
            set {
                if (this.XtraForm != null) {
                    this.XtraForm.Icon = value;
                }
            }
        }

        [Browsable(true), DXCategory("视图选项")]
        public string Text {
            get {
                if (this.XtraForm != null) {
                    return this.XtraForm.Text;
                }
                return null;
            }
            set {
                if (this.XtraForm != null) {
                    this.XtraForm.Text = value;
                }
            }
        }

        [Category("常用属性")]
        public bool ShowInTaskbar {
            get {
                if (this.XtraForm != null) {
                    return this.XtraForm.ShowInTaskbar;
                }
                return false;
            }
            set {
                if (this.XtraForm != null) {
                    this.XtraForm.ShowInTaskbar = value;
                }
            }
        }

        [Category("常用属性")]
        public bool MaximizeBox {
            get {
                if (this.XtraForm != null) {
                    return this.XtraForm.MaximizeBox;
                }
                return 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值