Results 1 to 8 of 8

Thread: How to display a message

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115

    Smile 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

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115
    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 ?

  4. #4
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    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.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    115
    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.

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I still disagree with displaying messages in your component. Why not create an enum and pass this up the chain.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width