I have a C# Windows Forms application where I eventually start another program with
Process.Start()
For all people using my software the new program now starts with English keyboard.
Is there a way to fix that issue?
FYI, the Windows Forms app is only available in English.
I have 2 ideas:
First one is to check ALL of your Project settings and look if you have somewhere set the english keyboard or just english language.
Second idea from here:
1- For better performance, get the machine installed language as
follows: C#
public static InputLanguage GetInputLanguageByName(string inputName)
{
foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
{
if (lang.Culture.EnglishName.ToLower().StartsWith(inputName))
return lang;
}
return null;
}
2- Set your preferred language at run time: C#
public void SetKeyboardLayout(InputLanguage layout)
{
InputLanguage.CurrentInputLanguage = layout;
}
Related
I've localized my App in two languages (English and German) with the MulitlingualAppToolkit 4.0. English is the base language, while german is a translation based on the english one.
The translations are stored as resw-file inside folder "strings.en" and "strings.de".
In App.xaml.cs App() I set the culture like this:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = GetCurrentCulture();
CultureInfo.CurrentUICulture = GetCurrentCulture();
private CultureInfo GetCurrentCulture()
{
var cultureName = new DateTimeFormatter("longdate", new[] {"US"}).ResolvedLanguage;
return new CultureInfo(cultureName);
}
(I got this quiet weird way to the regional-culture in Windows 10 from this article https://www.pedrolamas.com/2015/11/02/cultureinfo-changes-in-uwp/ since I recognized that CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture are always "en-EN" no matter what i configurate in my machines regional- and language-settings)
To check if PrimaryLanguageOverride works as expected, I added a TextBox by the name of tbTest on my first Page and a button linkt to this event:
private void Button_Click(object sender, RoutedEventArgs e)
{
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = tbTest.Text;
Frame.Navigate(this.GetType(), 0);
System.IO.File.AppendAllText(System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "PrimaryLanguageOverride.txt"),
DateTime.Now + " - Actual PrimaryLanguageOverride:\n " + WIndows.Globalization.ApplicationLanguages.PrimaryLanguageOverride);
}
catch(Exception ex) { Helper.Log.LogUnhandledError(ex); }
}
Now comes the weird stuff:
When Debugging, or executing the App from my Development-Machine, everything works as expected, but when I make an appx-bundle and install it on another (Windows10-Desktop) device, the App does not recognize the its Language.
In my situation, the device is set to german, regional as well as its language. Also when using the test-procedure, it defenetively gets the string I set , as long as it's a valid culture-name, e.g.: "en-EN", "en-US", "de-DE", "de", "en" (all of these are working fine on my development machine) if it's an invalid string, I get an exception, with a log-entry in my unhandled-error-log. It refresh the Page, and even writes the new-set language in my PrimaryLanguageOverride-Log, but it doesn't change any text I did translate.
So my question is, is this a common Issue (since I recognized in UWP/Win10 the culture-system is a little messed up) or do I use the wrong procedure to override the App-Culture?
This is an issue with AppXBundling. When Installing bundles, it checks with the current OS for the installed Language packs and copies the relevant language resources from the bundle and omits the other language files. The objective of a single bundle is to copy necessary resources and build the application and therefore the languages which are not in the system are considered irrelevant. As a fix you could stop generating single bundles and create package for each CPU architecture. Check this for more info
I'm try to use Vista TaskDialog Wrapper and Emulator and I'm getting the following exception:
"Unable to find an entry point named 'TaskDialogIndirect' in DLL 'ComCtl32'."
...in a simple Console application:
class Program
{
[STAThread]
static void Main(string[] args)
{
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
PSTaskDialog.cTaskDialog.MessageBox(
"MessageBox Title",
"The main instruction text for the message box is shown here.",
"The content text for the message box is shown here and the text willautomatically wrap as needed.",
PSTaskDialog.eTaskDialogButtons.YesNo,
PSTaskDialog.eSysIcons.Information
);
}
}
What am I doing wrong?
UPDATE:
Actually, I'm working on an Excel plugin using excel-dna. How can I control what dll Excel loads?
http://exceldna.codeplex.com/discussions/286990#post728888
I haven't been at Office programming in a while, but my guess is that Excel loads both versions of comctl32, so you may need to use the Activation Context API to direct your code to the version that includes TaskDialog. Some ideas for fixing the problem (not solutions as such):
For test purposes, make a temporary enumeration of all modules in the active process - just to check if 6.10 is actually loaded (see below for a simple example of such an enumeration, albeit with a different intent).
Use the Activation Context API to get to the right version. Example of use from C# (for enabling themes by way of comctl32 6.0) here.
Alternatively (I never actually got this to work reliably in a WPF application I worked on), make a dialog abstraction class, which falls back to MessageDlg depending on the version available to you. There may be better ways of doing the check, but...:
FileVersionInfo version = ProcessUtils.GetLoadedModuleVersion("comctl32.dll");
if (version != null && version.FileMajorPart >= 6 && version.FileMinorPart >= 1)
{
// We can use TaskDialog...
}
else
{
// Use old style MessageBox
}
The enumeration of modules:
internal static FileVersionInfo GetLoadedModuleVersion(string name)
{
Process process = Process.GetCurrentProcess();
foreach (ProcessModule module in process.Modules)
{
if (module.ModuleName.ToLower() == name)
{
return module.FileVersionInfo;
}
return null;
}
}
In addition to what all the others are saying: This error will disappear if you set the ForceEmulationMode on PSTaskDialog to true.
I need a GUI system that contain:
a tree list that each item of list linked to a view and when I click on a Item open the view
for next step
I want to insert to each view some grids.
I see a demo example named :dockpanelsuite http://sourceforge.net/projects/dockpanelsuite/
there is a explorer and multi document
I think that I can change it to my requirment.
but this is in C# and I need something in C++.
if is same sample in MFC ,or I can combine them?
what about performace and stability?
thanks herzl
use QT. It's comprehensive, has a lot of tutorials in the web out there, is portable and is in C++.
Qt is better than MFC for a number of reasons including:
. > 1.It is open source
2.It is cross platform. It works on Linux, some mobile devices and
Mac
OSX. This makes it easier to port
programs to other platforms.
> 3.Qt is much easier to use and learn that MFC.
> 4.Above all Qt is well documented.
MFC is too big library. Go for win32 if you only want simple GUI
Win32++ as also a nice little library for windows only development.
You could start creating a new MFC SDI App in the App Wizard pick the Visual Studio Project Style, you will need to use the Document/View architecture.
With the generated App you could work you way to have in the left docking pane a derived ListControl class from CMFCListCtrl.
class CMyListCtrl : public CMFCListCtrl
{
// Your stuff goes here....
public:
DECLARE_MESSAGE_MAP()
afx_msg void OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);
}
in the implementation file you could handle the click event with something like this..
BEGIN_MESSAGE_MAP(CMyListCtrl, CMFCListCtrl)
ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, &CMyListCtrl::OnLvnItemchanged)
END_MESSAGE_MAP()
void CMyListCtrl::OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
POSITION p = GetFirstSelectedItemPosition();
int nSelected = GetNextSelectedItem(p);
if (nSelected != -1)
{
CString strText = GetItemText(nSelected, 0);
// we open the document.....
CMainFrame *pFrame = static_cast<CMainFrame *> (AfxGetMainWnd());
CWinApp *app = AfxGetApp();
app->OpenDocumentFile(strText,FALSE);
pFrame->ShowJobsProperties ();
}
*pResult = 0;
}
SpeechSynthesizer allows peaking different voices by using
SelectVoiceByHints(VoiceGender, VoiceAge)function (as I understood). But no customization happens if I change the gender and voice age.
Can you explain why? And if I'm doing something wrong, what is correct way to do that?
Thank you.
Here's a small test program that you can use to discover installed voices:
using System;
using System.Speech.Synthesis; // Add reference to System.Speech
class Program {
static void Main(string[] args) {
var synth = new SpeechSynthesizer();
foreach (var voice in synth.GetInstalledVoices()) {
Console.WriteLine(voice.VoiceInfo.Description);
}
Console.ReadLine();
}
}
Output on my machine: Microsoft Anna - English (United States)
Which is the one and only default voice that's shipped with Windows afaik. Which would of course explain why changing gender and age doesn't have an effect on your machine.
According to the name of the function, I'd say this is a selector for installed voices. It does not customize the voice in any way, but rather picks one from the repo according to your specified parameters.
So, if there is only one voice installed, he can only pick that one.
I have a C# application that needs to set the Windows language bar to english or at least back to the default setting. I know I can set the InputLanguage of my own application but I need to set the input language for Windows in general. This can be done manually using the language bar, but I need a way to do it programmatically. Is there a way to do this?
I ended up doing this:
Process[] apps=Process.GetProcesses();
foreach (Process p in apps)
{
if (p.MainWindowHandle.ToInt32()>0)
{
NativeWin32.SetForegroundWindow(p.MainWindowHandle.ToInt32());
//send control shift 2 to switch the language bar back to english.
System.Windows.Forms.SendKeys.SendWait("^+(2)");
p.Dispose();
}
}
I haven't done this since Windows XP was in it's childhood, so you may want to check if the language support is still based on the same principles. It is all Win32, so they need to be imported for C#.
First, read on MSDN the pages about keyboard input:
http://msdn.microsoft.com/en-us/library/ms645530%28VS.85%29.aspx
GetKeyboardLayoutList tells you what layout are installed
LoadKeyboardLayout loads a new input locale identifer.
ActivateKeyboardLayout sets the current language
A much better approach to this is this:
//change input language to English
InputLanguage currentLang = InputLanguage.CurrentInputLanguage;
InputLanguage newLang = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("en-US"));
if (newLang == null)
{
MessageBox.Show("The Upload Project function requires the En-US keyboard installed.", "Missing keyboard", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else
{
InputLanguage.CurrentInputLanguage = newLang;
}
See full post on this: Language Bar change language in c# .NET