Needs to update WinForm (seperate process) to render newly created customized controls
I am facing a strange problem, I have launched a seperate Win Form based process with the help of Process.Start from another process.
That process just dispatched an object which actually contains .NET controls(e.g button,textbox,label,radio button etc) as information (control information I just collected from Injecting other running managed processes). After dispatching , I need to draw these controls on that process having WinForm as main window( as its form based process).
BUT THESE CONTROLS ARE NOT RENDERING ON MAIN FORM WINDOW. Main problem is having with parent control information which is not correct to me.
Take a look at Code
public partial class TestController: Form, IApplicationEventsSink
{
static bool m_ControllerLoadedFirstTime = true;
ITestControl m_TakoControlHandler = null;
public Controller()
{
if (m_ControllerLoadedFirstTime == true)
{
MessageBox.Show("TAKOController called first time");
InitializeComponent();
m_ControllerLoadedFirstTime = false;
}
else
MessageBox.Show("TAKOController called second time");
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Form1_Load");
initEnvironment();
bool bSubscriptionCreated = createSubscription();
if (bSubscriptionCreated == false)
throw new Exception(String.Format("Controller failed to create subscription with Simulator process!!"));
}
public ITestControl CreateControl(CustomControl a_CustomControl)
{
ITestControl TakoControlHandler = Factory.CreateControl(a_CustomControl);
m_TakoControlHandler = TakoControlHandler;
return TakoControlHandler;
}
private void SetProperties(CustomControl a_CustomControl)
{
m_TakoControlHandler.setPropeties(a_CustomControl);
}
public void OnProcess(CustomControl a_CustomControl)
{
MessageBox.Show("OnProcess");
ITestControl TakoHandler = CreateControl(a_CustomControl);
if (TakoHandler != null)
{
SetProperties(a_CustomControl);
m_TakoControlHandler.SetParentHandle(base.Handle);
}
base.Refresh();
base.Update();
base.Show();
}
}
while Control that I need to render after creating it.
public class TestButton : Button
{
Control m_Control;
public TestButton()
{
m_Control = new Button();
}
public void SetParentHandle(IntPtr a_ControlHandle)
{
Contro开发者_Python百科l ParentControl = Control.FromHandle(a_ContainerHandle);
this.m_Control.Parent = ParentControl;
}
}
any body having any idea? I would be greatly obliged. Regards Usman
Your control is not going to render on the main form window without adding the control to the form's control collection.
In your OnProcess function, you need to do something like this:
this.Controls.Add(a_CustomControl);
精彩评论