私はあなたが正しい、あなたが別のクラスとしてテキストボックスとボタンがあるcostumフォームを作成する必要がありました場合は、その後、あなたは)そのクラスのインスタンスを作成し、.showDialogを(呼び出す必要がありますメソッドを呼び出すと、ユーザーは(MessageBoxのように)ダイアログに何かを入力することしかできません。その後、あなたのクラスから入力されたパスワードを取得し、パスワードが正しいかどうかを尋ねる必要があります(私はあなたが単に "簡単な"保護と暗号化されていない保護を望むと仮定します)。 私の頭に浮かんだ最も簡単な解決策は、あなたのパスワードを他のクラスに渡して、あなたのパスワードが正しいかどうかをチェックし、ただ喚起する必要があるDialogResultを返すことです。 (あなたの方法button_6_Click_1ための())は、このような Somethig:
const string password = "123456789"; //just an example password
string url = textBox1.Text;
// Get if the user entered the right password
GetPass pass = new GetPass(password);
// Check this with a dialog result
DialogResult result = pass.ShowDialog();
if (result == DialogResult.OK)
{
BlockList.Add(url);
MessageBox.Show("Added " + url + " to blocklist.");
textBox1.Clear();
}
これは、他のWinForm・クラスのコードのようになります。
public partial class GetPass : Form
{
// Use a texBox called textBox1 and a button called btn_confirm
private string refPassword;
public GetPass(string password)
{
InitializeComponent();
refPassword = password;
}
private void btn_confirm_Click(object sender, EventArgs e)
{
string password = textBox1.Text;
if (password.CompareTo(refPassword) == 0)
{
this.DialogResult = DialogResult.OK;
}
}
}
私はあなたがこれを拡大する作業を行うようになります。
@Sharabeel 2つのパスワードが直接一致するかどうかを確認したくない場合は、ハッシュ(例としてmd5)は一致しますが、それはより高度なトピックです。 – 97hilfel