I've already read through this thread: Stop the 'Ding' when pressing Enter
I'm having no luck with e.SuppressKeyPress. I get an error "'KeyPressEventArgs' does not contain a definition for 'SuppressKeyPress' ..."
I am VERY VERY VERY VERY new to this. I cannot understate this enough. Please explain like I'm 5 years old. Sorry..
I'm using Visual Studio Express 2015 to create a Windows Form with C#.net.
Here is my code:
private void answer_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)ConsoleKey.Enter)
{
CheckAnswer();
}
}
I tried putting e.SuppressKeyPress = true; after my CheckAnswer(); function but I get red squigglies indicating it doesn't know what that is.
Why?
I've had no formal training in using C#.net and I'm missing the foundation of how this is all supposed to work which is messing me up I think. :(
Related
It's quite strange to state hereby, but remains to be a fact that, in one of my VSTO projects while the following piece of simple code works well enough, in another project, while it's almost exactly the same, i.e. assigned to a Ribbon's Button, the latter project only reflects the message in Visual Studio's Footer as Build Failed, as per the image following the same i.e. without even an error being highlighted?
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Microsoft.Office.Interop.Excel.Range RG = Globals.ThisAddIn.Application.InputBox("Select your desired cells:", Type: 8);
MessageBox.Show(RG.Address);
Microsoft.Office.Interop.Excel.Range RG2 = Globals.ThisAddIn.Application.Selection;
MessageBox.Show(RG2.Address);
}
What could be the reason???
The only difference between the said two projects is that in the latter project I am trying to use the WPF Forms in the same as per a video on YouTube, i.e.: Office Addin with WPF Windows Controls for Word Excel Access Forms
Upon Googling led me to find out the solution of using the following line for matter of Selection but have been unable to find a similar solution for Application.InputBox:
Microsoft.Office.Interop.Excel.Range RG2 = Globals.ThisAddIn.Application.ActiveWindow.RangeSelection
Even placing a similar question on Microsoft's Answers Community led to no reply till now, :,-(
Any advice / help would be appreciated.
Thanks in advance.
It's quite strange, but true enough. Till now the Visual Studio was not reflecting any error but today when I tried again to implement WPF in a VSTO it finally reflected that there was a Casting Error???
The said error also appeared for only few seconds and then again disappeared with the same old footer reflecting build failed.
When I googled it no doubt turn out to be so and the very first site clarifying the said matter was quite fruitful enough.
Thus, changing my code to the following did turn out to be resulting to a successful build:
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Microsoft.Office.Interop.Excel.Range RG = (Microsoft.Office.Interop.Excel.Range)Globals.ThisAddIn.Application.InputBox("Select your desired cells:", Type: 8);
MessageBox.Show(RG.Address);
Microsoft.Office.Interop.Excel.Range RG2 = (Microsoft.Office.Interop.Excel.Range)Globals.ThisAddIn.Application.Selection;
MessageBox.Show(RG2.Address);
}
Alhamdulillah!
I have a textblock (ContentTextBlock) with AutomationProperties.LiveSettings="Assertive". I'm just testing and checking how useful this feature is. And... am disappointed so far.
private void Button_Click(object sender, RoutedEventArgs e)
{
ContentTextBlock.Text += " test";
var peer = UIElementAutomationPeer.FromElement(ContentTextBlock);
if(peer == null)
{
peer = UIElementAutomationPeer.CreatePeerForElement(ContentTextBlock);
peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
}
peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
}
When using Narrator, this works as advertised. Whenever clicking the button, Narrator announces the TextBlock text ("test" "test test" "test test test")... But when I use NVDA or JAWS, nothing happens, although the screenreader versions are relatively up-to-date. Did they really not add any support for live-regions or am I just missing an important point?
Whilst I didn't manage to get live regions to work, I found another workaround:
Tolk by Davy Kager
Tolk is a library which can, among oterrs
Detect which supported screen reader, if any, is running
Pass strings to the screen reader's speech engine and braille.
Also has support for SAPI
To include Tolk in your C# project, download it from the link above, then include tolk.cs (from src/dotnet) in your project, and place tolk.dll (it's found in bin) in the folder with your executable (or somewhere in the PATH variable). Make sure that the dll version matches your CPU target (x86/x64). Do the same for the dlls in the lib directory. Then you can use it according to the code found in the examples folder.
PS. Tolk works on Win 7 as well, so that's a bonus. The live-regions of WPF were only supported from Win 8 on.
This question already has an answer here:
UWP app: FileOpenPicker PickSingleFileAsync() can't await
(1 answer)
Closed 5 years ago.
I am building an UWP app (C#) and on click of button, I want to verify input.
If verification fails, I want to display a message saying that there is wrong input.
this is my function which should handle this:
private async void AddContact_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
DBHelper db = new DBHelper();
if(i_name.Text != "" && i_phone.Text != "") {
db.insertPerson(new Person(i_name.Text, i_phone.Text));
Frame.Navigate(typeof(MainPage));
} else {
ContentDialog msg = new ContentDialog() {
Title = "Empty input!",
Content = "Please fill both fields!",
CloseButtonText = "OK"
};
await msg.ShowAsync();
}
}
However, when the last part (await msg.showAsync() ) is typed it stays underlined in red (in VS). The builder reads the following error:
Error CS4036 'IAsyncOperation' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation' could be found (are you missing a using directive for 'System'?) testniStudioApp d:...\SecondPage.xaml.cs 43 Active
Now i tried to assign this call to variable (as I saw that someone solved similiar problem that way), but it still didn't worked.
Then I tried clearing NuGet cache and rebuilding project as stated here, but none of those solutions worked.
I have a hard time understanding what it wants from me.
Every single tutorial on how to display message was written in more or less the same manner, so I can't understand what can be wrong.
using System; was mising.
Thanks to comments for answer
I have problem with my speech recognition.
It works on "English" windows with no problem.
It also works on some "Foreign" windows too. But only some.
I'm getting that exception:
The language for the grammar does not match the language of the speech recognizer
I added my own words to dictionary.
How can I fix it?
Not sure which version .net you are on, but I'll attempt to answer.
On your English Windows version, please navigate to C:\Program Files\Reference Assemblies\Microsoft\Framework[YOUR .NET VERSION]
You should find System.Speech.dll,
Make sure to bring this .dll over to your foreign computer, and everything should run smoothly.
I had the same problem on my friends Computer. So I made this (it is just part of the code, because all the code is really long ):
...
RecognizerInfo recognizerInfo = null;
foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
if ((ri.Culture.TwoLetterISOLanguageName.Equals("en")) && (recognizerInfo == null))
{
recognizerInfo = ri;
break;
}
}
SpeechRecognitionEngine SpeachRecognition = new SpeechRecognitionEngine(recognizerInfo);
GrammarBuilder gb = new GrammarBuilder(startLiserninFraze);
gb.Culture = recognizerInfo.Culture;
grammar = new Grammar(gb);
SpeachRecognition.RequestRecognizerUpdate();
SpeachRecognition.LoadGrammar(grammar);
SpeachRecognition.SpeechRecognized += SpeachRecognition_SpeechRecognized;
SpeachRecognition.SetInputToDefaultAudioDevice();
SpeachRecognition.RecognizeAsync(RecognizeMode.Multiple);
...
So this should work. My friends PC supported 2 instances of "en" or in "eng". Not sure why. So the code selects first one. I found some pieces of code on the internet and some of this is made by me.
SpeachRecognition.SpeechRecognized += SpeachRecognition_SpeechRecognized;
is made to make an event when everything is recognized. just type:
SpeachRecognition.SpeechRecognized +=
and the press TAB button (atleast in VS 2013) few times. and then in the bottom of code it will generate something like this:
void SpeachRecognition_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//then will be some line that you need to replace with your code
}
I hope this will help. :)
I've seen this question circulate around the internet a lot, but haven't found an answer that has solved my problem. I am basically using SpicIE.Controls.Toolbar (C#) to create an explorer bar for IE. It has a few text-boxes on it among other things. The problem I have is that when I am typing in the text-box and hit backspace, the browser handles it and instead of deleting the character on the text-box, it goes back one page on the browser. In order to fix this problem, I created my own custom text box to be able to handle backspace properly:
public class MyTextBox:TextBox
{
protected override void OnKeyUp(KeyEventArgs e)
{
if (e.KeyValue == 8)
{
this.Text = this.Text.Substring(0, this.Text.Length - 1);
this.SelectionStart = this.Text.Length + 1;
e.Handled = true;
}
}
}
The code does work as it is supposed to but the browser still goes back one page even after e.Handled is set to be true.
Can anyone help me with this? I feel like I have been to all forums where they discuss this, and still haven't found an answer
Thanks for your help guys!
Generally when this happens it means the extension did not implement IInputObject correctly. I'm not familiar with the SpicIE framework, so I'm not sure if you need to implement it or they do.