Click here to Skip to main content
15,923,120 members
Home / Discussions / C#
   

C#

 
GeneralRe: Insertions sort reversed - optimize [modified] Pin
harold aptroot3-Jun-10 1:42
harold aptroot3-Jun-10 1:42 
GeneralRe: Insertions sort reversed - optimize Pin
harold aptroot3-Jun-10 2:15
harold aptroot3-Jun-10 2:15 
GeneralRe: Insertions sort reversed - optimize Pin
bolikej3-Jun-10 2:31
bolikej3-Jun-10 2:31 
QuestionBest performance LAN communication for a Server/Client application Pin
teknolog1232-Jun-10 22:58
teknolog1232-Jun-10 22:58 
AnswerRe: Best performance LAN communication for a Server/Client application Pin
#realJSOP3-Jun-10 1:50
professional#realJSOP3-Jun-10 1:50 
QuestionCreating Events Pin
Roger Wright2-Jun-10 22:37
professionalRoger Wright2-Jun-10 22:37 
AnswerRe: Creating Events Pin
Abhinav S2-Jun-10 23:05
Abhinav S2-Jun-10 23:05 
AnswerRe: Creating Events Pin
OriginalGriff3-Jun-10 0:45
mveOriginalGriff3-Jun-10 0:45 
Signal an event from a child to a parent

In the child form:

public partial class frmChild : Form
   {
   // Signal file change happened
   public event EventHandler Changed;

   protected virtual void OnChanged(EventArgs e)
      {
      EventHandler eh = Changed;
      if (eh != null)
         {
         eh(this, e);
         }
      }

   private void DoSomethingToChangeData()
      {
      OnChanged(null);
      }
   }

----- The asign to eh is in case the handler changes between null check
----- and exec.
----- (unlikely, but possible)

----- The null check is to ensure there is a handler. If not, better to
----- ignore it gracefully, than to rely on the thrown exception
----- (NullReferenceException)

In the Parent form:


public frmParent()
     {
     frmChild.Change += new frmChange.ChangeHandler(Changed);
     }

 private void ShowChildForm()
     {
     // Link in his event so if it changes, we detect it.
     frmChild fd = new frmChild();
     fd.ShowDialog();
     }

 //
 // Fired when the file is changed at a lower level.
 //
 private void Changed(object sender, EventArgs e)
     {
     }

***************************************
You can pass data in this way via the EventArgs parameter:
Child:
public partial class frmOther : Form
     {
     public frmOther()
         {
         InitializeComponent();
         }

     public event EventHandler Changed;

     private void butGo_Click(object sender, EventArgs e)
         {
        EventHandler ch = Changed;
        if (ch != null)
           {
           ch(this, new ChangedArgs(tbData.Text));
           }
         }
     }

 public partial class ChangedArgs : EventArgs
     {
     public string strData;
     public ChangedArgs(string str)
         {
         strData = str;
         }
     }


Parent:
public partial class frmTextBox : Form
    {
    frmOther otherForm = new frmOther();
    public frmTextBox()
        {
        InitializeComponent();
        }

    private void frmTextBox_Load(object sender, EventArgs e)
        {
        otherForm.Changed += new EventHandler(Changed);
        otherForm.Show();
        }

    private void Changed(object sender, EventArgs e)
        {
        ChangedArgs ca = e as ChangedArgs;
        if (ca != null)
            {
            tbData.Text = ca.strData;
            }
        }
    }


[edit]Forgot the code block tags. Getting too used to the autopreview in QA I guess...[/edit]
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

GeneralRe: Creating Events Pin
Roger Wright3-Jun-10 4:08
professionalRoger Wright3-Jun-10 4:08 
AnswerRe: Creating Events Pin
DaveyM693-Jun-10 1:38
professionalDaveyM693-Jun-10 1:38 
GeneralRe: Creating Events Pin
Roger Wright3-Jun-10 4:09
professionalRoger Wright3-Jun-10 4:09 
QuestionSystem.DBNull returned for whitespace strings Pin
GDavy2-Jun-10 22:07
GDavy2-Jun-10 22:07 
AnswerRe: System.DBNull returned for whitespace strings Pin
Pete O'Hanlon2-Jun-10 23:30
mvePete O'Hanlon2-Jun-10 23:30 
GeneralRe: System.DBNull returned for whitespace strings Pin
GDavy2-Jun-10 23:59
GDavy2-Jun-10 23:59 
GeneralRe: System.DBNull returned for whitespace strings Pin
Pete O'Hanlon3-Jun-10 0:23
mvePete O'Hanlon3-Jun-10 0:23 
QuestionProblem reading multiple bytes from serialport Pin
myreki2-Jun-10 21:35
myreki2-Jun-10 21:35 
AnswerRe: Problem reading multiple bytes from serialport Pin
Luc Pattyn3-Jun-10 2:14
sitebuilderLuc Pattyn3-Jun-10 2:14 
QuestionNotifyPropertyChanged and ReadValue() not working Pin
Mycroft Holmes2-Jun-10 21:20
professionalMycroft Holmes2-Jun-10 21:20 
AnswerRe: NotifyPropertyChanged and ReadValue() not working Pin
Henry Minute2-Jun-10 22:14
Henry Minute2-Jun-10 22:14 
GeneralRe: NotifyPropertyChanged and ReadValue() not working Pin
Mycroft Holmes2-Jun-10 22:39
professionalMycroft Holmes2-Jun-10 22:39 
AnswerRe: NotifyPropertyChanged and ReadValue() not working - kludged Pin
Mycroft Holmes2-Jun-10 22:21
professionalMycroft Holmes2-Jun-10 22:21 
AnswerRe: NotifyPropertyChanged and ReadValue() not working Pin
GDavy2-Jun-10 22:25
GDavy2-Jun-10 22:25 
GeneralRe: NotifyPropertyChanged and ReadValue() not working Pin
Mycroft Holmes2-Jun-10 22:37
professionalMycroft Holmes2-Jun-10 22:37 
GeneralRe: NotifyPropertyChanged and ReadValue() not working Pin
GDavy2-Jun-10 22:53
GDavy2-Jun-10 22:53 
GeneralRe: NotifyPropertyChanged and ReadValue() not working Pin
Mycroft Holmes2-Jun-10 23:27
professionalMycroft Holmes2-Jun-10 23:27 

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.