Invoke method

N

Nina

I would like to call BringToFront() method using Control.Invoke method. How
can I add it to my code?

private void thread_Execute()
{
SetControlBringToFront(this); // SetControlBringToFront(this, BringToFront());
}

private delegate void SetControlBringToFtontDelegate(Control ctrl, Delegate
method);
void SetControlBringToFront(Control ctrl, Delegate method)
{
ctrl.BeginInvoke(new SetControlBringToFtontDelegate(SetControlBringToFront),
ctrl, method);
}
 
C

Chris Tacke, eMVP

Something like this?

if (myControl.InvokeRequired)
{
myControl.Invoke(new EventHandler( delegate (object o, EventArgs a)
{
myControl.BringToFront();
}));
}
else
{
myControl.BringToFront();
}

Should be 2.0 and 3.5 compatible. If you're 3.5-only it can be a little
simpler as you can probably forego typing the delegate.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
N

Nina

I have other code that should be using Invoke Method too. How can I do it?

Items = new ArrayList();
DataGrid.DataSource = Items;

DataGridTableStyle ts = new DataGridTableStyle();
DataGrid.TableStyles.Clear();
DataGrid.TableStyles.Add(ts);

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top