|
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)
|
|
|
|
|
lMr Cirwosl wrote: As if the text selection is done by gripping and moving the mouse The picture doesn't show a block-selection. And yes, you can do that with the mouse, the RichTextBox supports that. It does not support block-selections out of the box.
Click before the word "if", hold and drag upto the end of the selection. The keycombination to do so would be to hold down shift while using arrow/ctrl keys to make the selection.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
That is syntax highlighting in a code editor. It is done by rendering the text, measuring the text on the screen and drawing round it. This is usually done in a control you develop yourself, and by overriding the OnPaint method. However, it is worth doing a Google search first to see if there are any source code samples around.
|
|
|
|
|
Moreover, there is syntax highlighting? I'm talking about the style of highlight lines in the RichTextBox, but not about syntax highlighting. The example I show the picture in the middle of the selected row, that's the style for me.
|
|
|
|
|
|
Hello,
I am not an expert in C# but this site helped a lot creating a mini application that launches IE9, modifies some registry keys and bingo. Now, I have to add a few modifications but launch IE11.
This is the code:
RegistryKey key00 = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, "");
RegistryKey subkeyAA = key00.OpenSubKey("Software\\Microsoft\\Internet Explorer\\BrowserEmulation\\ClearableListData", true);
string[] namesAA = subkeyAA.GetValueNames();
string YesUserFilter = "";
string NoUserFilter = "";
foreach (string name in namesAA)
{
if (name.Equals("UserFilter", StringComparison.CurrentCulture))
{
YesUserFilter = "1";
break;
}
else
{
NoUserFilter = "1";
}
}
if (YesUserFilter == "1")
{
int myValue = (int)subkeyAA.GetValue("UserFilter");
if (myValue != 0)
{
subkeyAA.SetValue("UserFilter", "company.com", RegistryValueKind.Binary);
}
}
if (NoUserFilter == "1")
{
subkeyAA.SetValue("UserFilter", "company.com", RegistryValueKind.Binary);
}
subkeyAA.Close();
But the conditionals of YesUserFilter or NoUserFilter are blank, Thoughts ? Thanks for your help.
|
|
|
|
|
Hi,
The first thing I would look at is the MissingManifestResourceException .
It seems that, in your WindowsFormsApplication1 project, there's a problem with a resource file.
There can be several causes; could you check that, for every .resx file in your project, there is a .designer.cs file associated?
Is Form1 marked as localizable? If so, there must also exist some relative resource files.
Another thing to do would be to put a beakpoint on the first line of Form1's constructor, and pressing F11 line by line to find which one, in InitializeComponent() method, throws the exception.
Hope this helps.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
|
|
|
|
|
Thank you i think i figured it out
|
|
|
|
|
I fixed that part i had to change the string name variable to something else, it was bringing another value from the top.
But on this section:
subkeyAA.SetValue("UserFilter", "company.com", RegistryValueKind.Binary);
I get ArgumentException was unhandled
{"The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted."}
|
|
|
|
|
I also facing the same issue in the coding.. Can anyone help out in this issue
|
|
|
|
|
I am in the process to get a code signing certificate but there are some things I am not too sure about..
1st they ask me what kind of certificate I want, either of:
---
Adobe AIR
Sun Java
Multi-platforms
Mozilla
Microsoft Authenticode
Microsoft Macros and VBA Macros
---
I want a .pfx that can sign my .msi file! Would it be a "Microsoft Authenticode"?
Then they ask me a Company Name & Division!
I am working on my take over the world at home I my free tie at the moment, haven't have a company yet!
Should I register one? (what would be the 'division' anyway?)
Further it would be an Australian company name, how would that help a world wide certificate?
|
|
|
|