Jean-Bernard Pellerin
Jean-Bernard Pellerin

Reputation: 12670

which of the following is better for eventhandling

Ok so I'm just making a mock MVC app to get a handle on how things work
my model has some string in it (and more, but don't care at the moment)
my GUI has a bunch of radiobuttons and here is what I do

private class radioButtonEvent : Model.EventHandling.XObjectEvent{
        private List<RadioButton> myList;
        public radioButtonEvent() { }
        public override void execute(){
            foreach (RadioButton a in myList){
                if (a.Text == ((Model.InfoTree)myObj).Info){
                    a.Checked = true;
                    ((TabControl)a.Parent.Parent).SelectTab(a.Parent.Name);
                }
            }
        }
        public void setRadioList(List<RadioButton> a){
            myList = a;
        }
    }

I create one of these and add a list of all my radiobuttons then make it listen to a certain string, like so:

        radioButtonEvent locationEvent = new radioButtonEvent();
        List<RadioButton> radioList = new List<RadioButton>();
        radioList.Add(Location_Logged_Arena_radioButton);
        radioList.Add(Location_Logged_Market_radioButton);
        radioList.Add(Location_Logged_Mute_radioButton);
        radioList.Add(Location_Logged_Town_radioButton);
        radioList.Add(Location_Logged_Vault_radioButton);
        radioList.Add(Location_Logging_Home_radioButton);
        radioList.Add(Location_Logging_Select_radioButton);
        locationEvent.setRadioList(radioList);
        myModel.InformationTree.addInfoEvent(locationEvent);

one thing I should point out is that in XObjectEvent there is a method that gets inherited that handles the setting of myobj

now the two ways I've currently thought of going about having listenable strings are these:
Way 1:

    private ListenableString lstring = new ListenableString();
    public string Info{
        get
        { return lstring.Text;}
        set
        { lstring.Text = value;}

    }
    public void addInfoEvent(XEvent ev){
        lstring.addEvent(ev);
    }  

and this uses the following

class ListenableString
{
    public ListenableString() { }
    private string me = "";
    private List<XEvent> Events = new List<XEvent>();
    public void addEvent(XEvent ev){
        Events.Add(ev);
    }
    public string Text{
        get
        { return me;}
        set{
            me = value;
            foreach (EventHandling.XObjectEvent x in Events){
                x.setObject(this);
                x.execute();
            }
        }
    }
}

Way 2:

    private List<XEvent> infoEvents = new List<XEvent>();
    public void addInfoEvent(XEvent ev)
    {
        infoEvents.Add(ev);
    }
    private string _Info = "";
    public string Info
    {
        get
        {
            return _Info;
        }
        set
        {
            _Info = value;
            foreach (EventHandling.XObjectEvent x in infoEvents)
            {
                x.setObject(this);
                x.execute();
            }
        }
    }

Way 3
got a better way? :)

Upvotes: 0

Views: 349

Answers (1)

George Stocker
George Stocker

Reputation: 57877

Ye Olde New Answer

Here are some Stack Overflow questions that deal with implementing MVC in a Windows Form Application:

  1. Implementing MVC with Windows Forms.
  2. How would you implement MVC in a Windows Form Application?

Ye Olde Olde Answer

Use ASP.NET MVC 1.0.

Upvotes: 1

Related Questions