Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm so sorry for my enlish.
I writed a control which has a property named Associa(class). And this property reference from a static class. when i designed and saved Form, this property have lost。

Code:

public sealed class Associa
{
    private string _FunCode = "NULL";

    /// <summary>
    /// 构造
    /// </summary>
    private Associa()
    {
    }

    public string FunCode
    {
        get { return this._FunCode; }
        private set
        {
            if (string.IsNullOrEmpty(value))
            {
                value = "NULL";
            }

            if (this._FunCode != value)
            {
                this._FunCode = value;
            }
        }
    }

    public static Associa Generate(string pcFunCode)
    {
        Associa loAssocia = new Associa();
        loAssocia.FunCode = pcFunCode;
        return loAssocia;
    }



public static class AssociaFactory
{
    public static Associa NULL = Associa.Generate("NULL");

    public static Associa pubvocabulary = Associa.Generate("pubvocabulary");
}



used by:
this code in designer file

this.control.Associa = AssociaFactory.NULL


it lost on saving

What I have tried:

i watch the code "Control.Cursor",but has no idea.....
Posted
Updated 22-Sep-16 1:12am
Comments
BillWoodruff 19-Sep-16 9:16am    
Not clear what you are doing here. What is your goal ? When you mention "saving" it's logical to assume some form of serialization ... but, your code shows no attempt to serialize or de-serialize.
Ralf Meier 19-Sep-16 13:48pm    
I think the OP wants that the property-value is "saved" by the designer. But for me this "CustomControl" makes no sense in this way. Perhaps more information is required ...
AdaEniac 19-Sep-16 21:46pm    
Yes. I want that the property-value is "saved" by the designer.
Ralf Meier 20-Sep-16 15:26pm    
OK ... show (improve your question with) the code where you use Associa as a Property ...
AdaEniac 21-Sep-16 3:46am    
Well,i want simulate System.Windows.Forms.Cursor.
As you know, "Control.Cursor" is from Cursors. So, when you saved a Form, you can see the property which named "Cursor" in the XXX.Designer.cs file.
like this "this.Cursor = System.Windows.Forms.Cursors.Default".

So, how can i save my property like "Cursor"

1 solution

with your class-Property try it like this :
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
public Associa Associa
{
	get { return _Associa; }
}
private Associa _Associa = new Associa();


your class itself I modified like this :
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public class Associa
{

	public string FunCode {
		get { return this._FunCode; }
		set {
			if (string.IsNullOrEmpty(value)) {
				value = "NULL";
			}

			this._FunCode = value;
		}
	}

	private string _FunCode = "NULL";
	public static Associa Generate(string pcFunCode)
	{
		Associa loAssocia = new Associa();
		loAssocia.FunCode = pcFunCode;
		return loAssocia;
	}

	public Associa()
	{
		_FunCode = "NULL";
	}

	public Associa(string pcFunCode)
	{
		_FunCode = pcFunCode;
	}


	public override string toString()
	{
		return _FunCode;
	}

}

now it should work like you want ...
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900