I am currently developing an application in which I want to display UserControl inside the context menu. I managed (to achieve this somewhat using ToolStripControlHost). Shown in (NumericUpDownToolStripItem code): below is the code for the object (written in VC ++ .NET 2.0). Note. There are semi-similar SO questions on this, but none of them seem to be related to serializing user controls, but simply a standard object in usercontrols.
The object shown below is the actual user control code, which is tagged user control, and the numericupdown control.
Problem: when I load the constructor for my application, I can add my NumericUpDownToolStripItem just fine, however, when I open use to efficiently edit my user control, none of this data is serialized in the InitializeComponent method for my NumericUpDownToolStripItem object. The effect of this is my control loads with all the default values ββat runtime. And every time I reload the form, the changes are lost.
I tried using the TypeConverter tutorial located On Msdn , but it did not work properly. Everything compiled just fine, except that my object is completely saddled in the design grid (just an accessor property, not all menupic). Another issue that I noticed is that this method is not specifically designed for UserControls, which can have several different mutable properties and cannot have overloads for each.
So, I have the following questions:
- This is what I do practical, or my structure goes beyond the norm. I am sure there is a lot of redundancy in attributes.
- usercontrol, UserControl\toolstriphost. "" (, ..).
- TypeConverter , , (, ), , . , ? ( , ).
. .
NumericUpDownToolStripItem Class:
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability::All)]
public ref class NumericUpDownToolStripItem : public ToolStripControlHost
{
public:
[DesignerSerializationVisibility(DesignerSerializationVisibility::Content |
DesignerSerializationVisibility::Visible)]
property LabeledNumericUpDown ^LabeledNumericUpDownControl
{
LabeledNumericUpDown ^get() { return (LabeledNumericUpDown^)this->Control; }
}
public: NumericUpDownToolStripItem(void) :
ToolStripControlHost(gcnew LabeledNumericUpDown()) {}
protected: void OnSubscribeControlEvents(Control ^control) new {
protected: void OnUnsubscribeControlEvents(Control ^control) new {
};
public ref class LabeledNumericUpDown : public UserControl
{
public: [ DesignerSerializationVisibility(DesignerSerializationVisibility::Content |
DesignerSerializationVisibility::Visible)]
property String ^DisplayText {
String ^get() {
return this->label->Text;
}
void set(String ^val) {
if(this->label->Text != val)
{
this->label->Text = val;
this->Invalidate();
}
}
}
};