c# form losing focus - c#

When i run my application with visual studio IDE, the application runs fine. When i run directly the executable it is not running fine.
My app creates two forms. First form losts focus when the second form is about to create. The first form UI frezzes when i run directly executable.
Please give any suggestions how to debug the problem.
Regards
Raju

Setting the First form property Topmost to true solved the prolem.

Related

c# Winforms can't open minimized form

I have a rather large win forms project that includes a form that opens another form that includes static information for our employees while working on the other form. (I will call the form that is opened the edit form and the informational form the information form for purposes of this question) The problem that I am having is that if they happen to minimize the edit form, they must click on the minimized edit form several times to open it, each time with a ding being heard until it works. This problem is not reproducible in my development environment, but is in the deployed environments including our production and test environments. I have worked backwards commenting out stuff until it went to working, and found that when this information form is accessing the data model is when the problem happens, if I don't let the information form access the datamodel the forms will open up as expected.
Additional Information:
.Net 4.0
Information Form includes a user control
Visual Studio 2013
If anyone has any clue as to what may be causing this issue or something that may help me find this issue it would be much appreciated. I have attempted looking at process monitor to no avail.

Visual Studio - End debugger only when all forms have been closed

I'm working in Visual Studio 2013 Premium on a Windows forms project. When I'm debugging my windows forms project and I close my start up form, all other forms stop too. I googled this problem and saw that in project --> properties there is a drop down list where you're able to change shutdown mode, which would solve my problem.
The shutdown mode option however is not present at my application properties. I can't find it anywhere else and searching the web didn't resolve this problem for me either, so what could it be?
That only applies to Visual Basic projects.
Here's your options:
For Visual Basic projects, twiddle the option you found on Google
For C# WPF projects, you can set the Application.ShutdownMode property
For C# WinForms projects, you must either:
Accept that it will close when the main form closes
Prevent the main form from closing until all other forms have closed
The Application.OpenForms Property should be helpful to you:
Definition:
Gets a collection of open forms owned by the application.
Example:
In the closing event of the main application you can put following code that will check if there's more than 1 form opened.
var openForms = Application.OpenForms;
if(openForms.Count > 1)
{
//More than 1 form is opened: cancel the close-event
}
else
{
}

VS2010 designer window is executing my form

Am I crazy or is this normal operation. Visual Studio 2010 SP1.
I have a .NET 3.5 (C#) base form with a few inherited classes. Whenever I open the inherited form in designer view it actually starts running my code... I'm not even executing or debugging.
Example:
I need my form to start a named pipe server which is created in the FormLoad event. Whenever I open the form in designer view, it actually starts up the pipe server.
Maybe I just don't fully understand how designer view works?
Edit: I know it's actually running because I'm trying to debug my pipe code and every time I open the designer window, it starts throwing pipe exceptions at me. I can also see through process explorer that devenv.exe is starting up my pipe instances when I'm not debugging.
Yes, the designer is actually "running" your form.
If you want to avoid this, just put your critical code inside an if block like so:
if(!this.DesignMode) //this is the Form
{
....
}
Cheers

Debug a WPF window or Windows Form without running your application?

I'm new to WPF and have a question which quite same with the article: "Walkthrough: Debug a WPF window or Windows Form without running your application".
The link: http://blogs.msdn.com/b/habibh/archive/2009/07/17/walkthrough-debug-a-wpf-window-or-windows-form-without-running-your-application-video.aspx
I will take the picture as an example:
http://blogs.msdn.com/blogfiles/habibh/WindowsLiveWriter/DebugaWPFwindoworWindowsFormwithoutrunni_FD38/image_3.png
From the picture, the project have 4 WPF windows such as:
App.xaml
Create...so on.xaml
MainWindows.xaml
ViewChart... so on.xaml
When every time in VS 2010, I click on the starting debugging (F5) or start without debugging(Ctrl + F5) will always run the MainWindows.xaml. What the reason coz this? Is this because of in the App.xaml that we declare StartupUri="MainWindow.xaml".
Can I run the particular WPF windows such number 4. ViewChart... so on.xaml instead of the whole application(*Such as the MainWindows.xaml)?
The article you linked is out of date and the video that demonstrates his solution is no longer hosted. However, the basic steps that were outlined in the video are still possible, though the process can be more trouble than it's worth.
The process is as follows:
Open the Immediate Debugger window (Debug -> Windows -> Immediate Window)
In the Immediate mode, create an instance of the window you are wishing to test.
call the ShowDialog() method on your Immediate instance.
The main trouble with this method of debugging is that if your window has a complex constructor or has dependencies on external objects, you may end up spending more time setting up the dependencies than just navigating to the page would have taken.

Main program window sometimes hides behind previous window when opening from installer

I have tried two installers - Setup2go, and Installmate Builder, and I have the same problem. At the last window of the install, I select the option to "Open program after installation finish", and sometimes (about 10% of the time?), my (Winforms) app's main window will open behind the Windows Explorer directory window I used to open the installation exe from.
The frustrating thing is - I am having trouble reproducing the problem reliably (the problem seems to occur around 10-20% of the time). I am using Windows 7 if that makes any difference. To clarify, if I open up the executable directly (rather than from the installation exe), the problem never occurs.
My knowledge on this kind of thing is limited - I recall a similar frustration happening with the MessageBox from this question
Any ideas?
It does not happen when you launch the app directly from installer because the shell allows it to “steal” the focus. When you launch it from the installer, the last interaction happens in the installer app. The system prevents the new window from stealing the focus from your installer. If installer window closes, then the explorer window which you used to start the installer is activated. Since the switch of the foreground window happened recently, the system does not allow to change the foreground window.
On the other hand, if your application window is shown before the installer window disappears from the screen, the the app will be placed below the installer in the Z-order; and when the installer window is finally hidden, the application window is activated.
So it's all related to timing between showing and hiding windows.
Although I am not expert in this area. You can use message tracers and WinAPI calls tracers like Spyxx which can give you more details on what happens in the system and why the new window of your application is placed below the Explorer window.
Make sure the window's title isn't changed, until the last possible moment. I moved the Text = "blahblah" line out of the Form_load event, and into the Form1_Shown event, and now the hidden taskbar icon problem has vanished. Also, the window doesn't flicker when it's loading.

Categories