C
C#2y ago
cgxlm

❔ Error Provider Windows Forms

im not sure how to get the error providers working
6 Replies
cgxlm
cgxlm2y ago
if (!passwordReg.IsMatch(password))
{
errorPassword.SetError(txtPassword, "");
errorPassword.Icon = Properties.Resources.CorrectIcon;
}
else
{
errorPassword.SetError(txtPassword, "Password is incorrect");
errorPassword.Icon = Properties.Resources.ErrorIcon;
}
if (!passwordReg.IsMatch(password))
{
errorPassword.SetError(txtPassword, "");
errorPassword.Icon = Properties.Resources.CorrectIcon;
}
else
{
errorPassword.SetError(txtPassword, "Password is incorrect");
errorPassword.Icon = Properties.Resources.ErrorIcon;
}
thats the code i have for it
TheBoxyBear
TheBoxyBear2y ago
What's the problem?
notlyze
notlyze2y ago
@cgxlm Your code looks mostly correct, but you need to set the error message to an empty string when the password is correct.
errorPassword.SetError(txtPassword, "Password is incorrect");
errorPassword.SetError(txtPassword, "Password is incorrect");
Wait U allready do Could you give more details about the issue you're experiencing?
cgxlm
cgxlm2y ago
when running the code, no matter if i put the details wrong or right just absolutely nothing happens
Pobiega
Pobiega2y ago
In what event are you running this code? Did you associate the provider with the control?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeErrorProviders();
}

private void InitializeErrorProviders()
{
numberErrorProvider.SetIconAlignment(numericUpDown1, ErrorIconAlignment.MiddleRight);
numberErrorProvider.SetIconPadding(numericUpDown1, 2);
}

private void numericUpDown1_Validated(object sender, EventArgs e)
{
if (numericUpDown1.Value < 10)
{
numberErrorProvider.SetError(numericUpDown1, "Too low.");
}
else if (numericUpDown1.Value >= 20)
{
numberErrorProvider.SetError(numericUpDown1, "Too high.");
}
else
{
numberErrorProvider.SetError(numericUpDown1, string.Empty);
}
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeErrorProviders();
}

private void InitializeErrorProviders()
{
numberErrorProvider.SetIconAlignment(numericUpDown1, ErrorIconAlignment.MiddleRight);
numberErrorProvider.SetIconPadding(numericUpDown1, 2);
}

private void numericUpDown1_Validated(object sender, EventArgs e)
{
if (numericUpDown1.Value < 10)
{
numberErrorProvider.SetError(numericUpDown1, "Too low.");
}
else if (numericUpDown1.Value >= 20)
{
numberErrorProvider.SetError(numericUpDown1, "Too high.");
}
else
{
numberErrorProvider.SetError(numericUpDown1, string.Empty);
}
}
}
I just made this as a sample and it works fine, winforms .NET 7 I first tried putting the SetIcon... code in InitializeComponent but it got overwritten, so I don't recommend that 😛
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ HttpResponse CacheHeadersI have two questions. Why is this list only returning one item? Also, the server gives me `public ma❔ Need helpHello, Is there any suggestion for a beginner's guide pdf or channel or something to learn I am a ❔ Modern web api frameworks in dotnetIs aspnet the only option for building web apis in modern dotnet? I've tried doing a bunch of search❔ publish blazor wasm app as docker image with nginx baseI create a dockerfile, and create a docker publish configuration, but it tells me that I need to ena❔ ✅ ✅ Why does $singlefile make the .exe file so largeHey I didnt want loads of files so I used $singlefile method and now the exe is 64 megabytes for jus❔ System.IndexOutOfRangeException has been thrown"Index was outside the bounds of the array."Hi I get this message at the line " Tile temp = Tiles[x, y]; " in my SwapTiles method when im trying❔ c# basicsCan anyone help for the test. it falls on Feb 18 and 19. theory and practice is the test, 6-7 tasks ❔ In blazor server,in which Method should you usually implement JWT assignationI have been wondering since I have used scaffolding por identity to receive the JWT token in J's but❔ How does the execution pipeline works with interfaces that implement methods?Lets say we have the icommand interfact, it has to methods : canExcute and Excute, When i bind said❔ WEBAPI [FromBody] Json with optional elementsI am building a .net Wep API application where I will be receiving requests where all of the data is