SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Parasitic window at compilation

Last post 08-29-2017 9:34 AM by NebulaWAN. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 08-25-2017 9:09 AM

    Parasitic window at compilation

    Hello,

    When I compile a project in Windows Forms, everything goes well but when I execute the binary I have a parasitic window (gray and without information) which appears after closing the binary ... How to prevent it ?

    Thanks

  • 08-27-2017 5:30 PM In reply to

    Re: Parasitic window at compilation

    Does this happen with all your Windows forms projects or one project in particular? Are you able to post some code that others can use to attempt to reproduce the problem? And what versions of SharpDevelop, .net etc are you running (help menu -> about and copy the information from the "About SharpDeveop" tab at the bottom)?

    Simon

  • 08-28-2017 9:36 AM In reply to

    Re: Parasitic window at compilation

    Hello Simon,

    My version of SharpDevelop is 5.1.0 build 5216 (the lastest). I use it on a Windows 7 Pro 64 bits.

    As a beginner, the only program that I study from now is the "welcome world" (with all trees structure).

    I wonder how this window appears because no lines seem to be attached with it ...

    Thank you,

    Nicolas

    Parasitic windows

  • 08-28-2017 10:17 AM In reply to

    Re: Parasitic window at compilation

    Try this way to see the picture if the first not working :

    http://hpics.li/6d530cd

  • 08-28-2017 11:52 AM In reply to

    Re: Parasitic window at compilation

    Looks like you're unintentionally creating and showing an instance of Form (the base class from which the form(s) in your application are derived), which would explain why it has no title or child controls. Does your application contain "new Form()" anywhere in its code?

  • 08-28-2017 1:36 PM In reply to

    Re: Parasitic window at compilation

    Here is the code I use to :

    //using System;
    using System.Windows.Forms;

    namespace Test2
    {
        public partial class MainForm : Form
        {
            public MainForm()
            {
                MessageBox.Show ("Test OK", "Test", MessageBoxButtons.OK);
            }
        }
    }

    It doesn't the seem to call twice ?

     

    Thank you

     

     

     

  • 08-28-2017 5:37 PM In reply to

    Re: Parasitic window at compilation

    hallo NebulaWAN, 

    no reason to worry, your program runs fine :-) 

    when you start a program, the file [Program.cs] is called first. 

    in there you find the codeline:  -- Application.Run(new MainForm());  which calls the constructor of your file MainForm.

    though you have delete the command InitializeComponent(); - it doesn't matter, the program constructs a window,  

    in your case an empty window. it can not display the window first, because you open a MessageBox, which is modal. 

    after you close the MessageBox, your MainForm-form is opened and displayed. 

    but I do not understand, why you only want to display a MessageBox.

     

    regards from Austria, 

    Stefan

     

     

  • 08-28-2017 5:58 PM In reply to

    Re: Parasitic window at compilation

    Ah, it's all clear now :-)

    When you first created the MainForm class (assuming you're using the normal template for a form), the MainForm() constructor would have contained a single line:

    InitializeComponent();

    If you expand the MainForm class in the solution explorer, it should have a dependent class file called MainForm.designer.cs, which contains the InitializeComponent method. Most of the time you shouldn't edit the code in this file manually, (unless you're sure you know what you're doing), because when you use the forms designer to add buttons and textboxes and other controls to the form and to set their properties, the forms designer updates that InitializeComponent method with the code needed to create those controls and add them to your form.

    You've replaced the call to InitializeComponent with a line which displays a MessageBox, so even if you've put controls and whatnot on your form, they never get added to the form at runtime. So the mysterious "parasitic window" which is there when you dismiss the MessageBox (which isn't the whole of your application, it's just one dialogue box that the application displays), is actually your MainForm form. Try putting the InitializeComponent call back into the beginning of the constructor, before any of your own code. The form will at least then be initialised correctly (even if it's only to set the default title) before the MessageBox is displayed.

    Or for a more realistic scenario, drop a button onto your form in the forms designer, double-click it (which is a shortcut for creating an event handler for the button's Click event), and move your call to MessageBox.Show into that event handler. When you run the application, you can then display the MessageBox as many times as you want, just by clicking the button.

    I hope this is all clear, if not then please ask away...

    Simon

  • 08-29-2017 9:34 AM In reply to

    Re: Parasitic window at compilation

    Hello Grayfox and Simon,

    Thanks for your help, I now understand my problem better. I had to be interested in the structure of the language rather than the execution of a particular command !

    I think too much about command line rather than window structure and instance structure.
    Thank you for opening my mind

    Nicolas from Paris, France ;-)

     

     

Page 1 of 1 (9 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.