failedtoperformactiononhiddencontrolexception despite the textbox being clearly visible - c#

I have a wpf application which has a text box in which I can write a text value to just fine the first time around. If I exit the window the text box is in and then reopen that same window the box can no longer be found by the testing, despite being enabled, and clearly visible on my screen.
I looked at the values of the box, the x,y = -1,-1 and height,width are also -1,-1 which is confusing seeing as the box is completely visible.
I know what the text in the box will be, is it possible to search for a text box with that as a workaround?
I'll keep researching this but any feedback is appreciated :)
EDIT: Upon further study there is a second field on top of the original field providing an initial explanation as to what the box is for ("Enter field value").
Maybe this is a wpf error?

I found that the box wasn't being updated properly on the UIMap. This can be solved by setting the application windows SearchConfinguration (only in the specific test) to always search like so:
UIMap.ApplicationWindowName.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
Apparently this can cause a performance hit but I haven't noticed!

I would look at the SearchProperties and FilterProperties of the text boxes, I suspect that two have been found and the wrong one is chosen. Or, it may be that the second window has some different values for the properties used to identify the windows.
One idea: Run the program again manually, move the first window with the text box to one corner of the screen, then close that window. Cause the window to be reopened and move it to the opposite corner of the screen; leave the window on display. Open the UI Map of the Coded UI test and use the Locate command to find the box - it should draw a blue line around the text box.
Another idea is to call FindMatchingControls (as shown in Coded UI conditional check on a method is not working) then use the properties (such as some of x, y, height, width) to select the wanted control.
I doubt if it is a WPF error, but it may be an error in the WPF application where it is not clearing up properly when the first window closes.

Related

How i can to change the size of a form c# without losing the structure

I made a virtual keyboard in C# Visual Studio, but I have problems when I try to change the dimensions.
This is the virtual keyboard:
and this is when I try to change the dimensions:
I lose the buttons. I found a tutorial where he uses a rectangle.
In this photo is the "main" function, and after I called this function for every button from list (I make a list with all the buttons), I lose all the buttons. Only shift/caps remain because they are special characters.
Your best bet is to anchor the buttons and enable auto size then set the AutoSize mode to grow and shrink.
If all else fails, writing a function to change the font of each button to change down in size according to the size of the form is your only option.
What the problem most likely is is that the font sizes for the individual keys is too big and when you re-scale the keyboard the font doesn't change to compensate for the scaling down in buttons.
(EDIT)
Also, next time you make a post on these forums try to keep up with the formatting and try to use more accurate descriptions of the problem as well as the properties of the buttons because all of my possible solutions are just going off a whim based on prior experience. Thanks
(EDIT EDIT)
Ok I just saw the resizeControl method, I didnt see that before, however, my previous edit still applies. Properties for the buttons would be much appreciated to help answer your question. Also, try to edit the image to instead of being an image, just use the markup language like so:
//Like this
To make it easier for us to use and help debug, if you need to know how, just add 4 spaces before your code. Again, thanks

Moving controls on a form onto a tab

I have been working for months on a project in c# in Visual Studio 2010 (it interfaces with a camera, power supplies, and motion control). There is a form with many controls on it (radio buttons, buttons, text boxes, bitmap displays...). Now I would like to put all of that on a tab so i can have another tab. This is so that the second tab can have all the default settings on it (e.g, portnumber, baud rate, integration times, pathname...).
Is this doable? Is there a way to cut and paste or click and drag?
Update:
I created a form, put a button on it that when clicked displays a message box with "Hello World". Then i added a tab control to the form, and dragged the button onto the first tab. The button still functions in the same way, displaying the message box when clicked.
So on my big form, i added a tabcontrol. Without resizing it, i did a select all, then unselected the tabcontrol, then dragged everything onto the tab. I then moved the tab control and resized it, then iteratively resized the tab window and moved all the controls. this worked, except the picturebox controls somehow got resized so they were larger than a screen width. Resized the pictureboxes and everything works. (perhaps i just needed the encouragement to give it a try...sorry if not the best question:).
To do this in code, in Form1.Designer.cs can add:
this.tabPage1.Controls.Add(this.button1);
However, I would have to do this for every single control (about 200 of them in Designer.cs).
This can usually be done with some editing of the .Designer.cs file. First, make sure you make a backup in case it all goes horribly wrong. Place the tab control and add a single control (a button or anything) to it. Then examine the .Designer.cs file. As you point out yourself, you will see a line like this:
this.tabPage1.Controls.Add(this.button1);
As for the existing controls on the form, there will be a bunch of lines like this:
this.Controls.Add(this.meErrorReport);
this.Controls.Add(this.peWarningSign);
this.Controls.Add(this.meHeaderText);
this.Controls.Add(this.btnClose);
So what you do is to cut these lines (not including the one for the tab control!), and paste them just following the line shown above, and do a find-and-replace to change them so they match the first one:
this.tabPage1.Controls.Add(this.meErrorReport);
this.tabPage1.Controls.Add(this.peWarningSign);
this.tabPage1.Controls.Add(this.meHeaderText);
this.tabPage1.Controls.Add(this.btnClose);
This should usually do the trick. The controls may be positioned wrong, and most will be hidden until you increase the size of the tab control, but these are minor problems that can be fixed.
PS. I know you've already fixed your problem, but I'm posting this answer in case it can help you, or someone else, in the future.

