C# NotifyIcon tooltip not showing (Windows 10) [duplicate] - c#

On Windows 10, the ShowBalloonTip method of NotifyIcon NEVER shows the balloon tip. This would appear to have something to do with Windows itself.
If I go to Settings > System > Notifications & actions > and find my running app (vshost32.exe in debug mode) and click on it, then turn on Show notifications in the action center, I can clearly see the balloon tip messages being added to the notifications, but never a balloon tip.
I assume this is a problem with Windows 10.
My NotifyIcon is VISIBLE
my_icon.ShowBalloonTip("Title", "Message", BalloonIcon.Info);

On my computer with Windows 10 version 1803, go to Settings > System > Notifications & actions, and turn on "Get notifications from apps and other senders".
The ballontips from my WPF app will show up.

Found the problem - was simple: Quiet Hours was turned on in the notification center and this was preventing the balloon tips.

Turn off Focus Assist. If you are using second screen, turn off "When I'm duplicating my display" option. My settings is like that:

I've fixed the problem by adding icon property. If this property isn't set, the baloontip won`t be shown. Here's example of my code:
var notify = new NotifyIcon();
notify.Visible = true;
notify.Icon = new System.Drawing.Icon(#"D:\Users\User\Desktop\some.ico");
int code = new Random().Next(1000, 9999);
notify.ShowBalloonTip(500, "code", $"{code}", ToolTipIcon.Info);

Neither of these solved my issue :(
But by accident I fixed it! My problem was I had my project configured for 32-bit on a 64-bit platform and for whatever reason they only show up when when I run the project for Any CPU (64-bit in this case)!!
Hopefully that helps some of you, it was a real mystery for me...
(I also posted this answer here because these are duplicate questions)

Change the Solution Configuration "Debug mode to Release mode" with X64 or X32 Solution platform. It will start work.
public static NotifyIcon trayIcon;
trayIcon = new NotifyIcon();
trayIcon.Icon = new Icon("Images/Test.ico");
trayIcon.Visible = true; trayIcon.Text=Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName);
ContextMenu contextMenu1 = new ContextMenu();
contextMenu1.MenuItems.Add("Menu2", Menu2_Event);
contextMenu1.MenuItems.Add("Menu3", Menu3_event);
contextMenu1.MenuItems.Add("Exit", Close_Click);
trayIcon.ContextMenu = contextMenu1;
trayIcon.BalloonTipText = "Hi Test";
trayIcon.ShowBalloonTip(1000);

Just for reference, as #rmirabelle wrote in the question "My NotifyIcon is VISIBLE". This is actually important.
If the notification icon is not visible in the systray, the BalloonTips won't show up either.
Possible sources for invisibility are:
Visible property = false
No icon is set for the NotifyIcon object

Related

Keyboard not showing when being prompted by UITextField

In iOS 13.2, I'm noticing that my keyboard no longer shows up in my apps on the simulator and a real device. When I tap inside a UITextField, nothing happens but the cursor blinking inside the textfield. Is anyone else having this problem or know how to solve?
UPDATE
The problem originates from removing storyboard files and initiating a rootViewController programmatically
var windowScene = new UIWindowScene(session, connectionOptions);
Window = new UIWindow(windowScene);
Window.RootViewController = new ViewController();
Window.MakeKeyAndVisible();
After that, I just noticed the keyboard doesn't show again in a new project.
This looks like a bug when you try use a programatic approach to setting a rootViewController in the new SceneDelegate opposed to how we used to in AppDelegate.
I got around this by keeping the dumb storyboard which sets the rootViewController inside and keeping SceneDelegate.cs clean for the moment and my keyboard works again. Thanks for all your answers.
set textfiled delegate.
#IBOutlet weak var urlTextField: UITextField!
override func viewDidLoad() {
self.urlTextField.delegate = self // urlTextField it is your textfield outlet
}
If you delete this line of code, the keyboard does not appear, but if this exists, the keyboard does come up.
About simulator : You can check setting in iOS simulator firsrt .
Have a look at this screenshot ,be sure Use Hardware Keyboard not be selected . Or you can select it and unselect it again , then keyboard will show.
Restart app to check whether keyboard can be shown.

c# exe encapsulation in wpf not work

I need to encapsulate exe on my wpf application.
My wpf application is very large and with many UserControls.
To do this, i've start the exe from my code, then get the handle and used the "setParent" to "bind" the exe to my application, but the only effect is to show the drop down menu of the exe, but not the main page. For example: i've tried to embedded notepad, but appear only the drop down menu when I click in the area (note that not appear the main menu bar).
var procInfo = new System.Diagnostics.ProcessStartInfo(this.exeName);
procInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(this.exeName);
// Start the process
_childp = System.Diagnostics.Process.Start(procInfo);
// Wait for process to be created and enter idle condition
_childp.WaitForInputIdle();
// Get the main handle
_appWin = _childp.MainWindowHandle;
// Get main window handle
var helper = new WindowInteropHelper(Window.GetWindow(this.AppContainer));
// Incapsulate
SetWindowLongA(_appWin, -20, 0x00000040 | 0x00000008);
SetParent(_appWin, helper.Handle);
Note that I've tried this piece of code in other c# application and work fine!
I think there is a problem of redraw/update the viewport.
In which way can i force this redraw of the external exe inside my application?
Can you help me, even to found an alternative solution to embedded the exe? Thanks
I've tried the solution to run the exe in a separate tab (here), but even this solution not work.
Can I resolve this with a "SendMessage" ???
Can you suggest me a test to do?
I ask you one thing: help me!!!
The below works for me, can provide you with example project if necessary. The missing piece seems to be that either you have a z index issue OR your initial window placement in your desktop co-oridinates is such that is it outside your 'outer window'.
this will bring it the the from and make it FILL your window:
SetWindowPos(_appWin, default(IntPtr), 0, 0, (int)Application.Current.MainWindow.Width, (int)Application.Current.MainWindow.Height, SetWindowPosFlags.FrameChanged);
The default(IntPtr) is for the ZIndex and says 'bring to front'
You can then make that smaller by passing in the offsets from your containing control, ie if this.grid was what you wanted notepad to appear over:
var desiredPos = this.grid.TranslatePoint(new Point(0, 0), Window.GetWindow(this.grid));
SetWindowPos(_appWin, default(IntPtr),
(int)desiredPos.X, (int)desiredPos.Y,
(int)this.grid.ActualWidth, (int)this.grid.ActualHeight, SetWindowPosFlags.FrameChanged);
Using AllowsTransparency="False" instead AllowsTransparency="True" inside the WPF of the Window I've been able to solve partially the problem
Now I've embedded the external exe (for example: "notepad.exe") using this approach (WindowsFormHost approach):
System.Windows.Forms.Panel _pnlSched = new System.Windows.Forms.Panel();
System.Windows.Forms.Integration.WindowsFormsHost windowsFormsHost1 =
new System.Windows.Forms.Integration.WindowsFormsHost();
windowsFormsHost1.Child = _pnlSched;
_grid.Children.Add(windowsFormsHost1);
ProcessStartInfo psi = new ProcessStartInfo(#"notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Normal;
Process PR = Process.Start(psi);
PR.WaitForInputIdle();
SetParent(PR.MainWindowHandle, _pnlSched.Handle);
Now the new problem may be the Z-order of the user control. In fact, when another user contol move above the "notepad", it is below and not above...
enter image description here
Note that also the background of the WindowsFormHost not respect the 'z-order':
enter image description here
any suggestion is welcome
Thanks

How to Always show my app icon in System Tray using C# in windows application

I have and windows app and I want that my app icon will always show in system tray. As now it will hide after time. Please help me to solve my problem. Thanks in advance.
Code of System tray App:
NotifyIcon ni = new NotifyIcon();
// Put the icon in the system tray and allow it react to mouse clicks.
ni.MouseClick += new MouseEventHandler(ni_MouseClick);
ni.Icon = Resources.favicon;
ni.Text = "***";
ni.Visible = true;
// Attach a context menu.
ni.ContextMenuStrip = new ContextMenus().Create(ni);
ni.BalloonTipText = "abc...";
ni.BalloonTipTitle = "abc";
ni.ShowBalloonTip(5000);
I guessing a little, but I think the issue is that the user has chosen a UI option that hides notification icons to avoid the notification area taking over the taskbar.
There is no supported way for you the programmer to indicate that your notification icon is so important that it must show all the time irrespective of the wishes of the user. The user gets the opportunity to indicate that certain icons are always to be shown. Right click in the notification area and select Customize notification icons. This allows the user to decide which icons are always visible.
So, you the programmer do nothing. You let the user make the choice.

Tooltip in c# form does not appear when switching computers

Hi I am having a very strange problem. I have a form with multiple tooltips that appear when the mouse is over a specific control. So far I was developing the form on a Windows 7 machine and everything were going fine. Tonight I tested my executable on my other Windows 7 machine (same version and service pack) but none of the tooltips are working.
Does anybody have an idea what might be the problem? Bellow I am giving the code for one such Tooltip
ToolTip UrlNameInputBallonTip = new ToolTip();
private void CheckForUrl()
{
UrlNameInputBallonTip.IsBalloon = true;
if (IsValidHttpUri(UrlNameInput.Text) == false && IsValidHttpsUri(UrlNameInput.Text) == false)
{
UrlNameInputBallonTip.SetToolTip(UrlNameInput, "This is not a valid url!\r\nex. \"http://domain\"");
UrlNameInputBallonTip.Show("This is not a valid url!\r\nex. \"http://domain\"", UrlNameInput, UrlNameInput.Width / 2, UrlNameInput.Height, 5000);
}
else
{
UrlNameInputBallonTip.Hide(this);
}
}
Hi I was able to find the cause of the problem and I am reporting this for future reference. On the suspected machine the option to display balloon tips (arrow pointing to the control) was disabled. I am not sure why, perhaps some other app disable it at some point, but after enabling it through registry ti works fine now. Thanks for the help!

How do I make a tray-icon-only C# application in MonoMac (no dock icon)?

I am trying to create an application that will have a tray icon only, and not appear in the taskbar. (similar to Dropbox) I need to create both Windows and Mac version of the application, so I tried using MonoMac to create the Mac front-end.
What is the best way to create a tray-only application in MonoMac?
All the resources I have found say to do one of two things:
Add <key>LSUIElement</key><string>1</string> to the Info.plist file.
Add the following code to the FinishedLaunching event in the AppDelegate class: NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Accessory;
I have tried all combinations of these two, but it seems that as soon as I try to instantiate a C# System.Timers.Timer, the icon reappears in the dock at the bottom of the screen. Am I missing something about how OSX handles background applications?
What am I doing wrong? Is there a better way to make a background application that has an upper tray icon but no bottom dock icon in OSX?
(This is very similar to this SO question, but that question was from a couple years ago and was never fully answered, so I'm hoping there might be a more complete answer out there.)
Here's the code I have so far:
public partial class AppDelegate : NSApplicationDelegate
{
MyServiceObject currentServiceObject;
public AppDelegate () { }
public override void FinishedLaunching (NSObject notification)
{
// Construct menu that will be displayed when tray icon is clicked
var notifyMenu = new NSMenu();
var exitMenuItem = new NSMenuItem("Quit My Application",
(a,b) => { System.Environment.Exit(0); }); // Just add 'Quit' command
notifyMenu.AddItem(exitMenuItem);
// Display tray icon in upper-right-hand corner of the screen
var sItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
sItem.Menu = notifyMenu;
sItem.Image = NSImage.FromStream(System.IO.File.OpenRead(
NSBundle.MainBundle.ResourcePath + #"/notify-icon.icns"));
sItem.HighlightMode = true;
// Remove the system tray icon from upper-right hand corner of the screen
// (works without adjusting the LSUIElement setting in Info.plist)
NSApplication.SharedApplication.ActivationPolicy =
NSApplicationActivationPolicy.Accessory;
// Start running the program -- If I comment out then no dock icon appears
currentServiceObject = new MyServiceObject();
}
}
I found the problem, and it wasn't related to the application settings at all. Evidently, there are some operations that MacOS does not allow an 'Agent applications' to perform. As soon as one of those methods is called, the application is forced to appear in the dock. The code that was tripping up my application was a call to:
System.Windows.Forms.Cursor.Position.ToString()
Removing that line, and replacing it with the following MonoMac method allowed the application to remain hidden:
NSEvent.CurrentMouseLocation.ToString()
I was able to get this working by setting the value of "Application is agent (UIElement)" key to 1 in the info.plist file. Even though it should be a BOOL value, MonoDevelop makes it a string, but setting it to 1 seems to work. You can also set an empty string the for the "Icon file" but it's not necessary.

Categories