Trigger screen reader when control already has focus - c#

I'm looking for a way to force a winforms controls which already has focus to be (re)announced by the screen reader.
The situation is that I have a manually painted area which the user is able to navigate around using the arrow keys, but since it's only a single control the focus is always the same so the screen reader only announces the control on the initial focus.
I have tried Focus()ing (and Select()ing) on a second control then immediately Focus()ing back, but this doesn't trigger the screen reader. The only way I've managed to get that working is to get the second control to wait 100ms then refocus back from a background thread, but then the second control is announced to the user, and there's a minefield of edge cases and race conditions.
It looks like UIA LiveRegions is the solution for this for .NET 4.7+, but I'm stuck on 4.6.
Any ideas how I can force the screen reader to re-announce the control under focus?

Related

UWP - Onscreen keyboard closes when switching to another textbox

I'm experiencing a strange bug(?) with my uwp app.
I have a page with multiple textboxes for user input that each have the InputScope set to number, which then opens the keyboard in tablet mode as expected. However if you tap on the next box the keyboard closes and a second tap is needed to open the keyboard. This also happens if the user hits tab to switch boxes.
I presume this has something to do with the Focus() event firing before the previous textbox has fired the loss of focus event but im unsure how to override the behavior.
How can i prevent the onscreen keyboard from closing, but also make sure the correct inputscope is still maintained?
Edit: Upon further investigation, the issue seems to be almost random. Sometimes you can move to different boxes and it remains open but other times it closes the keyboard every time.
This issue has been resolved with some others, in Windows 10 version 1803 released on 30th April, 2018.
You can try to play with InputPane that is a container for on-screen keyboard. For example, doing a small delay once the pane is trying to hide, then detect attempts to show the pane again (and cancel pending hide).
myPane = InputPane.GetForCurrentView();
myPane.Showing += myShowingHandler();
myPane.Hiding += myHidingHandler();
At least, you can receive a size of underlying screen region on the pane showing so you can put a placeholder (margin or dummy grid) on your UI to prevent it jumping up and down on keyboard show/hide.
I tried your case on my WP but I cannot reproduce your experience:
When I tap to other TextBox, keyboard stays opened and I can continue typing.
Keyboard hides as expected when I tap somewhere to whitespace.
Don't you have keyboard connected to your device?

SurfaceListBox not responding to touch gestures for several seconds

I have a WPF-program that has a grid with two columns. First one has buttons and second one has WindowsFormsHost-element that embeds an ActiveX component. One button hides the WindowsFormsHost-element and shows a SurfaceListBox on the same location on screen in the second column. If I have touched the WindowsFormsHost element just before pressing this button, it takes approximately 8 seconds from the last touch until the SurfaceListBox becomes responsible for touch gestures.
The thread is probably not blocked, because I can use the buttons in another column, and use use the ListBox with mouse.
The ListBox remains unresponsive for touch events forever, if I touch it within the 8 second waiting time. So it seems that somehow the ListBox does not get the touch events.
If I programmatically create another ListBox, it does not work either, for 8 seconds, if it is placed in same are on screen than the WindowsFormsHost was.
I noticed there is a method CaptureTouch() for UIElement, but I cannot get hold of to the TouchDevice that I could pass it as parameter. I have set ManipulationEnabled="true" for every UIElement and no TouchEvent will be fired.
I have also desperately used UpdateLayout() etc with no luck.
So I think the touch gestures are somehow routed wrong and after the waiting time it implicitly fixes the routing, but is there a way I could make the touch gestures work in the ListBox immediately?
The problem disappeared when I removed "focus tracking for launching on-screen keyboard" from my program.
So in case of somebody else struggles with the same problem,
http://www.infragistics.com/community/blogs/blagunas/archive/2013/12/17/showing-the-windows-8-touch-keyboard-in-wpf.aspx and SurfaceListBoxes aren't meant for each other.

Balloon pop up over control mouse enter/exit

