Adding Textbox and MessageBox to a class library
I'm trying to create a DLL for an existing project. The existing project is an application that calculates interest rates and is a Windows Form.
The code I've been given to create the DLL includes references to a TextBox and a MessageBox.
Here's a sample method in that code:
public static bool IsPresent(TextBox textBox)
{
if (textBox.Text == "")
{
MessageBox.Show(textBo开发者_运维问答x.Tag + " is a required field.", Title);
textBox.Focus();
return false;
}
return true;
}
I've never created a class library/dll before, so I followed the instructions here.
When I build the solution (for the class library), I get the error:
Error 1 The type or namespace name 'TextBox' could not be found (are you missing a using directive or an assembly reference?) J:\LoanApplication\ValidatorSolution\ValidatorSolution\Class1.cs 24 38 ValidatorSolution
And I get it; I understand what the error is saying. My problem is that I don't know how to get around it.
Any advice?
You need to reference System.Windows.Forms(use this guide) and include a using statement
using System.Windows.Forms;
For each external type you're using in your library, you need to help VS determine where it is and which one you mean.
in your project , right click on "References", then click on "Add References" . Now, in References manager window, just choose
System.Windows.Forms
click ok button and come back to your code page.
as usual you can now add System.Windows.Forms by using keyword:
using System.Windows.Forms;
Read the whole error message and then add a reference to System.Windows.Forms
to your project and add using System.Windows.Forms;
to the beginning of your source code.
精彩评论