I am using C# & .Net 4.0 and want to set the a differnet spellcheck language for a textbox without changing the keyboard layout.
I found out by reading great postings here that it is possible to change InputLanguage.CurrentInputLanguage for changing the SpellCheck language of my textbox. But this has the sideeffect, that the keyboard layout/language was changed too. But I need always an EN SpellCheck for my textbox without crashing the users keyboard settings. Is there any way for this case?
Thanks in Advance for every hint that can help me to solve this case.
I have found out, how to solve it.
You have to know, that I use the WPF TextBox in a Winforms project. Here is a sample code:
System.Windows.Forms.Integration.ElementHost elementHost1 = new System.Windows.Forms.Integration.ElementHost();
System.Windows.Controls.TextBox textBox = new System.Windows.Controls.TextBox();
textBox.Language = System.Windows.Markup.XmlLanguage.GetLanguage("en-GB");
textBox.SpellCheck.IsEnabled = true;
elementHost1.Child = textBox;
Setting the language using textBox.Language didn't work for me.
There seems to be an edge case where spell checking is completely disabled if the user's presently selected input language doesn't have the spelling dictionary installed for that language (i.e. the feature-on-demand language pack is missing for basic typing) - see here https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/features-on-demand-language-fod
Take the following example:
• the user's current selected language/keyboard is fr-FR
• the user doesn't have the "basic typing" feature on demand installed for fr-Fr (no dictionary is therefore available)
• the user does have en-GB installed as well as "basic typing", so the dictionary is available for en-GB.
I wanted to force my textbox to spell check in en-GB, even though the user's keyboard was set to fr-FR. (The reason for this is I'm actually piggy-backing off the WPF spell check feature to spell check an underlying document).
However, just setting the Language attribute in the textbox wasn't achieving that. i.e. even when specifying en-GB for Language, the spell check wasn't available.
In the end, I had transiently to set the input language to the desired language, create the textbox, and then change it back to the user's existing input language. This is therefore transparent to the user (i.e. as far as the user is concerned, it doesn't disturb their current input language).
InputLanguage original_language = InputLanguage.CurrentInputLanguage;
System.Globalization.CultureInfo my_culture = new System.Globalization.CultureInfo("en-GB");
InputLanguage c = InputLanguage.FromCulture(my_culture);
InputLanguage.CurrentInputLanguage = c;
System.Windows.Controls.TextBox testBox = new System.Windows.Controls.TextBox();
testBox.SpellCheck.IsEnabled = true;
elementHost1.Child = testBox;
InputLanguage.CurrentInputLanguage = original_language;
Note that, once the textbox has been created and bound to the elementHost, it doesn't matter if you change the input language back - the language of that textBox is permanently set to what it was when it was created.
Therefore, in the above example, the user would end up with the spell check working in British English, but still have his or her keyboard set to French.
In practice, there's extra code to the above to check that the language you're setting (en-GB in this case) is actually installed.
Related
I am trying to set up a Windows Form login screen that uses the user's language to set either German or English for a class. I have set up my .resx files within the Properties of my project, but I cannot figure out why the form always shows in English.
I reviewed How to use localization in C# and How to make multi language app in winforms, which is where I found the information on setting up the Strings.resx and Strings.de.resx files, but the text when I set my UI Language to German always shows in English. On the LoginForm Properties, I have Localizable set to True.
As I want the app to load the screen with the correct language, I placed all my code in the Load Event:
private void LoginForm_Load(object sender, EventArgs e)
{
// Check system language
CultureInfo Language = CultureInfo.CurrentUICulture;
// Check if system language is set to German or English, and display
// login screen elements as appropriate
if (Language.Name.ToString() == "Deutsch")
{
LoginLabel.Text = Properties.Strings.LoginLabel;
UserLabel.Text = Properties.Strings.UserLabel;
PasswordLabel.Text = Properties.Strings.PasswordLabel;
LoginButton.Text = Properties.Strings.LoginButton;
ExitButton.Text = Properties.Strings.ExitButton;
}
}
I know I'm likely missing something simple, but I can't figure it out. If I need to, I can manually set the Text fields to the German version, but I'd rather have it separated in the .resx files if possible.
Changed Language to a string, and removed the if loop, and it's now appearing in German when set that way.
There are many questions about it but still haven't read a solution for me
I have all my resources in a seperate project and this project has a Resource folder with 3 languages in it.
In any control I have in the constructor a call to InitializeLanguage()
where I set the right text for the right language like this:
public void InitializeLanguage()
{
bOK.Text = Lastenboek.Language.Ok;
cbSM.Text = Lastenboek.Language.SamenvattendeMeetstaat;
cbDM.Text = Lastenboek.Language.DetailMeetstaat;
cbDMHeadingStyles.Text = Lastenboek.Language.KopStijlen;
cbExportArtikelsZonderMeetstaat.Text = Lastenboek.Language.ArtikelsZonderMeetstaat;
cbSMHeadingStyles.Text = Lastenboek.Language.KopStijlen;
cbRamingsPrijs.Text = Lastenboek.Language.Ramingsprijs;
cbBeknopteOmschrijving.Text = Lastenboek.Language.BeknopteOmschrijving;
cbFaseSM.Text = Lastenboek.Language.GesplitstOpFase;
groupBox3.Text = Lastenboek.Language.Filter;
label2.Text = Lastenboek.Language.Tot;
label1.Text = Lastenboek.Language.DatumVan;
gbPrijzen.Text = Lastenboek.Language.Prijzen;
label3.Text = Lastenboek.Language.Account;
cbTotaalSM.Text = Lastenboek.Language.Totaal;
groupBox4.Text = Lastenboek.Language.Template;
label4.Text = Lastenboek.Language.Layout;
Text = Lastenboek.Language.ExporteerMeetstaat;
}
Everything works fine but now sometimes the label is too small for the text in other languages. Is there a good way to change the language at designtime and change the dimensions for different languages?
Yes. And you don't even need to programmatically set localized texts/images and other values.
Just set Localizable property on your form to true and then you can switch languages at design time and edit everything for that language at design time.
When you start the application the form will use the Windows language. If you want to change it programmatically just set Thread.CurrentThread.CurrentUICulture property. You might want to repoen your form to apply the language or call InitializeComponent() explicitly.
The problem is that you have dynamic texts for controls, but you want to have "hardcode" fixed control sizes for every language.
with this approach maintaining can be complicated. Every change in translation should be tested in UI - is it fit or not in the control.
Another approach will be support "AutoSize" for controls. Winforms have TableLayoutPanel control, which can be useful for controls with dynamic texts.
So I have tooltips on a variety of checkboxes and sliders in my application. This is partially necessary because the app is intended to be used by specific people at my company to create files (a large number of proprietary file formats, each with a variety of options). I decided at one point that tooltips were a good stopgap measure until there's a full set of documentation, plus it makes it easier on the fly to see what is out there.
I've considered using a global configuration checkbox that would enable or disable tooltips, but I was wondering if there was an elegant way to only display tooltips on mouseover while CTRL was being held down. I couldn't readily find anything on this. Any comments are appreciated.
Edit: The reason being that having tooltips pop up all the time as you move through the interface isn't really ideal, but being able to quickly access tooltips is very helpful.
Also, can someone please explain why this kind of question gets down-voted? It's frustrating to come here and see questions like "What is .NET" remain positive, and questions where I'm trying to learn something specific that isn't readily available on the Internet-at-large gets down-voted.
Here are all of the locations where the tooltip tipFRBx9P446 exists in my actual code.
Form1.Designer.cs:
this.tipFRBx9P446 = new System.Windows.Forms.ToolTip(this.components);
this.tipFRBx9P446.SetToolTip(this.cbFRBx9P446, "This will force P44 fields to reflect a value of \'6\'. This can be used to ensure" + " proper testing of TFS WI 75062.");
//
// tipFRBx9P446
//
this.tipFRBx9P446.UseAnimation = false;
this.tipFRBx9P446.UseFading = false;
//
private System.Windows.Forms.ToolTip tipFRBx9P446;
Form1.resx:
<metadata name="tipFRBx9P446.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>762, 17</value>
You can use the Control.Modifier Key to check if CRTL is pressed:
if (Control.ModifierKeys == Keys.Control)
{
//CRTL is being pressed, show tooltip
}
You should be able to use this code in your "Mouse_Hover"-event of the respective checkboxes.
Hope this will help!
I need to show, and input some text in xbox-like onscreen keyboard. Sadly, when I call Guide.BeginShowKeyboardInput, there is only some funny textbox shown, and i must fill it via keyboard. I know, that on PC iv very normal to use keyboard, but in my case i MUST enter text via gamepad, using xbox on screen keyboard.
Is there any way to achieve this? To call xbox onscreen keyboard on PC?
If you need one for like a touchscreen monitor you could do
using System.Diagnostics;
using System.IO;
then use this function
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + "osk.exe");
but if you need it to work with like an xbox controller you will probably need to build your own
No. It was a design decision (documented here) to give the end user control of the keyboard being invoked. Therefore, the end user has to touch a text box (or the like) to invoke the virtual on-screen keyboard.
Check this text form this link
Blockquote User-driven invocation
The invocation model of the touch keyboard is designed to put the user in control of the keyboard. Users indicate to the system that they want to input text by tapping on an input control instead of having an application make that decision on their behalf. This reduces to zero the scenarios where the keyboard is invoked unexpectedly, which can be a painful source of UI churn because the keyboard can consume up to 50% of the screen and mar the application's user experience. To enable user-driven invocation, we track the coordinates of the last touch event and compare them to the location of the bounding rectangle of the element that currently has focus. If the point is contained within the bounding rectangle, the touch keyboard is invoked.
Blockquote This means that applications cannot programmatically invoke the touch keyboard via manipulation of focus. Big culprits here in the past have been webpages—many of them set focus by default into an input field but have many other experiences available on their page for the user to enjoy. A good example of this is msn.com. The website has a lot of content for consumption, but happens to have a Bing search bar on the top of its page that takes focus by default. If the keyboard were automatically invoked, all of the articles located below that search bar would be occluded by default, thus ruining the website's experience on tablets. There are certain scenarios where it doesn't feel great to have to tap to get the keyboard, such as when a user has started a new email message or has opened the Search pane. However, we feel that requiring the user to tap the input field is an acceptable compromise.
Check out: http://classes.soe.ucsc.edu/cmps020/Winter08/lectures/controller-keyboard-input.pdf
You might find your answer in here, It has all information about the input of a gamepad and such.
There is a good guide on how to do this here:
static public string GetKeyboardInput()
{
if (HandleInput.currentState.IsButtonDown(Buttons.B))
{
useKeyboardResult = false;
}
if (KeyboardResult == null && !Guide.IsVisible)
{
string title = "Name";
string description = "Pick a name for this game";
string defaultText = "Your name here";
pauseType = PauseType.pauseAll;
KeyboardResult = Guide.BeginShowKeyboardInput(HandleInput.playerIndex, title,
description, defaultText, null, null);
useKeyboardResult = true;
pauseType = PauseType.pauseAll;
}
else if (KeyboardResult != null && KeyboardResult.IsCompleted)
{
pauseType = PauseType.none;
KeyboardInputRquested = false;
string input = Guide.EndShowKeyboardInput(KeyboardResult);
KeyboardResult = null;
if (useKeyboardResult)
{
return input;
}
}
return null;
}
And your Update method should contain something like this:
if (KeyboardInputRequested)
{
string result = GetKeyboardInput();
}
if (result != null)
{
//use result here
}
It is unlikely that the on-screen keyboard was packaged in the XNA DLLs for PC, but if you really want to find out, you could research a free .NET decompiling program (such as ILSpy) and look through it.
Also, you can't use the chatpad either. I would recommend either making your own on-screen keyboard that is usable by a controller, or maybe, if you can, using the MonoGame framework (an open-source version of XNA), and modifying it to have an on-screen keyboard on Windows.
You could also make a separate program that acts as a virtual keyboard controlled by the controller.
Image http://www.freeimagehosting.net/uploads/7efc3b2ddd.png
Is there any idea to create this in C# Windows Application.
We have a tool tip property of Text Box.Select the Text box press F4 or directly go to the property of Text box->Tool Tip->(Put the Text Whatever you want)This value can't be blank.
There is an "Error Provider" component that you can add to a form, which adds a "Error" property on every control. It accomplishes a similar goal, but does it a bit differently as far as the visual representation goes.
Propably you need validators to check input forms. these classes are presented in ASP.NET
unfortunatly for winforms you should do it on your own.
for instance there are events of TextBox Validated and Validating what you can handle to check input data.
Can't we use like
ToolTip t = new ToolTip();
t.IsBalloon = true;
if(textBox1.Text=="")
t.Show("This value can not be empty", this.textBox1 , 0, -40, 1000);
??