Click here to Skip to main content
15,901,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataGrid, Generic GDI+ errors, and a Big Red X Pin
ABean19-May-04 15:11
ABean19-May-04 15:11 
GeneralC#'s sprintf Pin
ABean19-May-04 13:19
ABean19-May-04 13:19 
GeneralRe: C#'s sprintf Pin
Heath Stewart19-May-04 13:24
protectorHeath Stewart19-May-04 13:24 
GeneralRe: C#'s sprintf Pin
ABean19-May-04 13:26
ABean19-May-04 13:26 
GeneralRe: C#'s sprintf Pin
ABean19-May-04 13:25
ABean19-May-04 13:25 
GeneralRe: C#'s sprintf Pin
Heath Stewart19-May-04 13:32
protectorHeath Stewart19-May-04 13:32 
GeneralRe: C#'s sprintf Pin
ABean19-May-04 13:46
ABean19-May-04 13:46 
GeneralMysterious behaviour (freezing) Pin
GuntherR19-May-04 12:40
GuntherR19-May-04 12:40 
Confused | :confused: Confused | :confused: Confused | :confused:
If somebody could make sense of the behaviour of the following code, I'd be really happy.

On the second line, either #define CRASH to have it crash or don't to have it, well, not crash.
Then just pick the menu items sequentially from 1 to 4.
The only difference is that in the crashing version, a UserControl is added as a control to a Panel instead of directly to a Form...
After closing the form created in step 4, the application freezes, sometimes terminates with an ObjectDisposedException ...

Cheers,

Gunther OMG | :OMG:

------------- CODE STARTS HERE -------------

// define "CRASH" to have it crash when you go from 1 to 4 ...

#define CRASH

using System;

namespace TestApp
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form1());
}


private System.Windows.Forms.Panel panel1;

public Form1()
{
this.panel1 = new System.Windows.Forms.Panel();

this.SuspendLayout();
//
// Menu
//
this.Menu = new System.Windows.Forms.MainMenu();
System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem("Crashing!?");
this.Menu.MenuItems.Add(mi);
mi = new System.Windows.Forms.MenuItem("1. Create Control");
mi.Click += new EventHandler(this.Create_Click);
this.Menu.MenuItems[0].MenuItems.Add(mi);
mi = new System.Windows.Forms.MenuItem("2. Display Dialog");
mi.Click += new EventHandler(this.Dialog_Click);
this.Menu.MenuItems[0].MenuItems.Add(mi);
mi = new System.Windows.Forms.MenuItem("3. Destroy Control");
mi.Click += new EventHandler(this.Destroy_Click);
this.Menu.MenuItems[0].MenuItems.Add(mi);
mi = new System.Windows.Forms.MenuItem("4. Display Dialog");
mi.Click += new EventHandler(this.Dialog_Click);
this.Menu.MenuItems[0].MenuItems.Add(mi);
mi = new System.Windows.Forms.MenuItem("-");
this.Menu.MenuItems[0].MenuItems.Add(mi);
mi = new System.Windows.Forms.MenuItem("Quit");
mi.Click += new EventHandler(this.Quit_Click);
this.Menu.MenuItems[0].MenuItems.Add(mi);

//
// panel1
//
this.panel1.AutoScroll = true;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(464, 326);
this.panel1.TabIndex = 1;

//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(464, 326);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

#if (CRASH)
#else
this.panel1.Hide();
#endif
}


private void Quit_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void Destroy_Click(object sender, System.EventArgs e)
{
#if (CRASH)
for (int i = this.panel1.Controls.Count - 1; i >= 0; i--)
{
if (this.panel1.Controls[i].GetType() == typeof(System.Windows.Forms.UserControl))
this.panel1.Controls.RemoveAt(i);
}
#else
for (int i = this.Controls.Count - 1; i >= 0; i--)
{
if (this.Controls[i].GetType() == typeof(System.Windows.Forms.UserControl))
this.Controls.RemoveAt(i);
}
#endif
}

private void Create_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.UserControl umc = new System.Windows.Forms.UserControl();
umc.Controls.Add(new System.Windows.Forms.TextBox());
#if (CRASH)
this.panel1.Controls.Add(umc);
#else
this.Controls.Add(umc);
#endif
}

private void Dialog_Click(object sender, System.EventArgs e)
{
// show dialog
System.Windows.Forms.Form d = new System.Windows.Forms.Form();
d.ShowDialog();
d.Dispose();
}

}
}

GeneralRe: Mysterious behaviour (freezing) Pin
je_gonzalez19-May-04 18:02
je_gonzalez19-May-04 18:02 
GeneralRe: Mysterious behaviour (freezing) Pin
GuntherR20-May-04 3:43
GuntherR20-May-04 3:43 
GeneralDllImport specification Pin
Colin Angus Mackay19-May-04 11:59
Colin Angus Mackay19-May-04 11:59 
GeneralRe: DllImport specification Pin
David M. Kean19-May-04 12:41
David M. Kean19-May-04 12:41 
GeneralRe: DllImport specification Pin
Heath Stewart19-May-04 13:25
protectorHeath Stewart19-May-04 13:25 
GeneralRe: DllImport specification Pin
David M. Kean19-May-04 16:11
David M. Kean19-May-04 16:11 
GeneralRe: DllImport specification Pin
Colin Angus Mackay21-May-04 9:13
Colin Angus Mackay21-May-04 9:13 
GeneralDesigner error Pin
Steve Schaneville19-May-04 11:47
professionalSteve Schaneville19-May-04 11:47 
GeneralRe: Designer error Pin
Heath Stewart19-May-04 13:36
protectorHeath Stewart19-May-04 13:36 
GeneralRe: Designer error Pin
Steve Schaneville19-May-04 17:08
professionalSteve Schaneville19-May-04 17:08 
GeneralRe: Designer error Pin
Heath Stewart19-May-04 18:40
protectorHeath Stewart19-May-04 18:40 
GeneralRe: Designer error Pin
Steve Schaneville19-May-04 18:55
professionalSteve Schaneville19-May-04 18:55 
GeneralRe: Designer error Pin
Heath Stewart19-May-04 19:05
protectorHeath Stewart19-May-04 19:05 
GeneralRe: Designer error Pin
Steve Schaneville19-May-04 19:16
professionalSteve Schaneville19-May-04 19:16 
GeneralHelp with CR 9 for C#.NET Pin
frank2119-May-04 10:52
frank2119-May-04 10:52 
GeneralRe: Help with CR 9 for C#.NET Pin
Heath Stewart19-May-04 11:00
protectorHeath Stewart19-May-04 11:00 
GeneralRe: Help with CR 9 for C#.NET Pin
frank2120-May-04 2:21
frank2120-May-04 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.