Originally Posted by
Artificial_Intelligence
let me see if i get what your saying:
is i want to use a method_A on a formA to show a formB and then use
a methodG_on_FormB to send data back to FormA i would have to A:Threading or B:IPC (The forms will have to be seperate apps) ?
In theory, separate message loops, no modal blocking, but not necessarily different apps, and your right threads would be different.
I am sure why the 'public' implementation is not what you want, but for me, that implementation would be the one of choice.
Anyway, I tried a win proc messaging app, but then I found a better way to do it with threading while looking at an example of how to make cross thread call on a Control.
Here is the code in .Net 2.0 C#. I commented out the win proc because that was not needed anymore. I also used some global variables which may not be accepted in your particular case, I hope not.
Program.cs
Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
static class Program
{
static Form1 A;
static Form2 B;
[STAThread]
static void Main()
{
A = (new Form1());
B = (new Form2());
B.Tag = A;
Thread t1 = new Thread(new ThreadStart(RunA));
Thread t2 = new Thread(new ThreadStart(RunB));
t1.Start();
t2.Start();
}
static void RunA()
{
A.ShowDialog();
}
static void RunB()
{
B.ShowDialog();
}
}
}
Form1.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
delegate void UpdateTextCallback(string strNew);
public Form1()
{
InitializeComponent();
}
/*
protected override void WndProc(ref Message m)
{
// Listen for operating system messages.
switch (m.Msg)
{
case 777:
MessageBox.Show("A recieved");
break;
}
base.WndProc(ref m);
}
*/
public void UpdateText(string strNew)
{
if (this.txtBoxA.InvokeRequired)
{
this.Invoke(new UpdateTextCallback(this.UpdateText), new object[] { strNew });
}
else
{
this.txtBoxA.Text = strNew;
}
}
}
}
Form2.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void txtBoxB_TextChanged(object sender, EventArgs e)
{
/*
Message m = Message.Create(this.Handle, (777), new IntPtr(0), new IntPtr(0));
this.WndProc(ref m);
*/
/*
Message m = Message.Create(((Form)(this.Tag)).Handle, (777), new IntPtr(0), new IntPtr(0));
((Form)(this.Tag)).WndProc(ref m);
*/
((Form1)(this.Tag)).UpdateText("blah");
}
/*
protected override void WndProc(ref Message m)
{
// Listen for operating system messages.
switch (m.Msg)
{
case 777:
MessageBox.Show("B recieved");
break;
}
base.WndProc(ref m);
}
*/
}
}
Form1.Designer.cs
Code:
namespace WindowsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtBoxA = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtBoxA
//
this.txtBoxA.Location = new System.Drawing.Point(113, 126);
this.txtBoxA.Name = "txtBoxA";
this.txtBoxA.Size = new System.Drawing.Size(67, 20);
this.txtBoxA.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.txtBoxA);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtBoxA;
}
}
Form2.Designer.cs
Code:
namespace WindowsApplication1
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtBoxB = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtBoxB
//
this.txtBoxB.Location = new System.Drawing.Point(113, 126);
this.txtBoxB.Name = "txtBoxB";
this.txtBoxB.Size = new System.Drawing.Size(67, 20);
this.txtBoxB.TabIndex = 1;
this.txtBoxB.TextChanged += new System.EventHandler(this.txtBoxB_TextChanged);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.txtBoxB);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtBoxB;
}
}