Hi! I try to show Windows Form but the form is showing for a moment and after that closes itself. Is Someone can help me???

Would you mind showing us the code? I cannot know what can be wrong.

WindowsForm windowsForm = new WindowsForm();
windowsForm.Show();

It shown for a moment after that the form closes itself.

Explain: What type is a WindowsForm?
When I use a form it is normally derived from the Form class. A class that lives in the System.Windows.Forms namespace.

WindowsForm windowsForm = new WindowsForm();
windowsForm.Show();

It shown for a moment after that the form closes itself.

Provide the whole method that is in. I suspect the method ends right after the Show, which makes the variable windowsForm go out of scope, which closes the window.

hey i think u should try changing the objecy name instead of
WindowsForm windowsForm = new WindowsForm();
windowsForm.Show();
should write

WindowsForm win = new WindowsForm();
win.Show();

This doesnt make any difference. Do you have any other code maybe, which would intentioanlly close your "WindowsForm"?

There`s got to be something, because form can close just by it self. Please double check whole code!!

This is my method:

private void labelBox_DoubleClick(object sender, EventArgs e)
        {
            LabelBox.CustomLabel labelBox = (LabelBox.CustomLabel)sender;
            string identifier = labelBox.Identifier;

            string query = "Extract Address" + SEPARATOR + identifier;
            StreamManager strmManager = new StreamManager(address, PORT);
            string userAddress = (string)strmManager.ExecuteQuery(query);

            if ((userAddress != null) && !(userAddress.Equals(String.Empty)))
            {                
                FunnyChatForm funnyChat = new FunnyChatForm(userAddress);
                funnyChat.Identificator = identifier;
                funnyChat.Show();

                funnyChatServer.funnyChatFormList.Add(funnyChat);                
            }
        }

I believe your problem lies outside of the code shown here. Could you zip your project and upload it to this thread?

I can't upload it before is finished. Sorry !!! I'll solve my problem alone. I don't now how. This information that i give you is all there i can share with you.

The only other way I know to catch this is by overriding the OnClosing / OnFormClosing / OnVisibleChanged and setting a breakpoint, and setting a breakpoint in the Form.Designer.cs file.

This method will already exist in the Form.Designer.cs file. One line was added:

protected override void Dispose(bool disposing)
    {
      System.Diagnostics.Debugger.Break(); //add this line
      if (disposing && (components != null))
      {
        components.Dispose();
      }
      base.Dispose(disposing);
    }

Add these lines in your Form.cs file:

protected override void OnClosing(CancelEventArgs e)
    {
      System.Diagnostics.Debugger.Break();
      base.OnClosing(e);
    }
    protected override void OnFormClosing(FormClosingEventArgs e)
    {
      System.Diagnostics.Debugger.Break();
      base.OnFormClosing(e);
    }
    protected override void OnVisibleChanged(EventArgs e)
    {
      System.Diagnostics.Debugger.Break();
      base.OnVisibleChanged(e);
    }

More than likely that should smoke out the culprit. Once you hit one of those breakpoints take a look at the callstack and see which method is closing the form. You might have to open the call stack window (Debug -- Windows -- Call Stack CTRL+D, C)

The OnVisibleChanged when the form first shows and becomes visible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.