[dba-VB] SCRUM: Northwind.NET project Design Note

Salakhetdinov Shamil mcp2004 at mail.ru
Fri Mar 27 12:58:58 CDT 2009


Hi Mike,

When you do renaming buttons that should work - you get new button name but still old name of event procedure but code shoudl compile and this event procedure should work.

I guess you could have made some other edits, which resulted in design time error message.

Please don't give up when you'll see all that "Object Not Instantiated" messages etc. - just type

CTRL+SHIFT+B to rebuild solution and then

Ctrl+\, Ctrl+E to show "Errors List" window 

and from the latter window by clicking on its entries you csn go directly to the code lines resulting in that error messages - and edit/fix code manually....

Master these skills now when the project is simple...

WinForm code in VS2008 consists from two standard code files constituting *one* class:

1. {{FormName}}.cs - part of partial form class to implement custom logic
2. {{FormName}}.Designer.cs  - part of partial form class used by form designer on design time as well as to instantiate form on runtime - have a look what code you have for Form1 and button1 control with Cick event having its empty event procedure:

Form1.cs
=========

  public partial class Form1 : Form
    {
        ...
        private void button1_Click(object sender, EventArgs e)
        {

        }
    }


Form1.Designer.cs
==================

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            ...
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(37, 46);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click_1);
            // 

 ...


When you rename button1 to addProductButton you'll get
...
            this.addProductButton = new System.Windows.Forms.Button();
...
            // 
            // addProductButton
            // 
            this.addProductButton.Location = new System.Drawing.Point(37, 46);
            this.addProductButton.Name = "addProductButton";
            this.addProductButton.Size = new System.Drawing.Size(75, 23);
            this.addProductButton.TabIndex = 0;
            this.addProductButton.Text = "button1";
            this.addProductButton.UseVisualStyleBackColor = true;
            this.addProductButton.Click += new System.EventHandler(this.button1_Click_1);

...

You can go and rename the rest manually like that:

Form1.cs
=========

  public partial class Form1 : Form
    {
        ...
        private void addProductButton_Click(object sender, EventArgs e)
        {

        }
    }


Form1.Designer.cs
==================

        private void InitializeComponent()
        {
            this.addProductsButton = new System.Windows.Forms.Button();
            ....
            this.SuspendLayout();
            // 
            // addProductButton
            // 
            this.addProductButton.Location = new System.Drawing.Point(37, 46);
            this.addProductButton.Name = "addProductButton";
            this.addProductButton.Size = new System.Drawing.Size(75, 23);
            this.addProductButton.TabIndex = 0;
            this.addProductButton.Text = "Add Product";
            this.addProductButton.UseVisualStyleBackColor = true;
            this.addProductButton.Click += new System.EventHandler(this.addProductButton_Click);

 ...

and everything should work OK.

I'm doing such renamings almost automatically when needed.
There are other ways to fix this issue.
Please note control names are started from lowerCase and use camelCase - that's a used by most of the developers namng convention recommended by MS.

Once again please do such renaming several times in a test project or directly in our main project - don't be afarid doing that - it's a usual practice.

Note that in designer part of code the code is usually hidden in VS2008 because of using 

#region Windows Form Designer generated code
....
#endregion

Sorry I can't write in all the details - such writing takes a lot of time...

Note (as in the case with strongly typed datasets we discussed here in another thread) there is Design and Run-Time modes for many parts of code you develop under VS - but some code (as for forms) can be changed manually while the other (as for strongly typed datasets) should be better kept untouched to not get your project heavily screwed...

For forms all the design information is stored in code and interpreted/executed by VS designers on design time but for strtongly typed datasets there are also some xml files keeping those datasets attributes and properties and those xml files are used by VS to generate C# code used on runtime....

Thank you.

--
Shamil


-----Original Message-----
From: "Mike Mattys" <mmattys at rochester.rr.com>
To: "Salakhetdinov Shamil" <mcp2004 at mail.ru>,"Discussion concerning Visual Basic and related programming issues." <dba-vb at databaseadvisors.com>
Date: Fri, 27 Mar 2009 09:50:48 -0400
Subject: Re: [dba-VB]SCRUM: Northwind.NET project Design Note

> Having added two buttons, button1 and button2, I double-clicked
> on button1 to add an event procedure to open the Products form.
> 
> Then I realized that I wanted to name the buttons ReviewProductsButton
> and AddProductsButton. I did so and saved. All sorts of errors ensued.
> "Object Not Instantiated" blah!
> 
> I reverted to my previous form using SVN.
> 
> -
> Michael R Mattys
> MapPoint and Database Dev
> www.mattysconsulting.com
> -
> 




More information about the dba-VB mailing list