   [.net] SendMessage in .net
  i have to forms, mainform and childform. mainform displays all my integers as labels, childform change these integers via buttons. now i would like to updatethe mainform-labels each time a childform is pressed. So I need to invalidate the mainform which isn´t possible from the childform (?) or I have to send a Message to the mainform (WM_OnPaint in WinAPI), but I don´t know how to do this. How do I solve the problem?thanks in advance,Bra    
  Let the childform expose a public event which is raised whenever a button is pressed on the childform.This event can then be handled on the mainform. In the event handler, update your label and call Application.DoEvents to actually repaint the mainform.This might not be the best way to do it but I think it should do the trick   ;  RizMan, sounds good, but a little bit "indirect". Is there now way to send the Mainform a message to be repainted? as a native function?Bra   ;  this.Invalidate(); ?   ;  Use the Win32 API function to send the message.  Forms contain the Handle property and an overloadable WndProc   ;  assuming it's an MDI app from the child you would do:this.MdiParent.Invalidate();   ;  xai, is it possible that you post some lines of code that do this. i don´t know how to call Win32Api-functions in .net...bra   ;  here is an ok link from googlehttp://www.c-sharpcorner.com/Code/2002/Nov/win32api.aspand anotherhttp://www.codeproject.com/csharp/cskillapp.aspthat should get you started.simply go to MSDN for exact signatures and locations of any Win32 function, then use the standard importing method to call it from .net   ;Quote:Original post by bratenRizMan, sounds good, but a little bit "indirect". Which is how it should be. Why should the MDI children know more about their parent than they absolutely have to? Quote:Is there now way to send the Mainform a message to be repainted?So not only do you want the MDI children to know about the internals of the parent, you want them to poke directly into its guts and make policy decisions for it as well?;  Using native Win32 calls for this is totally crazy IMHO.I also agree with Arild Fines that the child forms should know nothing about the main form.The following code assumes that the value that is to be changed is a field of Form1 (otherwise it could have been made slightly easier, by directly increasing/decreasing the value in Form2, and send the absolute value. Alternativly have a parameterless event and a public property of Form2 from which Form1 would get the current value when the event was raised).public partial class Form1 : Form{public Form1(){InitializeComponent();form2 = new Form2();form2.ButtonPressed += new EventHandler<ButtonPressedEventArgs>(delegate(object sender, ButtonPressedEventArgs e){switch (e.ButtonType) {case ButtonType.Increase:magicValue++;break;case ButtonType.Decrease:magicValue--;break;}labelMagicValue.Text = magicValue.ToString();});}private void Form1_Load(object sender, EventArgs e){form2.Show();labelMagicValue.Text = magicValue.ToString();}private Form2 form2;private int magicValue = 42;}public partial class Form2 : Form{public Form2(){InitializeComponent();}public event EventHandler<ButtonPressedEventArgs> ButtonPressed;protected void OnButtonPressed(ButtonPressedEventArgs e) { if (ButtonPressed != null) ButtonPressed(this, e); }private void buttonIncrease_Click(object sender, EventArgs e){OnButtonPressed(new ButtonPressedEventArgs(ButtonType.Increase));}private void buttonDecrease_Click(object sender, EventArgs e){OnButtonPressed(new ButtonPressedEventArgs(ButtonType.Decrease));}}public class ButtonPressedEventArgs : EventArgs{public ButtonPressedEventArgs(ButtonType buttonType){ButtonType = buttonType;}public readonly ButtonType ButtonType;}public enum ButtonType{Increase,Decrease}Screenshot to clarify meaning of variable names:You'll note that there is no need for any invalidation, and that anonymous methods are handy.I hope that sample code made it clear, but in case not I zipped and uploaded the sample project (VC#EE 2005): compilable sample.[Edited by - Enselic on May 28, 2006 2:33:18 PM]