Hello,
Above is the program I am writing. On the right panel is basically two custom controls (the blue rectangle area) I created and just added them as controls to the background panel control when this winform program loads.
I used MS paint to draw out the pop up balloon that I want to see when my mouse enter this control's area. I want to do the following:
1. If mouse enter the control area, the yellow area balloon pop up and populate with the information of that specific control
2. If mouse move out of the control area, the pop up balloon disappear.
Can this be done with Winform application? I looked around and found out about Tooltip class but so far from researching I don't know if it does what I want to do.
I could be wrong but googling around gave me the impress that Tooltip offers very little in term of style. Ideally I want to make this pop up balloon into almost like a border-less pop up window where I can put image , font ect.....at will. Also Tooltip works if you hover over a button or specific field whereas I want the entire control area.
Can this be done? I appreciate if you can point me to any work around if there is one.
I wrote a comment, but I figure I'll expand it into a full answer. This is assuming you want a new control, which isn't a tooltip, for maximum customizability. I did something similar to this for work recently, to act as a non-modal info popup that disappears when clicked.
Creating a Custom Popup Form
What you want is essentially a floating popup that appears over your form, which means you'll want to define a new Form object, rather than a UserControl, as it won't actually be embedded within your other form.
Give it a multiline, non-editable textbox that you can fill with the information you want to populate, then simply call a new instance of the form on your Mouse_Enter event. Close it upon Mouse_Leave.
Adjusting The Style
You'll have to play with it a bit to get it to actually act like a popup and not just a window. I'd recommend setting it to a non-modal popup, and removing the border. You can write a function to automatically size it to its contents. I don't imagine you'll want the user manually resizing it.
Some other things to look into would be overriding the CreateParams property that comes with the basic Form object. You can force DropShadows and TopMost forms without making the form modal. Overriding ShowWithoutActivation to always return true will prevent the form from stealing focus when it pops up.
I'm not sure if you can pull off rounded edges like you have in your mockup. Perhaps you can pull it off with some wizardry in the OnPaint() function, but I couldn't tell you how to do it.
It might be a bit of a pain for fiddling around with, but you can get some good functionality and appearance out of it. If you think you can pull it off acceptably with the ToolTip class, go for it. It took me about a week to get my notifications where I wanted them (though I added several features that you probably don't need to worry about).
Examples
Some keywords to look up in related searches would be Toast Notification and Non-Modal Popup. This might be some use:
http://www.codeproject.com/Articles/442983/Android-Style-Toast-Notification-for-NET
Since you already have implemented custom user controls you might want to try it again. Make a control that is that style and color, changes it's size based on it's text. You can feed it information (such as the text to display) from your existing user control object. You can also have the mouse enter/leave code reside in your first user control.
If you're not sure how to make a rectangle with round corners you can either make it on the fly using a graphics object (which will turn into a bitmap on the screen) or make it how you want it to look in GIMP (or photoshop if you have it) then use that image as the background on your user control. Make the default background transparent (so your voids above the round corners are not grey). If you make a pre loaded image you'll need to be aware you will only be able to scale it equally in Y and X directions. unequal scaling will make it look distorted.
Can you use the Mouse_Enter event on the control?

Animate a e.Graphics.DrawLine with arrowhead

I need to "animate" an arrow. It can go in any direction (up, down, left, right and diagonals) and the arrowhead will be at the end. It needs to appear as if it is growing from orgin to the end.
To make matters more complicated it has to be in a user control so it is possible to add to the controls collection in the forms and remove it to delete it from the screen, and its background is really transparent (no color.transparent) so i can't paint the background to "clear" the previous line.
I have it static already (drawn from origin to end) but i can't animate it. I tried to add a timer in the user control but I fail to get a correct algorithm to calculate the intermediate ends of the line while it is growing.
Any help would be appreciated.
Thanks
When using animation on a Windows form you have to use another thread. Look into using a background worker: http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
You don't need another thread - I have succesfully implemented Windows Forms animation.
My design:
Use a Windows.System.Forms.Timer object to call a callback function 'Animate()' at regular intervals
the Animate() function updates a property of your arrow, and then calls Invalidate() on the windows control
this all happens in the same UI thread, so yuo will not get any flicker effects (as long as your control has double duffering switched on).

C# ToolTip on MDI Client

I'm maintaining an application that shows a toolTip in certain conditions on a userControl. (When the mouse is over some area a timer starts, when it stops, and the mouse is still there, the toolTip displays a text, by calling "Show(..)".
This works fine.
A different applicatiion is holding this app as an MdiClient. The toolTip now only shows when the application is not active: If the user opens a different application on the computer, "WORD" for example, and then returns to mine without clicking on it, holding the mouse on the right region, then the text is displayed. Otherwise, although the "Show" is called, the "Popup" event is never raised.
Does anyone have an idea about how to solve this?
Thanks, Tali.
If I've understood the problem correctly, I think what you need to do is track when the window (which will show the tooltip) loses and gains focus. So when it loses focus, disable showing tooltips, then enable when it gains focus.

Categories

Resources