I'm building a GUI for a powershell script. It's a form built in Powershell studio.
I have this code which works well:
(Get-Content ".\historique.txt") | ? { $_.trim() -ne "" } | set-content ".\historique.txt"
$postes_historique = Get-Content ".\historique.txt"
$textboxPoste.AutoCompleteCustomSource.AddRange($postes_historique)
It takes what is in the "historique.txt" text file and suggests autocomplete values for the textbox like this:
On that texbox, i have a KEYDOWN event set up so when a user presses ENTER it clicks the button below the textbox:
$textboxPoste_KeyDown = [System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
if ($_.KeyCode -eq 'Enter')
{
$buttonConnexion.PerformClick()
}
}
The strange part and my question is :
-If I click a value in the dropdown, it clicks the button. (UNWANTED BEHAVIOR)
-If I REMOVE that KeyDown enter event, it DOESN'T click the button. (Wanted behavior)
That seems very strange to me, it's as if when you click a dropdown value, the code understands it like "YOU PRESSED ENTER". What kind of weird correlation is that? I want to have both, which is being able to press down enter to click the button AND being able to choose an autocomplete value without it triggering a button click...Doesn't seem like too much to ask, no?
Thank you for your time.
Not sure if there is another solution but the work around in this case is :
REMOVE the keydown event that clicks the button when ENTER is pressed
and
REPLACE it by setting the form's AcceptButton to your button. This way when user presses ENTER, that button is triggered and the autocomplete dropdown acts as expected.
Related
I'm making a GUI and I need a button, that doesn't close the window on click.
Just copying from some of my other code for button creation, which works fine, but closes the window, on click. I need something that doesn't close the window, when clicked.
$apply = New-Object System.Windows.Forms.Button
$apply.Location = New-Object System.Drawing.Point(150, 120)
$apply.Size = New-Object System.Drawing.Size(50, 22)
$apply.Text = "Apply"
# $apply.DialogResult = [System.Windows.Forms.DialogResult]::
I'm making a GUI and I need a button, that doesn't close the window on click, like an apply button, does.
A button in a GUI with text Apply usually means some setting is performed without closing the window.
You just need to add an Click event handler to the button like:
$apply.Add_Click(
{
# here you do whatever the Apply is meant for
}
)
Another button called OK is usually also present which also applies whatever is was, but does close the form.
I have a script which filters an excel sheet (schedule) and displays the result through Out-Gridview. When the user clicks "Cancel" it opens the excel sheet after closing the Out-Gridview. When the user clicks "Ok" it only closes the Out-Gridview. But these actions are not visible for the user. So can i rename the "Ok" and "Cancel" button of Out-Gridview to lets say "Close Schedule" and "Open Excelsheet"?
And also, is it possible to run the rest of the script without waiting for the response, but keep the buttons working?
I know that if i don't use an output mode the rest of the script runs without waiting, but with outputmode (which gives me buttons) it waits for the response.
I use this code to filter a schedule and it would be nice if i can use the rest of the program without shutting down the rest of the program, maybe by starting another instance of powershell or something?
$Schedule = $ResultsTable | Out-Gridview -OutputMode Single -Title "Schedule"
if ($Schedule -eq $Null) {
Start-Process "$Fileserver\Logistics_share\Planning_Alg\TS Delivery schedule rev2.0.xlsx"
}
If it can be done with only a visual overlay, it is ok by me (Buttons)
I have created an OpenOffice Calc spreadsheet and I have inserted a button into it. I can successfully call a macro with the button. I want to have a cursor hand when I mouse-over the button.
First, I switched to 'Design' mode, then I right-clicked on my button, and using the pop-up menu which appears, I selected the 'Events' tab. Then I clicked on the 'Mouse inside' dot dot dot button. In the 'Assign action' window that popped up, I clicked on the 'Macro..' button. I then got the 'Macro Selector' pop-up window, where I choose the 'OpenOffice Macros' folder in the left side pane. I expanded 'Tools'>'ModuleControls' from that 'Library' pane and then selected 'SwitchMousePointer' from the right side 'Macro name' pane, then clicked the 'Ok' 'Ok' buttons.
But now when I hover the mouse cursor over my button I get an OpenOffice Error window popping up "A Scripting Framework error occurred while running the Basic script Tools.ModuleControls.SwitchMousePointer."
I've very little OO experience but I have not found what I want here or on the OO Forum site. I would be very grateful to get some help, thanks, Nige.
The SwitchMousePointer needs attributes (oWindowPeer as Object, bDoEnable as Boolean). So you can't simply assign it to a event. And it will not do what you think.
You should better write you own Sub to change the Pointer. Also there is no need to do this on every mouse event. It should be done once on sheet activate for example.
For a introduce in OpenOffice.org BASIC Programming see https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide. And you will need a debugging tool, if you want to program your own BASIC macros. Therefore see especially: https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/UNO_Tools
Assuming on the sheet is a button named "Push Button 1" then:
Sub ChangeMousePointer
oController = ThisComponent.CurrentController
oButtonModel = oController.ActiveSheet.DrawPage.Forms(0).getByName("Push Button 1")
oButtonControl = oController.getControl(oButtonModel)
oWindowPointer = CreateUnoService("com.sun.star.awt.Pointer")
oWindowPointer.SetType(com.sun.star.awt.SystemPointer.HAND)
oButtonControl.Peer.setPointer(oWindowPointer)
End Sub
And assign this to the sheet event Activate Document.
Right click the sheet tab and select Sheet Events from the context menu. Then:
If, and only if, the button is on Sheets(0) then the sheet event Activate Document not occurs while opening the document and this sheet is in front. In this case we have to call the Sub ChangeMousePointer also on document event Open Document.
Sub Document_Open
oController = ThisComponent.CurrentController
oSheet = oController.ActiveSheet
if oSheet.Name = ThisComponent.Sheets(0).Name then
if oController.ActiveSheet.DrawPage.Forms.Count > 0 then
if oController.ActiveSheet.DrawPage.Forms(0).hasByName("Push Button 1") then
call ChangeMousePointer
end if
end if
end if
End Sub
To assign the macro to the document event Open Document select Tools - Customize from the menu and:
Going "back" from a form doesn't take me to the previous form but back to the main form. What am I doing wrong? Here's more detail:
I have a Command that takes you from the main form of my app to a "human setup" form. From that form if you click on a certain multibutton I go to another form (MaintenanceLevel) like this:
protected void onHumanSetup_MultiButtonMaintenanceAction(Component c, ActionEvent event) {
// Invoke the next level of form
showForm("MaintenanceLevel", null);
}
In the "MaintenanceLevel" form I have an Action set to Back, but when I click the menu bar to go back I end up back on the main-form and not the "human setup" where I want to be.
Edit:
Things have got a little worse!! Now when I go back in to view the Commands for my MaintenanceLevel form it's empty: it's forgetting the command I've entered :(
Here is my command setting for MaintenanceLevel form:
You don't need to define a back command. Remove it. Codename One automatically creates back commands for you.
The usage for this option is when you create a Button and place it within the form, then you want it to behave as a back button effectively (e.g. cancel button).
I have a button in a group widget and i simply want to create a keyboard shortcut(enter) so that the button action gets called and focused.Interestingly what happened is when i press space(on keyboard)the respective button action gets called which doesn't work with enter.Eventually all I'm trying to get is simply press enter so that button action triggers.Any ideas so that i can play-around it.
The Enter key (SWT.CR) does not invoke the current button, but rather the default button of the Shell. You set the default button with
shell.setDefaultButton(button);
Maybe what you're searching for is the method #addKeyListener of class Button. Implement a KeyListener and in the #keyReleased(KeyEvent keyEvent) method evaluate keyEvent like this: if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { //your code here}