一个没理想的程序员 2017-07-13 08:38 采纳率: 100%
浏览 1110
已采纳

winfrom自定义组合控件后台无法更改其属性值

我创建了一个组合控件,后台无法更改其属性值,请问是什么原因?

//控件代码
public partial class desk : UserControl
{
private string number = "0";
private string name = "桌子";
private string summoney = "金额";
private string bz = "备注";
private string zt = "";
System.Drawing.Color pb1 = System.Drawing.Color.LimeGreen;
System.Drawing.Color lb5bj = System.Drawing.Color.LightGray;
System.Drawing.Color nameforecolor = System.Drawing.Color.Black;
System.Drawing.Color smoncolor = System.Drawing.Color.Red;
public desk()
{
InitializeComponent();
this.NotifyPropertyChanged(Summoney);

}

    public event PropertyChangedEventHandler PropertyChanged;
    protected void NotifyPropertyChanged(string propertyName)
    {
        var propertyChanged = this.PropertyChanged;
        if (propertyChanged != null)
            propertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

     [Description("属性描述"), Category("属性卡名称"), DefaultValue("属性默认值")]

    public string Roomid
    {
        set { number = value; }
        get { return number; }

    }

    public string Roomname
    {
        get { return name; }
        set { name = value; }
    }

    public string Summoney
    {
        get { return summoney; }
        set { summoney = value; }
    }

    public Color getpb1
    {
        get { return pb1; }
        set { pb1 = value; }
    }

    public Color Lab5bj
    {
        get { return lb5bj; }
        set { lb5bj = value; }
    }

    public string Bz
    {
        get { return bz; }
        set { bz = value; }
    }

    public string Zt
    {
        get { return zt; }
        set { zt = value; }
    }

    public Color SmonColor
    {
        get { return smoncolor; }
        set { smoncolor = value; }
    }

    public Color NameForeColor
    {
        get { return nameforecolor; }
        set { nameforecolor = value; }
    }

    public event EventHandler AX;
    public delegate void select_Handle(object sender, EventArgs e, string orther);
    public event select_Handle Desk_click;      
    private void desk_Load(object sender, EventArgs e)
    {
        SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
        UpdateStyles();
        label4.Text = Roomid;//默认桌号
        label1.Text = Roomname;//默认名称
        label1.ForeColor = NameForeColor;//默认名称背景色
        label2.Text = Summoney;//金额
        label2.ForeColor = SmonColor;//金额背景色
        label3.Text = Bz;//备注
        label5.Text = Zt;//状态
        this.panel1.BackColor = getpb1;//默认顶部颜色
        this.label5.BackColor = Lab5bj;//默认背景颜色
    }

    private void desk_MouseClick(object sender, MouseEventArgs e)
    {
        //if (AX != null)
        //{
        //    AX(this, new EventArgs(),"");
        //}
    }

    private void desk_Click(object sender, EventArgs e)
    {

        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);  
    }

    private void label4_Click(object sender, EventArgs e)
    {

        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);
    }

    private void panel1_Click(object sender, EventArgs e)
    {

        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);
    }

    private void label1_Click(object sender, EventArgs e)
    {

        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);
    }

    private void label5_Click(object sender, EventArgs e)
    {
        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);
    }

    private void label2_Click(object sender, EventArgs e)
    {

        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);
    }

    private void label3_Click(object sender, EventArgs e)
    {
        if (Desk_click != null)
            Desk_click(this, new EventArgs(), this.Name);
    }
}

//前台引用代码
private void Test_Load(object sender, EventArgs e)
{

        this.desk1.Summoney = DateTime.Now.ToString("yyyy-MM-dd");
    }
  • 写回答

2条回答 默认 最新

  • csdn_zxw 2017-07-13 09:33
    关注

    自定义控件如果和布局中属性关联:
    * 1,在Values下创建attrs文件 在此文件中 添加属性
    * 2,在布局文件中使用添加的属性 (先添加命名空间)
    * 3,在逻辑代码 俩个参数的构造方法中 获取布局中的属性 并且进行刷新数据 最后回收属性

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型