How to focus window after show? - windows

I have window with global shortcut registered:
RegisterHotKey(SHOWHIDE_HOTKEY, wxMOD_CONTROL, VK_OEM_3);
with it's handle looking like this:
if (IsShown()) {
Hide();
} else {
Show();
SetFocus();
}
The hiding/showing of the window works fine, the focus part doesn't. Any ideas how can I achieve it?

Related

Change background color (of entire view) on button click in Xamarin

I'm using iOS/Xamarin
When the user clicks a button, I'd like to change the background color of my view controller's main view (View).
In the button click event, I tried this:
partial void MyButton_TouchUpInside(UIButton sender)
{
InvokeOnMainThread(() =>
{
SetBackgroundColor(View);
});
}
but it doesn't work. I tried a few other main thread/uithread things but no luck.
If I call SetBackgroundColor(View) from the ViewDidLoad of course it works. I suspect this is a UI thread issue.
Any advice?
Thanks!
You can use the BackgroundColor property on the UIViewController's View property.
partial void MyButton_TouchUpInside(UIButton sender)
{
View.BackgroundColor = UIColor.Red;
}
Turns out the above code is good - somewhere else in the code someone was setting another layer on top of the background so I never saw it =/

How to stop NSPanel from stealing input of another app

I have an NSPanel. It's purpose is to sit on top of everything in all spaces and it does that just fine.
I don't want it to ever become firstResponder and take focus from another app.
I sub classed NSPanel like so
class SomePanelClass: NSPanel {
override var acceptsFirstResponder: Bool{
return false
}
}
When the window shows or I drag it around the app I was in still appears to have focus and it's name is in the menu but keystrokes do not register in that app until I click back into it's window.
Is there something else I can do to prevent my app and panel from stealing input?
You probably want to override canBecomeKeyWindow on your Panel subclass to return NO.
- (BOOL) canBecomeKeyWindow {
return NO;
}

I need assistance with xcode buttons

So I'm trying to make an event happen with buttons in xcode, and it's working fine, and executing the way I want it to, but now I want a different section of code to run if the button is not being pushed. I don't know how to test for if a button is NOT being pushed. Any ideas?
While a NSButton is pressed its state is non-zero.
if (myButton.state) {
// My button is pushed!
}
Here's something that can help you. Define a var ,notPushed whose value can be checked to see if button is called or not.
var notPushed:Bool=true
#IBAction func buttonPressed(sender:UIButton)
{
//....
notPushed=false
}
To check wether the button is pressed :
if notPushed==true{
//...
} else {
//...
}
Link your button to the buttonPressed.

how to write a toggle method to open/close a window?

I have an NSPanel window in my app that I want to toggle open and close with a button on the toolbar. This seems like a fairly basic operation, and indeed one I see in many apps (like Inspector views). However, I'm struggling to find the right way to do this.
I've looked at the performClose: and the makeKeyAndOrderFront: methods, but I can't work out how to make them work in my method. Basically, I want something like this
-(IBAction)togglePanel:(id)sender {
if ( ) //what do i put here to assess if _myPanel is already open?
// tell _myPanel to close
else {
//tell _myPanel to open
}
}
Answering my own question, here. But got what I wanted thus:
- (IBAction)togglePanel:(id)sender {
if (_myPanel.isVisible == 0)
[_myPanel makeKeyAndOrderFront:self];
else {
[_myPanel performClose:self];
}
}

How to handle back button in windows phone 7?

I have an application, the main page contains few functions. To explain in detail - I have save, color palette button in my main page. When any of these buttons are clicked, save pop up or color palette appears. How to handle back button of the device, when color palette or save pop up is opened. When back button is pressed at these scenario it should just make them invisible and stay on the main page. When nothing is being performed in the main page, then it should come out of the app. I tried to make their visibility collapsed on back button press. But it still is coming out of the application.
Please, guide me in this. Thanks in advance.
Override PhoneApplicationPage.OnBackKeyPress and then set CancelEventArgs.Cancel to true if you want to stop it from actually going back.
protected override void OnBackKeyPress(CancelEventArgs args)
{
if (PanelIsShowing)
{
HidePanel();
args.Cancel = true;
}
}
The back button behaves as is intended by Microsoft.
If you change its behavior you risk your application not being certified for the Marketplace.
If you want the back button to close the popups, turn the popups into pages so the back button navigates back to the main page..
You need to use
protected override void OnBackKeyPress(CancelEventArgs e)
{
if (_popup.IsOpen)
{
_popup.IsOpen= false;
e.Cancel = true;
}
else
{
base.OnBackKeyPress(e);
}
}
That should do the trick.

Resources