试图让Label的文本暴露出来

时间:2011-02-02 10:33:07

标签: c# grid properties

我的一个基本表单中包含以下代码:

using System;
using System.Drawing;
using Telerik.WinControls.UI;

namespace ExciteEngine2.MainApplication.BaseUI {

  public partial class BaseCreateForm : BaseForm {

    public BaseCreateForm() {
      InitializeComponent();
      SetupLookAndFeelThings();
      Header = Tag.ToString();
    }

    public void SetupLookAndFeelThings() {
      LabelHeader.Font = new Font(Font.FontFamily, 14.25F, Font.Style, Font.Unit, Font.GdiCharSet);
    }

    protected RadLabel HeaderLabel {
      get {
        return LabelHeader;
      }
      set {
        LabelHeader = value;
      }
    }

    protected String Header {
      get {
        return LabelHeader.Text;
      }
      set {
        LabelHeader.Text = value;
      }
    }

    protected Image HeaderImage { 
      get {
        return LabelHeader.Image;
    } 
      set {
        LabelHeader.Image = value;
    } 
    }

    private void RadButtonCancel_Click(object sender, EventArgs e) {
      Close();
    }

  }
}

所以,我有几个属性允许我设置标题和副标题。但是这些属性在继承表单的可视化设计器属性网格中不可见。例如,我真的需要设置基本标签的图像。如何将这些属性放入Property网格?

1 个答案:

答案 0 :(得分:0)

好的,经过很多谷歌,我想出了这个:

using System;
using System.ComponentModel;
using System.Drawing;

namespace ExciteEngine2.MainApplication.BaseUI {

  public partial class BaseCreateForm : BaseForm {

    public BaseCreateForm() {
      InitializeComponent();
      SetupLookAndFeelThings();
    }

    public void SetupLookAndFeelThings() {
      LabelHeader.Font = new Font(Font.FontFamily, 12.25F, Font.Style, Font.Unit, Font.GdiCharSet);
    }

    [Category("Appearance"), DisplayName("HeaderText"), DescriptionAttribute("Text of the form's header."), Browsable(true)]
    public String HeaderText {
      get {
        return LabelHeader.Text;
      }
      set {
        LabelHeader.Text = value;
      }
    }

    [Category("Appearance"), DisplayName("HeaderImage"),  DescriptionAttribute("Image of the form's header."), Browsable(true)]
    public Image HeaderImage {
      get {
        return PictureTitle.Image;
      }
      set {
        PictureTitle.Image = value;
      }
    }

    private void RadButtonCancel_Click(object sender, EventArgs e) {
      Close();
    }

  }
}

必须从ComponentModel添加这些属性。