473,387 Members | 3,684 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,387 software developers and data experts.

Moving Events for Organization

I have a Form which has a great number of events. I thought I would organize
the project by moving some of the code into multiple '.cs' files (since the
Form.cs was getting huge). When I move them, it seems that Visual Studio can
no longer find them when I open a Button object (for example) and double
click on the previously created event. On top of this, Visual Studio creates
a new event that is blank. I know the program can 'see' my moved event as the
program still works fine.

I am just trying to organize a huge project. Is there a way to have Visual
Studio 'rescan' or something so this doesnt happen or is it always
recommended that you just keep the events where Visual Studio puts them?
May 18 '07 #1
4 1358
On Fri, 18 May 2007 16:17:00 -0700, GT <GT@discussions.microsoft.com>
wrote:
[...]
I am just trying to organize a huge project. Is there a way to have
Visual
Studio 'rescan' or something so this doesnt happen or is it always
recommended that you just keep the events where Visual Studio puts them?
How did you move them?

There's no problem moving pieces of code from one source code file to
another. But you have to make sure you correctly keep those pieces in
their respective places. If they belong in a particular class (and surely
they do :) ), they need to still be in that class in the new source code
file. You can use the "partial" keyword with the class declaration to
allow the class to be declared multiple places, combining the elements
from each place.

And of course, don't forget to put everything in the same namespace too.

This all assumes VS 2005. I gather from my discussions with other people
that the "partial" keyword is new, and that in VS 2003 you had to keep
everything in the same file. The only way to break things apart in that
situation would be to put them in an actual different class, and then use
that class from the main class.

Pete
May 19 '07 #2


"Peter Duniho" wrote:
On Fri, 18 May 2007 16:17:00 -0700, GT <GT@discussions.microsoft.com>
wrote:
[...]
I am just trying to organize a huge project. Is there a way to have
Visual
Studio 'rescan' or something so this doesnt happen or is it always
recommended that you just keep the events where Visual Studio puts them?

How did you move them?

There's no problem moving pieces of code from one source code file to
another. But you have to make sure you correctly keep those pieces in
their respective places. If they belong in a particular class (and surely
they do :) ), they need to still be in that class in the new source code
file. You can use the "partial" keyword with the class declaration to
allow the class to be declared multiple places, combining the elements
from each place.

And of course, don't forget to put everything in the same namespace too.

This all assumes VS 2005. I gather from my discussions with other people
that the "partial" keyword is new, and that in VS 2003 you had to keep
everything in the same file. The only way to break things apart in that
situation would be to put them in an actual different class, and then use
that class from the main class.

Pete

Thanks for responding Pete!
I am using VS2005 Express Edition... as for moving them, all i did was just
a cut and paste into a new codefile... and I placed them into a 'public
partial form' same as the one I moved it from... and under the same
namespace. The events work, so i know that on some level it knows where they
are... Also, when I use the combobox in the upper right hand corner of the
development environement, and I select the event that way, it has no porblem
taking me right to it.

It is only when I am going to the event from the graphical Form [Design]
page that it puts me in the wrong place (I assume it is sending me to the
place where it used to be before I moved it). The real annoying thing though
is that sometimes it automatically creates the event as if it hadn't been
created (a blank prototype)... and this of course forces me to select the
blank one and delete it for everything to build fine.

Is there another way to move them that you use? (because it sounds like I
shouldn't be having this issue)

May 19 '07 #3
On Fri, 18 May 2007 19:24:01 -0700, GT <GT@discussions.microsoft.com>
wrote:
Thanks for responding Pete!
Well, you're welcome. I wish I had something more useful to offer (as in,
an actual solution to your question :) ).
I am using VS2005 Express Edition... as for moving them, all i did was
just a cut and paste into a new codefile... and I placed them into a
'public
partial form' same as the one I moved it from... and under the same
namespace.
Sounds right to me.
[...]
Is there another way to move them that you use? (because it sounds like I
shouldn't be having this issue)
I agree you shouldn't be having the issue. As far as I know (knew?) the
VS designer doesn't cache the information about where the event handlers
are. Seems like it'd just use the same "references" database that the
other parts of VS use (used to be called the "browser database", but I'm
not sure what VS is calling it now). And that should get updated when you
build the project.

I assume you've tried doing a complete, clean build. But if you haven't,
you should definitely try that. I'm afraid that beyond that, I don't have
any useful advice. I don't know enough about the inner workings of VS to
be able to explain why it can't track your movements of the event
handlers. Seems like it ought to be able to do that just fine.

Pete
May 19 '07 #4
On Fri, 18 May 2007 19:24:01 -0700, GT <GT@discussions.microsoft.com>
wrote:
[...]
It is only when I am going to the event from the graphical Form [Design]
page that it puts me in the wrong place (I assume it is sending me to the
place where it used to be before I moved it). The real annoying thing
though is that sometimes it automatically creates the event as if it
hadn't
been created (a blank prototype)... and this of course forces me to
select
the blank one and delete it for everything to build fine.

Is there another way to move them that you use? (because it sounds like I
shouldn't be having this issue)
For what it's worth, I went and tried what you did, and ran into the same
problem. It's trivial to reproduce. I was unable to find any magic file
I could delete and get things to work. I did find that when I deleted the
hidden "cache" file that sits in the directory with the main solution
file, that VS forgot the offset into the original Form1.cs file where the
event handler was (before I did that, double-clicking on the event took me
to where the handler used to be).

So I suspect that the cache file is the correct magic file, but how to get
it to point to the right location, I don't know. It may be that deleting
all the event handlers and hooking them back up is the only way. :(

On top of all that, I found that when I added a new "Code File" where I
moved the event handler to, double-clicking the code file in the Solution
Explorer took me to a bogus form designer window. I say "bogus", because
it wasn't even my actual form...it was missing all the controls. And as
if that weren't bad enough, when I double-clicked on the form, it added a
new Load event handler in my new CodeFile1.cs file, _and created a whole
new "InitializeComponent()" method_! Duh.

It seems to me that VS has some serious bugs in dealing with the designer
versus "partial". Given that it does somehow manage to avoid getting
confused between Form1.cs and Form1.Designer.cs, I suspect they've
hard-coded some special cases or something, but the more general situation
trips it up. Boo!

Pete
May 19 '07 #5

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

Similar topics

12
by: swingingming | last post by:
Hi, in the NorthWind sample database, when clicking on the next navigation button on the new order record with nothing on the subform (order details), we got an order with nothing ordered. How can...
4
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from...
3
by: Michael Evanchik | last post by:
Im not getting any error messages but the event is not going off when i click the button it just posts back to the same page. I know this code has worked outside of Calanders with the same code. ...
5
by: karthick raja | last post by:
Am experiencing a problem intercepting the events from controls added dynamically to a Placeholder control at runtime. Is there any way that I can write an event handler on the page which will be...
4
by: Woody Splawn | last post by:
I have a grid with, lets say, 3 fields in it, Debit, Credit and Comments, in that order. When the user moves to the debit field, if he enters data in it, I would like for the cursor to skip past...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
4
by: Tom & Carol Satran | last post by:
Hi I am new to this group and to access. I am trying to make a database for a NFP Youth Organization. We have mutiple home teams, visiting teams, and sites. I have the following in a before...
2
by: TS | last post by:
when i try to do a response.flush and .end, the screen ends up blank. I want all page processing to quit when a check in the pageload event fails. Since control events occur after load, how do i...
0
by: Peter Anthony | last post by:
It seems kind of strange that if a Form is just moved that Resize events fire. This makes it hard to tell the difference betweeen resizing and moving a Form. I can understand why resizing might...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.