what does SychronizedInputPattern do in UI-Automation? - c#

Could some one explain what the SychronizedInputPattern does? I haven't been able to find any good examples of it being used.

Lets suppose you need to click something but before the click happens, the elements move (maybe due to resize …). In this case, some other element could get the mouse input.
To overcome this problem, SynchronizedInputPattern has been introduced.
buttonElement.GetCurrentPropertyValue(AutomationElement.IsSynchronizedInputPatternAvailableProperty);
Read more over here.. Example can be downloaded here.

Related

Programmatically select DrawingObject in HWindowControlWPF

I'd like to select a created DrawingObject to highlight it and show the handles without the user needing to click it. I am using Halcon 13 and tried using SendMouseDoubleClickEvent() (Docu) but this only seems to be available for the new Halcon Smart Window, which is currently not an option for me as it interacts differently with the Halcon-Procedures. I also tried to use SelectObj() (Docu) but this seems to do something entirely different.
I have:
a reference to the HWindowControlWPF
the ID of the HWindowControlWPF
the ID of the DrawingObject
Any help or hint is appreciated!
I could not find a proper solution to this problem but I found a hack that achieves the same result:
First, detach all drawing objects apart from the one you want to show as selected via DetachDrawingObjectFromWindow. Then, reattach them via AtachDrawingObjectFromWindow.
This works because the Halcon Window automatically selects the last attached drawing object.