Why can't I reliably focus a control in Winforms?

I have a form that consists of various controls on the left and the main body is a browser window that displays a HTML file created by the other controls. After generating a file I am attempting to set the focus onto the browser window so the scroll wheel works.
On every ODD attempt this works, on the EVEN attempts it does not.
There are two code paths (both starting from a button click) that generate output, both come down to:
Browser.Focus();
Browser.DocumentText = RenderAsHTML();
The first button updates a listbox on the left also, the second does not. The odd/even pattern is independent of which button was pressed.
What in the world is going on here?
In trying the response below and then throwing things at it I found something very interesting:
The system believes the window IS focused. Browser.Focused returns true even when it's not accepting scroll wheel messages.
To make it even stranger one test I did involved throwing a messagebox in there showing some variables--and when that box was cleared going back to the screen the scroll wheel worked 100% of the time. Removing ONLY the MessageBox.Show line returned it to the old behavior.
on Winforms c# - Set focus to first child control of TabPage will find a similar question, there the best answer says that you have to put
ActiveControl = yourControlThatReceiveFocus;

Graphical hiccups in C# User Control - Resize obscures components

I'm experiencing difficulty with a custom-made User Control, and my searching on Stack Overflow, MSDN, and Google didn't pop up any troubles quite like the one I'm experiencing.
I have a very simple User Control: It's a label, a text box, and a button, with a SaveFileDialog and a FolderSelectDialog available. The text box and button are anchored Left,Right and Right respectively, with the intent that if the control is resized larger, the text box will enlarge to fill the gap, and the button will stay on the right edge of the control.
The problem I am encountering is that when the control is enlarged, the area to the right of the default width of the control becomes blank space when the project is built and run. The pictures here will illustrate what I mean:
In editor:
Running:
The control is smallish in its design window, but when I add it to a form and widen it, it behaves as intended. However, when I run the form the control was added to, half the control isn't visible.
I suspect that I'm overlooking something fairly straightforward, but I wasn't able to find anything addressing this point in my search. Help would be much appreciated.
My guess is that there is a panel or something that is added to your control and will be brought to front somehow runtime.
from property window's top there's a combo from which you can select all the controls in your User Control.
check if all the controls are what you want.
if you find that panel or anything delete it :)
EDIT:
alright this was not your problem.
now I can only assume that you have set some manual sizes to your user control, i.e. in its constructor. in that case designer will show the correct size of you user control,
now some other place in your code, you have set the user controls size manually again. if the layout is suspended and size changes, I think that the anchored controls' size will not change automatically.
if this is your problem, it is probably hard to find.

DrawString over a TextBox [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Watermarked Textbox for Compact Framework
Using Visual Studio 2008 SP1, the latest Compact framework and Windows Mobile 5.
I need to use DrawString to put a string over a TextBox. But as soon as I draw the string the TextBox Control just over writes it. (I Know because I drew slightly off the edge of the control and my text is half visible (where is is off the control) and half gone (where it is on the control.)
Is there anyway I can get the TextBox to not refresh so I can keep my text there?
NOTE: I have looked into subclassing TextBox and just having it paint my text. However, Paint events for the TextBox class are not catchable in the CompactFramework. If you know a way to be able to paint on the TextBox without the Paint events then I would love to subclass the TextBox class.
--End of Question--
Just in case you are wondering why I need to do this, here is what I am working on: I need to have a text box where a numeric value must be entered twice. I need some sort of clear clue that they have to enter the number again. I would like to have a slightly grayed out text appear over the text box telling the user to re-enter.
I have tried using a label, a hyperlink label and another text box, but they obscure the text below (which has a default value that has to be partially visible).
If anyone knows a different way cue for re-entry that would be great too!
Vacano
You can solve this problem in a different fashion. It sounds like you want to silhouette their previous input so they must type it again.
I don't know what strides the CF has made recently but if there is a RichTextBox then this method will work. If not you would have to write your own implementation starting with a base control.
Set the text of the RichTextBox to the silhouette value but make the text color gray for all the characters.
Capture the keypress events and as they press the correct key, change the text color for that character pressed from gray to black and discard that key press, and discard all other key presses.
This solution won't work if you want to allow them to go off the reservation, such as freeform text. Instead of discarding what they typed if they mistype or enter a different character you would not discard the keypress, but blank out the current and remaining gray characters thus allowing them to type with no silhouette.
As I answered in the closed dupe of this:
Where are you doing the DrawText? On the TextBox parent? If so, then that would be expected behavior. Why not create a custom TextBox control that paints (by overriding OnPaint) the value the first time, maybe in something like a light grey, then the second time paints it again in Black?

Categories