Windows form: Focus and Show doesnt work properly
I have an MultiThreaded pplication with many Controls and forms. I have an event regeistered that will开发者_如何学Go call Show Method on a form to show. When the event occur for the first time it executes the method Show but the form is not shown but now if event fires again(2nd, 3rd, ....) the form is shown.
I am making a simple call frm.Show()
.
2nd Problem
In my next application the same thing happen bu instead of show the Focus doesnt work for the first time. I have tried the following properties :
this.WindowState = FormWindowState.Normal;
this.Focus();
//this.BringToFront();
this.TopMost = true;
Are you calling Show() from a different thread than the one in which the form was created? In general Windows Forms Controls are not thread safe and behavior is unpredictable. There are a few ways to do it though if you must. I recommend you read this MSDN article on how to make thread-safe calls: How to: Make Thread-Safe Calls To Windows Forms Controls
精彩评论