473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why does my new-ed form keep closing on me right after Show()-ing?

Hi all,

I'm certain this is stupid, but I'd like to know how to keep a form
open for, say, longer than 1ms. Here's the code I'm using to open my
form:

TestModelFileReaderForm modelInfo = new TestModelFileReaderForm();
modelInfo.txtModelInfo.Text = elementInfo;
modelInfo.Show();

MessageBox.Show("Done walidating DTD", "Walidator");
I exposed a textbox on the modelInfo form, and assign some text to it.

The reason for the MessageBox is that without it, the modelInfo form
will disappear as soon as its opened.

I've seen new-ed form code that *looks* just like mine, but (a) their
$%^$% windows stay open, and (b) they don't even need the form's Show()
method to be called - they just appear on the screen on their own.

How can I get this form to stay on the screen?

thanks in advance,

cdj

Aug 29 '06 #1
5 1508

sherifffruitfly wrote:
Hi all,

I'm certain this is stupid, but I'd like to know how to keep a form
open for, say, longer than 1ms. Here's the code I'm using to open my
form:

TestModelFileReaderForm modelInfo = new TestModelFileReaderForm();
modelInfo.txtModelInfo.Text = elementInfo;
modelInfo.Show();

MessageBox.Show("Done walidating DTD", "Walidator");
I exposed a textbox on the modelInfo form, and assign some text to it.

The reason for the MessageBox is that without it, the modelInfo form
will disappear as soon as its opened.

I've seen new-ed form code that *looks* just like mine, but (a) their
$%^$% windows stay open, and (b) they don't even need the form's Show()
method to be called - they just appear on the screen on their own.

How can I get this form to stay on the screen?
We would need to see the code for the TestModelFileReaderForm class.

Aug 29 '06 #2

Bruce Wood wrote:
We would need to see the code for the TestModelFileReaderForm class.
Oh. Ok. I think that code is just what VS came up with after I drew the
form in Designer, but here ya go:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestMaker
{
/// <summary>
/// Summary description for TestModelFileReaderForm.
/// </summary>
public class TestModelFileReaderForm : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox txtModelInfo;
public System.Windows.Forms.Label lbl_ModelInfo;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public TestModelFileReaderForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

And then there's the InitializeComponent() method, that's
autogenerated:

private void InitializeComponent()
{
this.lbl_ModelInfo = new System.Windows.Forms.Label();
this.txtModelInfo = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// lbl_ModelInfo
//
this.lbl_ModelInfo.Location = new System.Drawing.Point(24, 8);
this.lbl_ModelInfo.Name = "lbl_ModelInfo";
this.lbl_ModelInfo.Size = new System.Drawing.Size(464, 16);
this.lbl_ModelInfo.TabIndex = 0;
this.lbl_ModelInfo.Text = "Model Info for ";
//
// txtModelInfo
//
this.txtModelInfo.Location = new System.Drawing.Point(24, 24);
this.txtModelInfo.Multiline = true;
this.txtModelInfo.Name = "txtModelInfo";
this.txtModelInfo.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
this.txtModelInfo.Size = new System.Drawing.Size(464, 400);
this.txtModelInfo.TabIndex = 1;
this.txtModelInfo.Text = "";
//
// TestModelFileReaderForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 446);
this.Controls.Add(this.txtModelInfo);
this.Controls.Add(this.lbl_ModelInfo);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "TestModelFileReaderForm";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "TestModelFileReaderForm";
this.ResumeLayout(false);

}
#endregion
}

Aug 29 '06 #3
Actually, it sounds like your Application terminated.

TestModelFileReaderForm modelInfo = new TestModelFileReaderForm();
modelInfo.txtModelInfo.Text = elementInfo;
Application.Run(modelInfo);

jliu

sherifffruitfly wrote:
Bruce Wood wrote:
We would need to see the code for the TestModelFileReaderForm class.

