このクラス Validators があり、WinForms プロジェクトのすべてのテキスト ボックスを検証します。方法がわからないのは、「検証に失敗したテキストボックスのボーダーカラーを変更できません」です。そこでLoginForm_Paint
、同じクラス「バリデーター」でこのイベントを使用しました。使い方がわからない、そもそもあってはならないのかもしれない、使い方がわからないのかもしれない。誰か助けてくれませんか?
public void LoginForm_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Pen redPen = new Pen(Color.Red);
}
public bool ValidateTextBoxes(params TextBox[] textBoxes)
{
foreach (var textBox in textBoxes)
{
if (textBox.Text.Equals(""))
{
textBox.BackColor = Color.Red;
return false;
}
}
return true;
}
私はこのように使いたかった(LoginFormのように):
public void LoginForm_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Pen redPen = new Pen(Color.Red);
}
public bool ValidateTextBoxes(params TextBox[] textBoxes)
{
foreach (var textBox in textBoxes)
{
if (textBox.Text.Equals(""))
{
graphics.DrawRectangle(redPen, textBox.Location.X,
textBox.Location.Y, textBox.Width, textBox.Height);
return false;
}
}
return true;
}
しかし、そうはいきません。作成したインスタンスを認識しませんGraphics graphics = e.Graphics;
。