在dll库中显示消息框 [英] Display messagebox in dll library

查看:127
本文介绍了在dll库中显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个dll库(例如用于检查用户的登录详细信息),我想在此过程中弹出确认对话框或信息对话框,例如


$ b $您确定要继续吗?(是/否/取消)



一些原因。目前我需要Winforms中的一个应用程序,而且我也想使用同样的dll为我的其他webforms应用程序。任何人都可以指导如何实现吗?不用说我不想引用 System.Windows.Forms System.Web 。任何人可以给我一些指针吗?我正在使用.net 4.0



我不想出版/订阅活动,因为我对cab架构不太熟悉。



编辑



我有一个dll用于在应用程序的运行时创建数据库。所以我的dll通常会检查数据库是否已经存在,并且是否已经更新,如果它是停止的。但是如果它不存在或不是最新的,那么我想询问用户是否要现在或之后进行更新。如果用户现在说,更新它,然后说继续应用。



谢谢。

解决方案

你真的不应该。这不属于图书馆,但应该在使用此库的应用程序中完成。



WinForms应用程序可能通过显示一个 MessageBox ,一个Web应用程序可能会执行请求,而不要求POST成功(因为POST通常显示修改资源的意图)。



例如,当您的库用于登录时,只需抛出一个 AuthenticationException ,因此客户端应用程序(无论是WinForms,Web还是其他)可以捕获和显示相应的消息。






至于您的编辑:


我有一个dll在应用程序的运行时创建数据库...


为什么不暴露两种方法,如 IsDatabaseUpToDate() UpdateDatabase()?然后在客户端,你可以调用第一个方法。如果它返回false,您是否要求用户(无论是使用MessageBox,HTML表单,JavaScript Alert,简单的Yes按钮或闪烁的图块)是否要更新数据库。如果是这样,你可以调用 UpdateDatabase()方法,你准备好了。


I am writing a dll library (for example for checking login details of a user) and I want to pop up a confirmation dialog or a informational dialog in the process, for example

"Are you sure you want to continue? (Yes/No/Cancel)"

for some reason. At present I am need this for an application in Winforms and I want to use same dll for my other webforms applications also. Can anyone guide how to achieve it? Need less to say I don't want to reference System.Windows.Forms or System.Web. Can any one give me some pointers? I am using .net 4.0

I don't want to for Publication/Subscription of events as I am not very familiar with cab architecture.

EDIT

I have a dll for creating database at runtime of an application. So my dll generally checks if the database already exists and is upto date or not, if it is then stop. But if it does not exist or not upto date, then I want to ask user if he want to update it now or afterwards. If user says now, update it and says afterwards continue to application. It is just an example and any relevant information on this is welcome.

Thanks.

解决方案

You really shouldn't. This does not belong in a library, but should be done in the application that uses this library instead.

Where a WinForms application might solve it by showing a MessageBox, a web application might perform the request without asking after a successful POST (since a POST usually shows the intent to modify a resource).

When for example your library is used for logging in, simply throw a AuthenticationException, so the client application (whether it's WinForms, web, or whatever) can catch that and display the appropriate message.


As for your edit:

I have a dll for creating database at runtime of an application ...

Why not expose two methods like IsDatabaseUpToDate() and UpdateDatabase()? Then in the client, you can call the first method. If it returns false, you ask the user (be it with a MessageBox, an HTML form, a JavaScript Alert, a simple Yes button or a blinking tile) whether they want to update the database. If so, you call the UpdateDatabase() method and you're ready to go.

这篇关于在dll库中显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