|
if (TextBox.Text == null)
{
}
if (TextBox.Text != null)
{
}
Wouldn't an if/else be more appropriate? Control validators eliminate this kind of clutter.
_Madmatt wrote: Maybe you can create your whole "Form2" by codig
And how does this solve the issue?
_Madmatt wrote: That will be much easier
Really? How so?
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: Really? How so?
Like I described
If Form1 creates Form2, Form1 can access Form2 and take inf out of it...
|
|
|
|
|
_Madmatt wrote: Maybe you can create your whole "Form2" by codig? That will be much easier
How is "create your whole "Form2" by coding" easier?
only two letters away from being an asset
|
|
|
|
|
Are you going to tell me you don't know how to make a control in the codebehind?
|
|
|
|
|
As you are having difficulties understanding, I'll try to make this very clear, again.
You stated it was easier to create the form in code.
My question, once again, is to have you explain why you think this is easier?
_Madmatt wrote: Are you going to tell me you don't know how to make a control in the codebehind?
Take a better look around before making statements like this.
only two letters away from being an asset
|
|
|
|
|
I am guessing this recent interchange of messages must be part of another thread.
But since you've responded in this one. I still have an issue that I cannot for the life of me figure out. Your input has been helpful but I cannot get around the problem of the code in Form2 checking for empty textboxes twice and then falling through to the rest of the code in Form1. I run Debug and cannot find the cause. A similar If/Else in Form1 returns to Form1 focused on field 1 if the conditions find that a required field is empty. It continues to do this until I fill all the required fields or hit Exit.
Similar code in Form2 only checks twice, finds/reports the correct empty textboxes and then drops down back to Form1 regardless whether the textboxes are empty or not. The returns in Form2 do not seem to affect anything. Here's some of the code:
Form1.cs
--------
{
MessageBox.Show("The Last Name and First Name are required!!");
return;
}
GetForm2();
...
...
public void GetForm2()
{
Form2 qForm = new Form2();
qForm.ShowDialog();
if (qForm.ShowDialog()== DialogResult.OK)
{
CaseNo = qForm.CaseNo;
Reason = qForm.Reason;
MessageBox.Show("Form2 Exists" + " " + CaseNo + " " + Reason);
}
qForm.Dispose();
}
Form2.cs
--------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DMV_Test_1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public string CaseNo
{
get { return textBox1.Text; }
}
public string Reason
{
get { return textBox2.Text; }
}
private void button1_Click(object sender, System.EventArgs e)
{
if (CaseNo == "")
{
MessageBox.Show("The Case No is required!!");
this.textBox1.Focus();
return;
}
else
if (Reason == "")
{
MessageBox.Show("The Reason is required!!");
this.textBox2.Focus();
return;
}
else
{
this.DialogResult = DialogResult.OK; Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel; Close();
}
}
}
Seems so simple (has been so far) but this just really frustrates me. Any ideas, gotchas, tips, etc. will be much appreciated. BTW, I did this in Visual Studio 2005 IDE with very little code from me to design and set up the forms. Great tool.
Thanx again
modified on Tuesday, October 27, 2009 6:14 PM
|
|
|
|
|
The application is behaving exactly as planned. You are calling ShowDialog twice.
public void GetForm2()
{
Form2 qForm = new Form2();
qForm.ShowDialog(); <---- Form2 opened. Not needed
if (qForm.ShowDialog()== DialogResult.OK) <------ Form 2 opened again
{
CaseNo = qForm.CaseNo;
Reason = qForm.Reason;
MessageBox.Show("Form2 Exists" + " " + CaseNo + " " + Reason);
}
qForm.Dispose(); <----- Not needed
}
only two letters away from being an asset
|
|
|
|
|
Thank you ... that handled Form2 popping up twice and I learned something. I thought the first one opened the form and the second was just a check.
However, the check for an empty textbox now just drops through even if a textbox is empty and the message appears. Am I missing something on how Form2 is processed versus how Form1 is processed? Maybe which form is the primary form? I would expect for the process to stay within the if/else until the textboxes are no longer empty. That is what similar code in Form1 does.
Almost there.
Thanx again
|
|
|
|
|
I would suggest you maybe email me what you have. That way I can take a look at the whole problem and maybe be better able to help you at this point.
only two letters away from being an asset
|
|
|
|
|
GOT IT!!!!! Thank you all for your input. The trick is to set the DialogResult to None in properties.
Also, I sure hope you all work out this smal argument.
|
|
|
|
|
Excellent.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: As you are having difficulties understanding, I'll try to make this very clear, again.
I'm so sorry, my English isn't that good.
If Form1 creates Form2, Form2 can check its own textboxes. When those boxes are empty, you just display a message. If the textboxes are valid, Form2 closes itself and Form1 can still acces the textbox.Text properties. You may not Dispose Form2 for that
I'm not yet studying c# so you may conclude I'm beginner
|
|
|
|
|
Thanx _Madmatt, your English is good, no problem. I understand what you are saying but am confused on the HOW. I am also new to C# and am getting used to the gotchas. I am sure the problem is with how the Dialogresult is handled, just not clear on how I need to handle it.
Thanx again for your suggestions.
|
|
|
|
|
You're welcome!
Maybe you can show your Form2 just in a form and not in a Dialog. Then you just check if your textboxes are empty like this:
if (txt1.Text == null)<br />
{<br />
}<br />
<br />
else if(txt1.Text != null)<br />
{<br />
}
|
|
|
|
|
_Madmatt wrote: I'm so sorry, my English isn't that good.
I don't buy this excuse
You still have not answered the question, why is doing it in code better? But no matter, not worth continuing based on below.
_Madmatt wrote: I'm not yet studying c#
Then you absolutely should not have answered in the first place
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: Then you absolutely should not have answered in the first place
You don't give beginners a chance? Ow that's pretty nice...
|
|
|
|
|
Beginners, yes. However, by your own admission you do not even know the language. You can't comment on things you don't know!!
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: you do not even know the language.
I know the language. I've read a book. But I'm still at secundary school, so I've not studied c# yet at high school. I surely know the language, otherwise it would be stupid to wate my time on it...
|
|
|
|
|
|
Very simple... Both, I know c# but I'm not yet studying it at school. Or is that too difficult for you to umderstand?
|
|
|
|
|
I'm still waiting for your explanation.
only two letters away from being an asset
|
|
|
|
|
I'm not online all day long
|
|
|
|
|
Surely you could have just answered his question instead of writing "I'm not online all day long"?
I wouldn't argue further, your logic isn't correct, and you might want to reread those books of yours.
|
|
|
|
|
I don't know if you can read, but I've already answered... Read the whole topic before you say stupid things like that.
EDIT: What I said was just a suggestion about how he COULD do it. I've ABSOLUTELY NOT said "this is the best solution". It's the solution how I should do it with my skills and my understoodings about his issues. But if there are better solutions, no problem for me! I have still to learn, but it's not needed to slap me down. Everybody here has ever started with something where there were better solutions for? Or was you a pro from the first day on?
Last but not least a quote from the rules: "Let's work to help developers, not make them feel stupid.."
modified on Thursday, October 29, 2009 1:15 PM
|
|
|
|
|
Funny, I don't see that in the rules[^].
Plus, I'm not the one who looks stupid here.
And you did say it was the easiest method, and you where asked how and ignored it. If anything, you proved your own stupidity, not mine.
|
|
|
|