|
|
Downvote countered.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
Downvote also countered.
/ravi
|
|
|
|
|
A code dump does not a question make.
There is no question asked, so we have no idea what problem you are having, or what kind of help you are seeking.
Please, try to think about how you present the problem from the POV of the reader: Remember that we can't see your screen, access your HDD, or read your mind.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Could it be that you made your properties read-only and are then attempting to assign them a value?
|
|
|
|
|
I really don't care if you downvote me or not. Just keep this in mind. The quality of the answer you get is directly determined by the quality of the question you ask.
You didn't really ask a question. You just dumped your code and hoped someone would rewrite it so it would work. You didn't do any research on your problem at all. That's what I provided you. If that wasn't good enough for you, piss off. You'll be out of a job within 6 months.
|
|
|
|
|
@Davee Kreskowiak
Sorry Sir , I am just a beginner. I tried a lot to debug but was not getting where my code is getting wrong so that's why i posted my whole of the code . And my code wasn't uploaded fully.
I am sorry if my skill of asking question is not upto match.I am jsut trying to get upto.
|
|
|
|
|
You didn't even try to ask a question!
Would you pass your shopping bag to the checkout person at the supermarket and expect her to fill it with exactly what you wanted to buy?
Of course you wouldn't! At the very least, you'd give him or her a shopping list so they had an idea what you wanted, and could ask "how much cheese?" And "which coffee brand?"
So why post your code and tell us nothing about what it should do, what it does do, and what you have done to try and work out why or fix it?
Instead of thinking about what we might need to help you, you took the lazy way and dumped cr@p on us and walked away in the hope that we'd do it for you. And when we didn't do exactly what you wanted, you decided to be rude and down vote someone. This isn't a behaviour model that is likely to get you anywhere in the real world, so why would you think it would work here in the virtual one?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sorry Sir , I am just a beginner. I tried a lot to debug but was not getting where my code is getting wrong so that's why i posted my whole of the code . And my code wasn't uploaded fully.
I am sorry if my skill of asking question is not upto match.I am jsut trying to get upto.
|
|
|
|
|
Hi All,
How to install system input language programatically in c#
|
|
|
|
|
|
Hey, so I have an issue with my array/code. I want the code to write out YES if the string exists within my array, and write out NO if it doesn't. Problem is that it writes out YES all the time, even if the string does not exist. What am I doing wrong?
string[] kos = new string[] { "test1", "test2", "test3" };
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i <= kos.Count() - 1; i++)
{
if (textBox2.Text == kos[i])
{
kosCheckLabel.Text = "YES.";
kosCheckLabel.ForeColor = System.Drawing.Color.Red;
}
else if(textBox2.Text != kos[i])
{
kosCheckLabel.Text = "NO.";
kosCheckLabel.ForeColor = System.Drawing.Color.Lime;
}
}
}
modified 14-Feb-15 8:14am.
|
|
|
|
|
It looks to me like it should usually give "NO", unless the last item matches, but it's the weekend so I'm not having coffee.
The problem there is that you change it to "NO" all the time, instead of only when you've found out there are no matches. If one item doesn't match, that is in general not proof that none will.
By the way, i <= kos.Count() - 1 is more commonly written as i < kos.Length
So how about this:
kosCheckLabel.Text = "NO.";
kosCheckLabel.ForeColor = System.Drawing.Color.Lime;
for (int i = 0; i < kos.Length; i++)
{
if (kos[i] == textBox2.Text)
{
kosCheckLabel.Text = "YES.";
kosCheckLabel.ForeColor = System.Drawing.Color.Red;
break;
}
}
|
|
|
|
|
The first thing to note is that it's a loop - which means the code inside it is executed every time the value of "i" is incremented: so for your example, the code within the loop is executed 3 times: for i == 0, i == 1, and i == 2.
And because your two if conditions are opposite:
if (textBox2.Text == kos[i])
...
if(textBox2.Text != kos[i]) It will always print one string or the other.
In fact, because they are opposite, you don't need to test again at all: the else code will be executed if the first if fails, so your code is the equivalent of
for (int i = 0; i <= kos.Count() - 1; i++)
{
if (textBox2.Text == kos[i])
{
kosCheckLabel.Text = "YES.";
kosCheckLabel.ForeColor = System.Drawing.Color.Red;
}
else
{
kosCheckLabel.Text = "NO.";
kosCheckLabel.ForeColor = System.Drawing.Color.Lime;
}
}
If you want to just print once - "Yes" if it is there, or "No" if it isn't, the normal way is to use a bool value to "store" the current result:
bool isThere = false;
for (int i = 0; i <= kos.Count() - 1; i++)
{
if (textBox2.Text == kos[i])
{
isThere = true;
break;
}
}
if (isThere)
{
kosCheckLabel.Text = "YES.";
kosCheckLabel.ForeColor = System.Drawing.Color.Red;
}
else
{
kosCheckLabel.Text = "NO.";
kosCheckLabel.ForeColor = System.Drawing.Color.Lime;
}
But the simplest way to do it is to use a Linq method:
string[] kos = new string[] { "test1", "test2", "test3" };
private void button2_Click(object sender, EventArgs e)
{
if (kos.Contains(textBox2.Text)
{
kosCheckLabel.Text = "YES.";
kosCheckLabel.ForeColor = System.Drawing.Color.Red;
}
else
{
kosCheckLabel.Text = "NO.";
kosCheckLabel.ForeColor = System.Drawing.Color.Lime;
}
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you both very much for the answers and effort in assisting me!
The output is still the same though, which I cannot understand why.
|
|
|
|
|
Are you sure?
I just tried my Linq solution:
private void button1_Click(object sender, EventArgs e)
{
string[] kos = new string[] { "test1", "test2", "test3" };
if (kos.Contains(textBox2.Text))
{
kosCheckLabel.Text = "YES.";
kosCheckLabel.ForeColor = System.Drawing.Color.Red;
}
else
{
kosCheckLabel.Text = "NO.";
kosCheckLabel.ForeColor = System.Drawing.Color.Lime;
}
}
And I get "YES" for "test1", "test2", and "test3" and "NO" for everything else.
Are you sure there are no spaces, capital letters, etc. which might be confusing it?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Oh wow, I feel so stupid.
Turns out I had the wrong TextBox written out.
Pardon me for my newbie miss.
The code works now.
Thanks a ton!
|
|
|
|
|
I have days like that as well!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It's nice that you found it. Let this be a lesson to you. ALWAYS give your controls nice names that mean something. Don't ever use the default names, like "TextBox1".
|
|
|
|
|
Can we implement CSS on a Window Form if yes how?
|
|
|
|
|
|
Hi all.
Interested in such a thing:
Is it possible to do block allocation (as in the pictures) in WinForms RichTextBox?
If you can, then about how this is done?
p.s. know what is being done through OnPaint, Graphics.. but how exactly is the drawing of a border on the sides?
Example
|
|
|
|
|
lMr Cirwosl wrote: but how exactly is the drawing of a border on the sides? If you want to know how it is done "exactly", then you'll need the source-code of the app you are showing.
And no, that's not a simple RichEditControl with some code that you can copy/paste. Google for the name in the caption, and you'll see that it is a commercial control.
lMr Cirwosl wrote: but how exactly is the drawing of a border on the sides? Drawing a border is not hard. Rechecking on each keypress if you need to repaint isn't hard either. Having it in an edit-control that performs nicely is hard.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What this picture shows, I wanted to show others what I had in mind under the block allocation, and not how this control was done, and the standard whether it is or not.
And about the method itself.
And what's the keystroke?
As if the text selection is done by gripping and moving the mouse, not the keyboard keys (except for Ctrl+A)
|
|
|
|