Click here to Skip to main content
15,908,675 members
Home / Discussions / C#
   

C#

 
GeneralRe: Question on iterators Pin
Colin Angus Mackay14-Jun-07 2:04
Colin Angus Mackay14-Jun-07 2:04 
GeneralRe: Question on iterators Pin
Dewald14-Jun-07 2:21
Dewald14-Jun-07 2:21 
AnswerRe: Question on iterators Pin
Luc Pattyn14-Jun-07 1:27
sitebuilderLuc Pattyn14-Jun-07 1:27 
GeneralRe: Question on iterators Pin
Dewald14-Jun-07 2:02
Dewald14-Jun-07 2:02 
GeneralRe: Question on iterators Pin
Luc Pattyn14-Jun-07 2:19
sitebuilderLuc Pattyn14-Jun-07 2:19 
GeneralRe: Question on iterators Pin
Le centriste14-Jun-07 7:24
Le centriste14-Jun-07 7:24 
QuestionStruggling with delegates Pin
kbalias14-Jun-07 0:10
kbalias14-Jun-07 0:10 
AnswerRe: Struggling with delegates Pin
Martin#14-Jun-07 1:29
Martin#14-Jun-07 1:29 
Hello,

Here is what I would do:
The members and logic for the UserControl would look like this:
public bool RemoveMe //property to get info about the CheckBox status
{
    get
    {
        return checkBox1.Checked;
    }
}

        //event/delegate for the connection to the form
public event EventHandler CheckedChanged;

        //If checkBox CheckedChanges
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
    if (CheckedChanged != null)
    {
        CheckedChanged(this, e);  //Fire event
    }
}

Form:
Forms member:
private ArrayList removableUC = new ArrayList(); //holds the instances of the usercontrols which have to be deleted

Forms constructor code:
public Form1()
{
                //Check if Control is added
    this.ControlAdded+=new ControlEventHandler(Form1_ControlAdded);

    InitializeComponent();
}

Forms ControlAdded Handler code:
private void Form1_ControlAdded(object sender, ControlEventArgs e)
{
                //cast to UserControls type
    UserControl1 uc = e.Control as UserControl1;
    if(uc!=null)
    {
                        //add link to UserControls delegate
        uc.CheckedChanged+=new EventHandler(uc_CheckedChanged);
    }
}

Forms handles CheckedChanged event
private void uc_CheckedChanged(object sender, EventArgs e)
{
    UserControl1 uc = sender as UserControl1;
    if(uc!=null)
    {
        if(uc.RemoveMe)//Check if CheckBox is Checked (check check check)
        {
            removableUC.Add(uc);  //If yes, add it to List
        }
        else
        {
            if(removableUC.Contains(uc))//If no, and it's in list
            {
                removableUC.Remove(uc); //remove it from list
            }
        }
    }
}

Forms handles button click of "removeallbutton"
private void buttonRemoveAll_Click(object sender, System.EventArgs e)
{
    foreach(object o in removableUC) //iterate threw all controls in list
    {
        UserControl1 uc = o as UserControl1;
        if(uc != null)
        {
            uc.CheckedChanged-=new EventHandler(uc_CheckedChanged);  //disconnect delegate (Importend for GarbadgeCollector)
            this.Controls.Remove(uc);//remove from Form
            uc.Dispose(); //dispose (Importend for GarbadgeCollector)
            uc=null;
        }
    }
    removableUC.Clear();
}

I'm working with .Net1.1, so I couldn't use a generic Collection, which would be much nicer.

Hope it helps!

All the best,

Martin
GeneralRe: Struggling with delegates Pin
kbalias14-Jun-07 18:51
kbalias14-Jun-07 18:51 
AnswerRe: Struggling with delegates Pin
Martin#14-Jun-07 19:29
Martin#14-Jun-07 19:29 
QuestionHow to read Character from Image Pin
Soosai13-Jun-07 23:59
Soosai13-Jun-07 23:59 
AnswerRe: How to read Character from Image Pin
Russell'14-Jun-07 1:52
Russell'14-Jun-07 1:52 
Questionturn a string into a querystring Pin
tim_gunning13-Jun-07 23:47
tim_gunning13-Jun-07 23:47 
Questioninclude icon to setup project Pin
korsosjosi13-Jun-07 23:20
korsosjosi13-Jun-07 23:20 
AnswerRe: include icon to setup project Pin
Colin Angus Mackay13-Jun-07 23:26
Colin Angus Mackay13-Jun-07 23:26 
GeneralRe: include icon to setup project Pin
korsosjosi13-Jun-07 23:42
korsosjosi13-Jun-07 23:42 
GeneralRe: include icon to setup project Pin
Colin Angus Mackay13-Jun-07 23:46
Colin Angus Mackay13-Jun-07 23:46 
GeneralRe: include icon to setup project Pin
korsosjosi13-Jun-07 23:47
korsosjosi13-Jun-07 23:47 
AnswerRe: include icon to setup project Pin
Hesham Yassin14-Jun-07 8:23
Hesham Yassin14-Jun-07 8:23 
QuestionAccessing Active Directory profile "on the fly" Pin
Klaus MJ13-Jun-07 22:47
Klaus MJ13-Jun-07 22:47 
QuestionSearching for an alternative of typedef in C# [modified] Pin
Gatchan13-Jun-07 22:43
Gatchan13-Jun-07 22:43 
AnswerRe: Searching for an alternative of typedef in C# [modified] Pin
Luc Pattyn14-Jun-07 0:58
sitebuilderLuc Pattyn14-Jun-07 0:58 
GeneralRe: Searching for an alternative of typedef in C# Pin
Gatchan14-Jun-07 2:22
Gatchan14-Jun-07 2:22 
GeneralRe: Searching for an alternative of typedef in C# Pin
Luc Pattyn14-Jun-07 2:31
sitebuilderLuc Pattyn14-Jun-07 2:31 
QuestionRemote Registry in C# Pin
devesh_code13-Jun-07 22:21
devesh_code13-Jun-07 22:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.