Oh. Ok. I think that code is just what VS came up with after I drew the
form in Designer, but here ya go:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace TestMaker
{
/// <summary>
/// Summary description for TestModelFileReaderForm.
/// </summary>
public class TestModelFileReaderForm : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox txtModelInfo;
public System.Windows.Forms.Label lbl_ModelInfo;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public TestModelFileReaderForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

And then there's the InitializeComponent() method, that's
autogenerated:

private void InitializeComponent()
{
this.lbl_ModelInfo = new System.Windows.Forms.Label();
this.txtModelInfo = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// lbl_ModelInfo
//
this.lbl_ModelInfo.Location = new System.Drawing.Point(24, 8);
this.lbl_ModelInfo.Name = "lbl_ModelInfo";
this.lbl_ModelInfo.Size = new System.Drawing.Size(464, 16);
this.lbl_ModelInfo.TabIndex = 0;
this.lbl_ModelInfo.Text = "Model Info for ";
//
// txtModelInfo
//
this.txtModelInfo.Location = new System.Drawing.Point(24, 24);
this.txtModelInfo.Multiline = true;
this.txtModelInfo.Name = "txtModelInfo";
this.txtModelInfo.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
this.txtModelInfo.Size = new System.Drawing.Size(464, 400);
this.txtModelInfo.TabIndex = 1;
this.txtModelInfo.Text = "";
//
// TestModelFileReaderForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 446);
this.Controls.Add(this.txtModelInfo);
this.Controls.Add(this.lbl_ModelInfo);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "TestModelFileReaderForm";
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "TestModelFileReaderForm";
this.ResumeLayout(false);

}
#endregion
}
Aug 30 '06 #4

John Liu wrote:
Actually, it sounds like your Application terminated.

TestModelFileReaderForm modelInfo = new TestModelFileReaderForm();
modelInfo.txtModelInfo.Text = elementInfo;
Application.Run(modelInfo);
Close - the function that new-ed the form terminated - thus (I assume)
terminating everything declared within it.

I had the notion that new-ed objects - heap stuff - would persist past
the function they were new-ed in. My mistake. My fix was to call
myform.ShowDialog() rather than myform.Show() - that forces execution
to wait until the form is closed, which is good enough for me.

Aug 30 '06 #5
I suggest reading up the topics about application message loop,
Application class, Application.Run and Application.Quit

jliu - johnliu.net

sherifffruitfly wrote:
John Liu wrote:
Actually, it sounds like your Application terminated.

TestModelFileReaderForm modelInfo = new TestModelFileReaderForm();
modelInfo.txtModelInfo.Text = elementInfo;
Application.Run(modelInfo);

Close - the function that new-ed the form terminated - thus (I assume)
terminating everything declared within it.

I had the notion that new-ed objects - heap stuff - would persist past
the function they were new-ed in. My mistake. My fix was to call
myform.ShowDialog() rather than myform.Show() - that forces execution
to wait until the form is closed, which is good enough for me.
Aug 31 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Supra | last post by:
in vc.net... private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) { Bitmap bmp = new Bitmap(e.Bounds.Width,e.Bounds.Height,e.Graphics); Graphics g = Graphics.FromImage(bmp); ...
4
by: Schraalhans Keukenmeester | last post by:
I have no clue why below code (found it somewhere and altered it a wee bit to my needs) will run without problem in both IE and Mozilla FireFox 1.0 but in the latter it takes up close to 100% cpu....
4
by: Astronomically Confused | last post by:
using System; using System.Collections; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; class HttpProcessor { private Socket s;
2
by: Besta | last post by:
Hello all, I am having trouble creating a windows service with a timer. Everything seems to go ok but the elapsed event does not fire.Can anyone shed any light on this, may be something simple as...
18
by: Daniel | last post by:
Hey guys I have an instance of an object say: List<Object> myList = new List<Object>(); Object myObject = new Object(); myObject.PositionVector = new Vector3(10,10,10); ...
52
by: Julie | last post by:
I'm supporting an application at work. Below are some code segments that I can't understand how they work. First let me say, I would never code this standard. I'm just really creeped out that it...
3
by: Joachim Klassen | last post by:
Hi all, if I accidentally use a TAKEOVER command with BY FORCE clause while primary and standby are in peer state I'll end up with two primary's (at least with FP10 and Windows). Is this works ...
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
14
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does K = parseInt('09') set K to 0? ----------------------------------------------------------------------- ...
6
by: schnag | last post by:
import java.util.*; class Student { private String name; private int score; public Student() { name = ""; score = 0; }
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.