开发者

Modifying the Label Property(text and font) by a custom ComboBox

开发者 https://www.devze.com 2022-12-31 20:00 出处:网络
I have created a custom combobox that has a LABEL property so when we drop it on a form, we can say the Label associated with this ComboBox is say Label2

I have created a custom combobox that has a LABEL property so when we drop it on a form, we can say the Label associated with this ComboBox is say Label2 this is what I wrote for its label property. The whole thing I want to do is that when I am assigning the Label property of my custom ComboBox to one of the labels on the form, I want开发者_开发技巧 that label to change its font to bold and also add an "*" to its Test property. thats it ... but it does not work! any ideas?

    private Label assignedLabelName;
    public Label AssignedLabelName
    {
        get
        {
            return assignedLabelName;
        }
        set
        {
            assignedLabelName = value;
            assignedLabelName.Text = "*" + assignedLabelName.Text;
            assignedLabelName.Font = new Font(AssignedLabelName.Font, FontStyle.Bold);
        }
    }


Try to add a call to

assignedLabelName.Refresh()

at the end of the setter

and - as a reply to your comment How about having a Custom Label too this custom label will hold a flag telling if it is bound to any combo box. The text will be saved in private member and the Text property will return the value of the private text member + an asterisk in case the flag is set.

0

精彩评论

暂无评论...
验证码 换一张
取 消