Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Force UI of control to refresh on certain control property changed
 

Force UI of control to refresh on certain control property changed

How do i make my custom control repaint certain component on control when
another property is changed?
Consider this example.

When i add windows label on form it's text value is automatically set to
label1.
Then i open proerties tab and change Text property and when i hit enter this
new value imediately get's reflected on label
... i mean i set text to "label2" hit enter and imediately results are there
... on the control so something causes control to be repainted...

Now ... another example let's say i add some property to default label
called TextEnding which should add some kind of additional text to
label.Text property.
No idea why this would be useful in any scenario, but let's just consider i
want this to be done.

So i would write something like this

Code Block
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Bindable(false)]
[DefaultValue("")]
[Category("Appearance")]
[RefreshProperties(RefreshProperties.All)]
public string TextEnding
{
get
{
return textEnding;
}
set
{
textEnding = value;
Text = Text + value;
}
}



So if i now, if i open properties tab and set " the end" to TextEnding
property i would imediatelly see the changes on Text property
and it would look like this "label1 the end", BUT these changes would not
appear on label ... label control would still have its default value label1
only after build the new value get's reflected visually. The question is
what attributes should i apply to get the value changed imediatelly ?

ambidexterous  Friday, November 16, 2007 2:25 PM

Hi Mix from Latvia,

I have tested your code, and it worked well on my machine. As you have generated code for the TextEnding property, the TextEnding will be added to the Text property twice, one by designer and the other by the code. So I suggest you use the DesignerSerializationVisibility.Hidden to not produce code for the TextEnding property. Try something like the following:

Code Block

class ExLabel :Label

{

private string textEnding;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

[Bindable(false)]

[DefaultValue("")]

[Category("Appearance")]

public string TextEnding

{

get

{

return textEnding;

}

set

{

textEnding = value;

Text = Text + value;

}

}

}

If this does not help, you can try to call the Control.Invalidate method in the set accessor.

Code Block

set

{

textEnding = value;

Text = Text + value;

this.Invalidate();

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, November 22, 2007 2:40 AM

Hi Mix from Latvia,

I have tested your code, and it worked well on my machine. As you have generated code for the TextEnding property, the TextEnding will be added to the Text property twice, one by designer and the other by the code. So I suggest you use the DesignerSerializationVisibility.Hidden to not produce code for the TextEnding property. Try something like the following:

Code Block

class ExLabel :Label

{

private string textEnding;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

[Bindable(false)]

[DefaultValue("")]

[Category("Appearance")]

public string TextEnding

{

get

{

return textEnding;

}

set

{

textEnding = value;

Text = Text + value;

}

}

}

If this does not help, you can try to call the Control.Invalidate method in the set accessor.

Code Block

set

{

textEnding = value;

Text = Text + value;

this.Invalidate();

}

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, November 22, 2007 2:40 AM

You can use google to search for other answers

Custom Search

More Threads

• How I Make a form a Resolution Independent Form?
• GotFocus and LostFocus in design mode
• Enable adding existing controls / component to a collection property
• UserControl Background Color
• Extend default context menu
• UndoEngine in standalone Designer
• Property grid and Datagrid in .Net 2.0
• Refresh Designer at Design Time?
• 2 WinForm bugs
• Wanted: Collapsable TreeView/ListView control