Wrox Programmer Forums
|
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2009, 09:45 PM
Registered User
 
Join Date: Mar 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Windows Form won't display after Pressing F5

hi there, I'm new to C# and using the Beginning C# Book. I'm a bit embarrassed to ask this question but I'm stumped...here I go:

I performed steps in Chapter 2, Pages 36-44. However, when I press F5 (or click the Green Arrow) to execute the code -- my form won't pop up. There are no errors in the bottom of Visual Studio. I went online and grabbed the source code and it runs fine (The form will popup and you can enter data). However, If I copy/paste the source code into my own project - I notice the same behavior, I can click F5 to execute it and no errors show up in the dialog messages but the form simply won't popup.

Since the code from the book won't work when I copy/paste the code into my project, I assume its some type of MSFT Visual C# 2008 Express settings but I'm stumped. Under Project Properties --> Application, I have Output Type = Windows Application and StartupObject = frmMain. I have a similar problem in Chapter 3, Pages 57-60...again, I think its some setting in my Visual Studio that is preventing the Windows form from popping up.

Any ideas where I can look?
 
Old March 9th, 2009, 03:28 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

hmm... whats the loop look like in your main method?

if your init code looks like this:

Code:
 
FormClass frmObject = new FormClass();
frmObject.Show();
then that would explain it... you need to keep it in some kind of loop or something... a using statement would do just fine. it would ensure that as long as the form object exist, you will keep running the form. visual studio has different code by default and as long as you dont change the main() method you wont have issues... did the book tell you to? go ahead and paste your Main() function here in the code blocks.
 
Old March 9th, 2009, 08:23 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No. Windows forms do not require some explicit loop to be declared to keep the window open (it is true that this is the behavior with XNA Game Studio where a Main loop is required to keep the game running but not the case with a typical Windows Form).

In the Program.cs file you should have some code similar to this:

csharp Code:
[STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

I assume, obviously, that you are using a Program.cs file, however, since you have indicated that you have your startup object set to the Form object this tells me you have moved the Main() method into your form, is that correct?

What you might also try is in the Startup Object combo box change the startup object to (Not Set) and see if that corrects the problem.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old March 9th, 2009, 04:10 PM
Registered User
 
Join Date: Mar 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Let me try another thing

hmm, I took the solution and tried it out on a different computer. Now, on that computer the Form pops up but its blank when it should have the Mailing Label program. If I run the book source code, it works fine.

Let me take a step back and retry everything from scratch..maybe I didn't follow directions exactly right. I've written stuff in MSFT Poweshell (basic stuff) but this is my first time using a real IDE and using C#.

I will report back tomorrow what I find.
 
Old March 9th, 2009, 10:21 PM
Registered User
 
Join Date: Mar 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to get Form to display

Hi Doug and Iceman, thanks for your responses.

Down below is my code and my output. I went through the excerise on Page 36-42 (although this time, instead of adding all the labels and textboxes, I just did one). Syntax checks out OK, and I press F5 and the Form doesn't popup... the screen will move a little bit and then reset back to the original spot and no form. The excerise calls for a empty projtect and when you add a new item, I'm adding a Code File. Also, for my project properties under Application, I have frmMain as Startup Object and Output Type = Windows Application. I tried setting the Startup Object with no set and I got the same result. Doug, your question about where my Main() -- I'm a newbie and don't understand the question (I've done some scripting in the past and zero OOP).

Code:
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
publicclassfrmMain : Form
{
privateTextBox txtName;
privateButton btnDisplayOutput;
privateButton btnExit;
privateLabel label1;
#region Windows code
privatevoid InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.btnDisplayOutput = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
// 
// label1
// 
this.label1.Location = new System.Drawing.Point(135, 36);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Name:";
// 
// txtName
// 
this.txtName.Location = new System.Drawing.Point(182, 36);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(100, 20);
this.txtName.TabIndex = 1;
// 
// btnDisplayOutput
// 
this.btnDisplayOutput.Location = new System.Drawing.Point(59, 106);
this.btnDisplayOutput.Name = "btnDisplayOutput";
this.btnDisplayOutput.Size = new System.Drawing.Size(75, 23);
this.btnDisplayOutput.TabIndex = 2;
this.btnDisplayOutput.Text = "&Display";
this.btnDisplayOutput.UseVisualStyleBackColor = true;
this.btnDisplayOutput.Click += new System.EventHandler(this.btnDisplayOutput_Click);
// 
// btnExit
// 
this.btnExit.Location = new System.Drawing.Point(339, 106);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 3;
this.btnExit.Text = "E&xit";
this.btnExit.UseVisualStyleBackColor = true;
// 
// frmMain
// 
this.ClientSize = new System.Drawing.Size(680, 266);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnDisplayOutput);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label1);
this.Name = "frmMain";
this.Text = "Mailing Label";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public frmMain()
{
InitializeComponent();
}
publicstaticvoid Main()
{
frmMain main = newfrmMain();
Application.Run(main);
}
privatevoid btnDisplayOutput_Click(object sender, EventArgs e)
{
String buffer;
buffer = "Name: " + txtName.Text;
// txtResult.Text = buffer;
}
}
Output:
Code:
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\MCW\My Documents\Visual Studio 2008\Projects\MailingLabel2\MailingLabel2\bin\Debug\MailingLabel2.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0xd30 has exited with code 0 (0x0).
'MailingLabel2.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\MCW\My Documents\Visual Studio 2008\Projects\MailingLabel2\MailingLabel2\bin\Debug\MailingLabel2.exe', Symbols loaded.
The program '[1740] MailingLabel2.vshost.exe: Managed' has exited with code -1073741819 (0xc0000005).
 
Old March 9th, 2009, 10:53 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes I think there is a problem with your dev environment. It might not be Visual Studio but the PC itself. Here is my build output from the code you pasted:

Code:
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'D:\Wrox\261293\p2pHelp\MailingLabel\MailingLabel\bin\Debug\MailingLabel.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'MailingLabel.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 0x530 has exited with code 0 (0x0).
'MailingLabel.vshost.exe' (Managed): Loaded 'D:\Wrox\261293\p2pHelp\MailingLabel\MailingLabel\bin\Debug\MailingLabel.exe', Symbols loaded.


Our outputs are almost identical except that you have one additional line at the very end:
Code:
The program '[1740] MailingLabel2.vshost.exe: Managed' has exited with code -1073741819 (0xc0000005).
This thread might be able to help you: http://social.technet.microsoft.com/...3-3a81cf103274. It seems that that exit code is an access violation so you might not have permission to run the file or something else is going on (its hard to say for sure).

If there is anything I can do to help further let me know.

hth.
-Doug


__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old March 12th, 2009, 08:45 PM
Friend of Wrox
 
Join Date: Sep 2008
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default

If you want to use Iceman's code, change the

frmObject.Show();

to

frmObject.ShowDialog();

This will cause the second form to be shown and allow the user to interact with it.

Dr. Purdum
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
Login Control Behavior when pressing ENTER rsearing ASP.NET 2.0 Basics 6 July 22nd, 2007 08:21 PM
Pressing Enter should fire an event r_ganesh76 ASP.NET 1.0 and 1.1 Professional 4 September 28th, 2004 12:02 AM
Display data into windows explorer din_porwal Pro VB.NET 2002/2003 0 August 26th, 2004 02:09 AM
How to send form data without pressing SUBMIT eapsokha Classic ASP Professional 2 March 1st, 2004 09:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.