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

C#

 
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 
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 
Hello,

Glad I could help!

To make your code a little more OOP, you could use a special EventArgs class defined in the UserControl.
This would pass the Checked property of the checkbox over the event.
So there would be no more need for the property in the UserControl. (Saves a little bit of memory, specially if you have that much controls).
The other advantage is that you than only have to cast to Control and not UserControl, which takes a little more time I think.
Add a class:
public class EventArgsUserControl : System.EventArgs
{
    public bool RemoveMe  = false;

    public EventArgsUserControl(bool removeme)
    {
        RemoveMe = removeme;
    }
}

Changes in UserControl:
Remove:
		public bool RemoveMe
		{
			get
			{
				return checkBox1.Checked;
			}
		}

Add new delegate:
public event UserControlEventHandler CheckedChanged;
public delegate void UserControlEventHandler(object sender, EventArgsUserControl eauc);

Change To:
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
    if (CheckedChanged != null)
    {
        CheckedChanged(this, new EventArgsUserControl(checkBox1.Checked));
    }
}

Changes in Form:
link to your new delegate
private void Form1_ControlAdded(object sender, ControlEventArgs e)
{
    UserControl1 uc = e.Control as UserControl1;
    if(uc!=null)
    {
        uc.CheckedChanged+=new UserControlEventHandler(uc_CheckedChanged);
    }
}

disconnect it like this
uc.CheckedChanged-=new UserControlEventHandler(uc_CheckedChanged);

New checkedchanged code, without casting to UserControl
private void uc_CheckedChanged(object sender, EventArgsUserControl e)
{
    Control c = sender as Control;
    if(c!=null)
    {
        if(e.RemoveMe)
        {
            removableUC.Add(c);
        }
        else
        {
            if(removableUC.Contains(c))
            {
                removableUC.Remove(c);
            }
        }
    }
}


It might sound not neccessary in this special case, but you should consider it as good programming practice.

Hope it helps!

All the best,

Martin
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 
Questionc# passing parameter from Form to crystal report Pin
Wilson xyz13-Jun-07 22:19
Wilson xyz13-Jun-07 22:19 
AnswerRe: c# passing parameter from Form to crystal report Pin
Sylvester george14-Jun-07 2:23
Sylvester george14-Jun-07 2:23 

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.