views:

23

answers:

2

I'm trying to set other properties based on setting "master" property but it won't work. Nothing is written in Designer.cs file except "master" property.

idea:

[ProvideProperty("SaveUserSettings", typeof(Component))]
[ProvideProperty("SaveLayoutGroupSettings",typeof(Form))]
public class UserSettingsExtender : Component, IExtenderProvider

private Dictionary<Component, bool> _components; // for SaveUserSettings
private Hashtable _layoutGroupComponents = new Hashtable(); //for SaveLayoutGroupSettings

By setting "SaveLayoutGroupSettings" on Form property in designer i want to set "SaveUserSettings"property on other component.

In SetSaveLayoutGroupSettings method I traverse child controls and put them in _components but property SaveUserSettings on child controls is not changed.

Can someone point me in right direction?

A: 

It's unguessable from your code snippet, you didn't post the critical methods you have to provide. Particularly the Get and Set methods you need. I'll just give a working example:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;

[ProvideProperty("SaveUserSettings", typeof(Component))]
public class UserSettingsExtender : Component, IExtenderProvider {
    private Dictionary<Component, bool> _components = new Dictionary<Component, bool>();

    public bool CanExtend(object extendee) {
        return extendee is Component;
    }
    public bool GetSaveUserSettings(Component extendee) {
        if (!_components.ContainsKey(extendee)) _components.Add(extendee, false);
        return _components[extendee];
    }
    public void SetSaveUserSettings(Component extendee, bool value) {
        if (!_components.ContainsKey(extendee)) _components.Add(extendee, false);
        _components[extendee] = value;
    }
}
Hans Passant
A: 

Tnx for response. That part you are talking about is working fine. My problem is that I want to set another extended properties when setting one property.

Let me try to explain (bare with me :) )

I want to have one extended property on Form and when i set that property on true i want to propagate that on another extended property on child controls on that Form.

I'll try to use your example (bare with me 2) :

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;


[ProvideProperty("SaveUserSettings", typeof(Component))]
[ProvideProperty("SaveGroupSettings",typeof(Form))]
public class UserSettingsExtender : Component, IExtenderProvider {
    private Dictionary<Component, bool> _components = new Dictionary<Component, bool>();
    private Dictionary<Component, bool> _groups = new Dicitonary<Component, bool>();

    public bool CanExtend(object extendee) {
        return extendee is Component;
    }
    public bool GetSaveUserSettings(Component extendee) {
        if (!_components.ContainsKey(extendee)) _components.Add(extendee, false);
        return _components[extendee];
    }
    public void SetSaveUserSettings(Component extendee, bool value) {
        if (!_components.ContainsKey(extendee)) _components.Add(extendee, false);
        _components[extendee] = value;


    public bool GetSaveGroupSettings(Component extendee) {
        if (!_groups.ContainsKey(extendee)) _groups.Add(extendee, false);
        return _groups[extendee];
    }
    public void SetSaveGroupSettings(Component extendee, bool value) {
        if (!_groups.ContainsKey(extendee)) _groups.Add(extendee, false);
        _groups[extendee] = value;

    ///THIS PART!  
    if(extendee is Form)
    {
        foreach(Control c in Forms.Control)
        {
            if (_components.ContainsKey(c))
            {
            _components[c] = value ;
            }
            else
            {
            _components.Add(c, value );
            }
        }
    }

    }
}

In SetSaveGroupSettings i want to put control i _components dictionary in order to set SaveUserSettings property but it doesn't work. Hm maybe i should call SetSaveUserSettings instead putting controls in collection...I'll try that and see what happens.

jkricka
Do you need anything else?
Hans Passant