Use MessageBox in the class library

Source: Internet
Author: User


Error:

Data room Charging System (VB. during the process, there is an exception capture processing in the sqlhelper class of the D Layer. if an exception is caught, you want to use MessageBox. the show () exception description is displayed, but "MessageBox not declared" is displayed during compilation ". It may be inaccessible due to its protection level ." Error:

View help. msdn explains that a statement references a programming element, but the compiler cannot find the element with the exact name.


Judgment:

The compiler cannot identify the problem, but MessageBox can be used in the form application, and MessageBox. show () is. net, so it may be because the project of the form application implicitly references a function library that contains MessageBox. show () assembly, and the class library project does not reference this assembly.

Solution:

According to the judgment, I checked the reference of the UI Layer and found that there were a lot more references than the reference of the D Layer. After trying, I got the conclusion: If the reference is in the D Layer (only representative of the Class Library Project) to use the MessageBox () method, you must reference the namespace system. windows. forms. The specific operation is as follows (I use visualstudio2013, and other versions should not be significantly different ):


1,Right-clickProject to reference system. Windows. Forms → add → reference




2. Select the "Framework" under the Assembly and check system. Windows. forms to confirm.



3. Reference System. Windows. Forms in the file header of the class:

Imports system. Windows. Forms


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.