How do I show/activate the text cursor in open document? [C#, EnvDTE]

I'm trying to set the cursor in an open document, but it doesn't show. I can see that the line is "marked" and I can "navigate" the lines, but the cursor is not shown, and thus I'm not able to write anything. Also it seems like the document doesn't really fully load, since guidelines and the navigationmap is not shown either.
Which makes me believe that the focus isn't being set completely inside the document.
I have confirmed that the focus indeed is not set in the document in the window, since If I have the output window focused before, it's still focused after the window.Activate() method has been called.
I've used the common way of opening the document through ProjectItem.Open(Constants.vsViewKindCode), activating it, and using the TextSelection.GotoLine(1,false) method.
This correctly shows the document and sets the line correctly, but I have to manually click inside the document for the cursor to appear.
The code I have:
Window window = projItem.Open(Constants.vsViewKindCode);
window.Activate(); <----- this does not focus the window.
TextSelection textSelection = window.Document.Selection as TextSelection;
textSelection.GotoLine(1, false);
I want to not have to manually click inside the document for it to load completely and for me to be able to write in it.
Hope someone can help me.
Oh well, another issue I had to solve by myself... Two for two. I guess people don't know that much in here like I'd hoped. Oh well.
Anywho, I discovered that if you use DTE.ItemOperations.OpenFile(path); and nothing else,
the file will receive focus correctly, just like it should have when you use .Activate().

Why is this WinForm in execution so different from its design?

I have a simple WinForm whose only function is to display a message passed to it. The message is passed as a string and is displayed in a textbox. It is set to be a FixedToolWindow (and no matter how else I set it I get the same behavior in the end).
The form is called with:
PswCoordFailDisplay coord1 = new PswCoordFailDisplay(inputString);
coord1.Show();
Here are two screenshots: top is of the designer; bottom is how it is actually painted.
This is part of a fairly complicated application with about 10 other WinForms. They all act like they're supposed to, except this one.
The changes from design are:
the Form's dimensions change
the textbox changes to occupy the entire width of the form (possibly in response to the size of the text that fills it -- although ScrollBars is set to Both)
the Close button changes its text to "OK" and migrates to the bottom right
the form's Title is gone
the X-closer is different
when I turn ControlBox to False, the X-closer appears regardless, and in the same form as in the bottom example
I pretty much take all the defaults that a WinForm provides when creating the WinForm, except for a couple of items that shouldn't make this kind of difference.
What on earth is happening? I mean, it still works fine, but it's not what the design calls for!
If you pay close attention to the pictured screenshots presented in the question, you will notice that the bottom one shows a MessageBox, not the intended WinForm. As commenters T McKeown and Grant Winney pointed out, there is no way for the elements of the form to go that far off the rails unless the form was coded that way. Since it wasn't coded that way, the expected form is NOT being called. There is a very superficial resemblance, of course, which accounted for my confusion.
If I had showed the complete calling code, a sharp eye would have seen this quickly:
switch (opRes.OpResult)
{
case OperationResult.Result.Succeeded :
MessageBox.Show("Password coordination succeeded.");
LoadUser();
break;
case OperationResult.Result.PartialSuccess :
MessageBox.Show(String.Format("Password coordination partially succeeded: {0}{1}", Environment.NewLine, opRes.Notation));
LoadUser();
break;
default :
MessageBox.Show("Password coordination failed.");
PswCoordFailDisplay coord1 = new PswCoordFailDisplay(opRes.Notation);
coord1.Show();
break;
}
As you can clearly see, with a "partial success" control would be passed to the second case in the switch statement, not the default. The second case was supposed to be coded with the new WinForm, but I forgot to do it! And so there you see the problem:
READ YOUR DARNED CODE BEFORE POSTING YOUR PROBLEM ON STACKOVERFLOW!
Less embarrassment that way.
ETA: Also, if I had posted the above code in my question, as #Rockster suggested, someone would have noticed it immediately, perhaps saving a step or two.

How can I create a Delphi TSpeedButton or SpeedButton in C# 2.0?

How can I create a Delphi TSpeedButton or SpeedButton in C# 2.0?
Using a Button and setting the TabStop property to false only works when tapping through the form...
If you need (as I did) a button that does not get selected when clicking on it, there is only one way I have found to do it.
The way I did it, was to subclass the Button class and in the constructor calling the SetStyles and thereby setting Selectable to false, like so:
public class ButtonNoFocus : Button
{
public ButtonNoFocus()
: base()
{
base.SetStyle(ControlStyles.Selectable, false);
}
}
This worked out for me, and is perfect if you e.g. have a control-panel with buttons that perform actions to a selected object...
I'm wondering if you want to create a control like a TSpeedButton, or you just need same kind of end result ...
Programming one from scratch is certainly possible, but I'd only tackle that as a learning exercise.
Assuming you want to achieve a similar end result ...
Delphi's TSpeedButton had a differences from the standard TButton that developers found useful - it was flat, didn't take focus, and it consumed fewer resources than a regular button (because it didn't have an underlying Windows Handle).
Which of these are important to you?
If you just want a flat button that doesn't accept focus, use a regular Button with FlatStyle=Flat (or PopUp) and TabStop=false. You can configure a glyph by setting either the Image property, or a combination of ImageList and ImageIndex/ImageKey.
An alternative to this would be to look for an existing button component that comes close to your needs - one place to look might be the Krypton Toolkit (free to use, see http://www.componentfactory.com/toolkit_buttoncontrols.php).
If you're wanting to reduce the number of resources consumed by your application, it's likely you'll get a better return looking elsewhere.
Back in the days of Windows 3.1 (Delphi 1) and Windows 95 (Delphi 2), the number of available handles was strictly limited, with a maximum number available system wide. Today, with Windows XP and Vista, the number of available handles is far far higher, and the number is per process, not system wide. Unless you're creating thousands upon thousands of buttons, you're very unlikely to come anywhere close to running out.
Does this help? Looks like you would have to handle the OnPaint event, and not take focus...
The regular .net 2.0 button supports part of what a TSpeedbutton Does:
The Glyph: Image
Flat : FlatStyle
It does not handle:
Down
Group
These two are related, you could inherit from the button, and ownerdraw it, adding Down and Group features.
Codeproject has an example of ownerdraw buttons.

Shape of a Winforms MessageBox

I am looking for a way to have some control over the shape of a simple MessageBox in Winforms. I would like to control where the passed in text wraps so that the dialog rect is narrower. Windows seems to want to make the dialog as wide as possible before wrapping the text. Is there an easy way to control the maximum width of the dialog without resorting to creating my own custom form?
You can embed newlines in the text to force it to wrap at a certain point. e.g.
"message text...\nmore text..."
update: I posted that thinking it was a win32 API question, but I think the principle should still apply. I assume WinForms eventually calls MessageBox().
There's really just two ways (sane ways)
1) Add line breaks to your string yourself to limit the lenghth of each line.
2) Make your own form and use it rather than messagebox.
What happens if you throw your own newlines in the string message you pass it? I'm pretty sure that will work if I recall correctly.
This, or alternatively create your own form and use that.
The \n newline chars will give you enough flexibility, then do this. I use this a lot. Eg. if I'm giving a warning, the first line will give the warning, and the next line will give the internal error message or further information as appropriate. If you don't do this, you end up with a very wide message box with very little height!
MessageBox only has limited variability - eg. the button types and icon. If you need more, then create your own. You could then do all sorts of things like add URLs, a Help button ,etc.

Categories

Resources