473,480 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help-document view architecture in c#

Is this a good idea? From a brief dabble with MFC years ago, I
understand that this is a worthy goal.
Therefore I'm trying to remove most of the guts of an app from the main
form code to another class. This class starts the program with
Application.Run(new frmMain()) within its static void Main() method.

However, ..... how can I get frmMain to update the data held within
this data class? Pass events back to it? Contain a refernce to the
class and access its properties? I'd like to be able to send frmMain a
reference to the class when I isntantiate it within Application.Run(new
frmMain()) but becuase void main is declared statically, this isn't an
option.

Feeling a little lost now...!

Nov 29 '05 #1
6 2743
Greg,

Why isn't it an option? To me, it would seem like you just create a
constructor for your form which would take an instance of the data class.
You can create an instance of the data class before you call
Application.Run, and then do this:

Application.Run(new frmMain(dataClass));

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg" <gr*************@yahoo.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Is this a good idea? From a brief dabble with MFC years ago, I
understand that this is a worthy goal.
Therefore I'm trying to remove most of the guts of an app from the main
form code to another class. This class starts the program with
Application.Run(new frmMain()) within its static void Main() method.

However, ..... how can I get frmMain to update the data held within
this data class? Pass events back to it? Contain a refernce to the
class and access its properties? I'd like to be able to send frmMain a
reference to the class when I isntantiate it within Application.Run(new
frmMain()) but becuase void main is declared statically, this isn't an
option.

Feeling a little lost now...!

Nov 29 '05 #2
Thanks Nicolas
I'm pretty chuffed that you think it is an option - at least I'm not
barking up the wrong tree.

The problem is that I cant get the class ("clsApplicationData") to send
an instance of itself. the this keyword doesn't work since void main()
is static.

Nov 29 '05 #3
Greg,

Um, so why not just create it, like so?

// Create the instance of the application data:
clsApplicationData appData = new clsApplicationData();

// Run the program.
Application.Run(new frmMain(appData));

Of course, this doesn't help if you want to have a universal instance.
In which case, you should expose a singleton of the app data, and then you
could do this:

// Get the singleton instance.
clsApplicationData appData = new clsApplicationData.Instance;

// Run the program.
Application.Run(new frmMain(appData));

Or, you could just access the instance directly in your form.

I don't see what the problem is.

Also, you might want to re-consider your naming of the classes/forms.
The suggested public naming conventions indicate you should not prefix class
names with an indicator of the type (cls, frm).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg" <gr*************@yahoo.co.uk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanks Nicolas
I'm pretty chuffed that you think it is an option - at least I'm not
barking up the wrong tree.

The problem is that I cant get the class ("clsApplicationData") to send
an instance of itself. the this keyword doesn't work since void main()
is static.

Nov 29 '05 #4
Thanks Nick.
Thanks also for the advice on naming conventions - I've just migrated
from VB so I haven't found my feet yet. For the purpose of this thread
though, I'll stick with what I've already used, to save confusion.

The issue is that it is an instance of clsApplicationData that
kickstarts the program. Therefore for your suggestion to work, this
would need to create a new instance of itself. That doesn't make sense,
does it? Maybe my form class should start the application and create an
instance of clsApplicationData. That would definitely solve the
problem, though it doesn't seem best practice to me - surely
clsAppplicationData should be running the whole show, not being created
by a class that is GUI related.

Nov 29 '05 #5
Greg,

If you have a Main method on clsAppplicationData, then in that Main
method, no instance is created.

I prefer the approach taken by the template for the windows forms
application in VS.NET 2005. Basically, there is a class in your project,
"Program" which has the entry point "Main", which creates the instance of
your form class (which is separate) and then calls the static Run method on
the Application class, passing the instance. It allows you easily place
whatever other code you need for startup somewhere that is separate from
your UI code (or any other code, for that matter).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg" <gr*************@yahoo.co.uk> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Thanks Nick.
Thanks also for the advice on naming conventions - I've just migrated
from VB so I haven't found my feet yet. For the purpose of this thread
though, I'll stick with what I've already used, to save confusion.

The issue is that it is an instance of clsApplicationData that
kickstarts the program. Therefore for your suggestion to work, this
would need to create a new instance of itself. That doesn't make sense,
does it? Maybe my form class should start the application and create an
instance of clsApplicationData. That would definitely solve the
problem, though it doesn't seem best practice to me - surely
clsAppplicationData should be running the whole show, not being created
by a class that is GUI related.

Nov 29 '05 #6
Excellent. That appears to have worked.
within the Program class:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

static void Main()
{
Application.Run(new frmMain(new clsApplicationData()));
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I'll see how it behaves tomorrow, but from the logic it would appear
that frmMain will know all about clsApplicationData, which is what I've
been striving for!

Thanks a lot Nicholas, I really appreciate your help.

Greg.

Nov 29 '05 #7

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

Similar topics

21
6480
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
4368
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
3315
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
4297
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
3311
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
5336
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
3242
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
3198
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
3322
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
6105
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
7044
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
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7087
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...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.