|
-
Oct 20th, 2003, 09:48 AM
#1
Thread Starter
Lively Member
How to display a message
Hi All,
Here is my problem :
I use C#.net to write a class library project. In the class, i need to display some message on the screen, say, some warning or error message. However, in a class library, there is no System.Windows namespace. So how can i do that ? i'd like to have such func like messagebox, i.e, not only display message but also allow user to make choice, in a class library project, is that possible ?
Thanks in advance
-
Oct 20th, 2003, 10:10 AM
#2
Frenzied Member
post your code...my assumption would be you would return a string from your library and then that string would be displayed in a messagebox from your application.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 20th, 2003, 10:46 AM
#3
Thread Starter
Lively Member
Thank you for your reply, Memnoch1207
As an simplified example, the code logic is like following:
if ( ErrorFlag ) {
x = Messagebox (" Ignore the Error ? ", YesNo) ; // This is part i want
if ( x== NO )
return ;
}
So, i really need to display and deal with the message inside of the class, can't return it to application and let the application to deal with it. Any suggestion ?
-
Oct 20th, 2003, 12:39 PM
#4
If you really want to use a messagebox, simply add a reference to the Windows.Forms assembly. <opinion>However, I think the correct way to go about this would be to throw an error so that the application programmer can decided what course to take -- to silently continue, ask the user, or abort.</opinion>
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Oct 22nd, 2003, 04:30 PM
#5
sunburnt is right. It is poor design if a class library does any user interaction that the library user didn't explicitly ask for. Log whatever ignorable messages/warnings you have in some kind of log file and let the real errors throw exceptions.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 23rd, 2003, 12:42 PM
#6
Thread Starter
Lively Member
Yes, i agree with you guys in general speaking. However, in my case, it is not good enough for the func to throw an exceptions. It has to finish the work based on the user's selection when error occurs. I know i can break the func into multi-funcs. But i really want to keep it into one piece, easy to use and maintain...
Anyway, the way i am doing now is to define a form and use the form in the class.
-
Oct 23rd, 2003, 12:54 PM
#7
PowerPoster
I still disagree with displaying messages in your component. Why not create an enum and pass this up the chain.
-
Oct 23rd, 2003, 02:29 PM
#8
Or an error delegate. When the error occurs, the delegate gets called. It must be set to a app-supplied function, which can then ask the user for input or decide somehow else what to do, or it can cancel the process completly.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|