Windows form designer generated code being misplaced

B

BobRoyAce

Let's say that I have a form, called Form1. It could have three files
associated with it, which I have listed below together with my
understanding of what "should" be in each:
Form1.vb -- should contain any custom code I've written for the
form
Form1.Designer.vb -- should contain all windows form designer
generated code
Form1.resx -- should contain any resources associated with the
form

I have two questions.

First, why do I sometimes end up without the Form1.Designer.vb file,
where all windows form designer generated code is put into the
Form1.vb file?

Second, why, in cases where I do have the Form1.Designer.vb file, does
a bunch of windows form designer generated code get put into the
Form1.vb file anyway? These would be lines like:

Friend WithEvents spinedNumberOfLocations As
DevExpress.XtraEditors.SpinEdit

I really would like to keep the Designer code in the *.Designer.vb
files always and would like to understand why this is happening.
 
R

RobinS

Are you using .Net 1.1 or .Net 2.0 or above? IIRC, .Net 1.1 put all of the
code in the main form. I use VS2005. I inherited a project that was .Net
1.1, and I converted it, but it still has the code in the main form rather
than a designer file; I'd have to move it myself. I've never seen VS2005 or
VS2008 randomly put code-behind designer code in the main form.

Can you give an example of what you're talking about being included in the
main form that you think should be in the designer.vb file?

RobinS.
GoldMail, Inc.
 
B

BobRoyAce

Are you using .Net 1.1 or .Net 2.0 or above? IIRC, .Net 1.1 put all of the
code in the main form. I use VS2005. I inherited a project that was .Net
1.1, and I converted it, but it still has the code in the main form rather
than a designer file; I'd have to move it myself. I've never seen VS2005 or
VS2008 randomly put code-behind designer code in the main form.

I am using .NET 2.0 and have only ever used VS2005 on this machine,
the machine on which this project was created.
Can you give an example of what you're talking about being included in the
main form that you think should be in the designer.vb file?

Well, like I said, I have forms that have no Designer.vb file at all.
If I remember correctly, and I may not, I had ones that did have a
Designer.vb file, that demonstrated the problem, which had lines like
following:

Friend WithEvents lblAppPath As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtPrinterName As System.Windows.Forms.TextBox
Friend WithEvents btnCheckForPrinterOnline As
DevExpress.XtraEditors.SimpleButton
Friend WithEvents VwRoeCountsByPriorityBindingSource As
System.Windows.Forms.BindingSource
 
B

BobRoyAce

In the cases where there is no Designer.vb file associated with the
form, how do I go about creating the corresponding Designer.vb file?
Do I just add a new class file to the same folder where the form files
are and name it Form.Designer.vb, where Form is the name of the form?
Then, I just grab the windows-generated code from Form.vb and put it
in there (with the needed Partial Class declaration at the beginning)?
 
J

Jeff Gaines

In the cases where there is no Designer.vb file associated with the
form, how do I go about creating the corresponding Designer.vb file?
Do I just add a new class file to the same folder where the form files
are and name it Form.Designer.vb, where Form is the name of the form?
Then, I just grab the windows-generated code from Form.vb and put it
in there (with the needed Partial Class declaration at the beginning)?

As RobinS said I have only seen this behaviour when upgrading a project.
If you start a brand new project does VS produce a Designer.vb file?

It may be more work but I would be inclined to start a new project and
copy and paste across so everything is where VS thinks it should be.
 
J

Jack Jackson

In the cases where there is no Designer.vb file associated with the
form, how do I go about creating the corresponding Designer.vb file?
Do I just add a new class file to the same folder where the form files
are and name it Form.Designer.vb, where Form is the name of the form?
Then, I just grab the windows-generated code from Form.vb and put it
in there (with the needed Partial Class declaration at the beginning)?

I also have never had this happen with projects created in VS2005.

However, if you have such a file and want to add a designer.vb file,
this is how to do it:

Create the xx.designer.vb file.
Add the xx.designer.vb file to the project with Project -> Add
Existing Item.
Close the project.
Make a copy of the .vbproj file in case something goes wrong.
Edit the .vbproj file in a text editor like Notepad. Find the lines
describing the xx.designer.vb file. It should look something like:
<Compile Include="ctlEditbox.Designer.vb" />
Expand the <Compile /> clause to have an ending tag and add a
DependentUpon clause:
<Compile Include="ctlEditbox.Designer.vb">
<DependentUpon>ctlEditbox.vb</DependentUpon>
</Compile>
 
R

RobinS

BobRoyAce said:
I am using .NET 2.0 and have only ever used VS2005 on this machine,
the machine on which this project was created.


Well, like I said, I have forms that have no Designer.vb file at all.
If I remember correctly, and I may not, I had ones that did have a
Designer.vb file, that demonstrated the problem, which had lines like
following:

Friend WithEvents lblAppPath As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtPrinterName As System.Windows.Forms.TextBox
Friend WithEvents btnCheckForPrinterOnline As
DevExpress.XtraEditors.SimpleButton
Friend WithEvents VwRoeCountsByPriorityBindingSource As
System.Windows.Forms.BindingSource

That's definitely strange. What type of project are you creating? Is it an
Application, or did you by chance choose dll or something else like that?

RobinS.
 
B

BobRoyAce

That's definitely strange. What type of project are you creating? Is it an
Application, or did you by chance choose dll or something else like that?

It's just a Windows application.

Just FYI, at least one of the forms was copied from another project.
However, that project was also created in VS2005.

Hopefully, as I add more and more forms to the project, it won't
happen again. If it does, I'll try to catch it right away and figure
out rhyme and reason as to why it's happening.
 
R

RobinS

BobRoyAce said:
It's just a Windows application.

Just FYI, at least one of the forms was copied from another project.
However, that project was also created in VS2005.

Hopefully, as I add more and more forms to the project, it won't
happen again. If it does, I'll try to catch it right away and figure
out rhyme and reason as to why it's happening.

When you added the form from the other project, I assume you did an "Add
Existing Item". Did you just ask for myForm.cs file, or did you include the
designer and resx file? Try it and just include the myForm.cs file; I think
it automatically brings the other two with it.

That's the only thing I can think of. At this point, I would recreate the
dang form if it wasn't too too complicated.

RobinS.
GoldMail, Inc.
 
J

Jack Jackson

It's just a Windows application.

Just FYI, at least one of the forms was copied from another project.
However, that project was also created in VS2005.

Hopefully, as I add more and more forms to the project, it won't
happen again. If it does, I'll try to catch it right away and figure
out rhyme and reason as to why it's happening.

There is a bug in VS2005 that sometimes fails to associate the
designer file with the main file when using Add Existing Item after
moving files from one project to another. The effects of this bug
that I have observed are that the designer file and the main file are
not linked in the Solution Explorer window (they are shown separately,
and the designer file is always shown regardless of the state of Show
All Files), and the designer will not show the control (when the
control is based on a container like UserControl and contains other
controls).

The fix is to modify the .vbproj file as I describe later in this
thread.
 
R

RobinS

Jack Jackson said:
There is a bug in VS2005 that sometimes fails to associate the
designer file with the main file when using Add Existing Item after
moving files from one project to another. The effects of this bug
that I have observed are that the designer file and the main file are
not linked in the Solution Explorer window (they are shown separately,
and the designer file is always shown regardless of the state of Show
All Files), and the designer will not show the control (when the
control is based on a container like UserControl and contains other
controls).

The fix is to modify the .vbproj file as I describe later in this
thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top