ShowBalloonTip Not Working - 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

C# Windows Forms App - Show balloon tip

I try to show a balloon tip like the one in the screenshot:
First I created a notifyIcon
Then I added this code to the Form1_Load function:
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.Visible = true;
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.BalloonTipTitle = "Balloon Tip Title";
notifyIcon1.BalloonTipText = "Balloon Tip Text.";
notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
notifyIcon1.ShowBalloonTip(10000);
}
All I get is a little icon, and If I hover over it then i see the name of the notify icon.
I also tried this notifyIcon1.ShowBalloonTip(10000, "Text", "Title", ToolTipIcon.Warning); but then nothing happens.
I noticed in the function description of ShowBalloonTip, that the parameter "timeout" is deprecated from windows vista on, so what should I do instead?
PS: I run it on windows 10 64bit.
UPDATE 1/3:
I just created a fresh project, the balloon tip does not show either.
Maybe a setting in my OS blocks these messages?
UPDATE 2/3:
I downloaded the project from #pisi1001 but I get the same behaviour.
So I think it must be either a bug in windows 10, a wrong setting or group policy.
However like the next screenshots shows, the app is even allowed to show notifications:
UPDATE 3/3:
I noticed that you can even configure deeper if you double click on the setting, e.g. on "WindowsFormsApp1" from the last screenshot.
After I activated the setting in the red box in the last screenshot (which is basically saying "Show Notifications in the Info Center") I get at least notifications in the info center now:
This must be a Windows 10 Bug.
LAST UPDATE: A few weeks passed since I asked this question, now it seems to work and I am not sure why. Maybe Microsoft fixed it after I reported it to them.

Disabling or removing the close button from uwp app

Universal app does not allow to remove or disable the close button it seems. We can hide it by going full screen. But when moving cursor over it, brings title bar back. Is there any way to remove the close button?
Reason : I am working on screen time. After allowed time gets over, I want to block the screen. I should remove close button so that user cant get over my app.
Edit : Removing close button wont help completely. It is a part of work. I am just asking how to remove it.
In Windows 10 version 1703 (build 10.0.15063) and beyond, you can prevent the app from closing, using the SystemNavigationManagerPreview class.
Add this to your app manifest:
<Capabilities>
<rescap:Capability Name="confirmAppClose" />
</Capabilities
You need to have the rescap namespace at the Package element:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
In the constructor of your main form, add:
var sysNavMgr = SystemNavigationManagerPreview.GetForCurrentView();
sysNavMgr.CloseRequested += OnCloseRequested;
OnCloseRequested can be implemented as follows:
private void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
{
var deferral = e.GetDeferral();
e.Handled = true;
deferral.Complete();
}
With current released API, we are able to customize the color of these three buttons in title bar. But there is no property or method could be used to disable or remove these buttons.
In UWP, we can use ApplicationView.TitleBar | titleBar property to get the title bar like following:
ApplicationViewTitleBar titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;
This property's type is ApplicationViewTitleBar. It only has several properties that can customize the button's color like:
titleBar.ButtonBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonHoverForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonInactiveForegroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedBackgroundColor = Windows.UI.Colors.White;
titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.White;
Using these properties may make the close button invisible like:
However this won't actually hide these buttons. Users can still minimize or maximize the app and when the pointer is over the top right corner, they will still see the close button.
From Windows 8.1, if we want users to use only an application and do nothing else including closing the application, we can use Kiosk Mode. For more info, please see Enable Kiosk Mode in Windows 8.1 and Set up a kiosk on Windows 10 Pro, Enterprise, or Education. However this won't meet your requirement as you want to block the screen after allowed time gets over.
So UWP may not be the best choice for your requirement. You may try to implement it with classic desktop apps.
in App.Xaml.cs add this code :
// Collapse Title bar
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(null);
ApplicationView view = ApplicationView.GetForCurrentView();
view.TryEnterFullScreenMode();
C++ Version
// COLLAPSE THE TITLE BAR
Windows::ApplicationModel::Core::CoreApplication::GetCurrentView()->TitleBar->ExtendViewIntoTitleBar = true;
Window::Current->SetTitleBar(nullptr);
Windows::UI::ViewManagement::ApplicationView^ view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
view->TryEnterFullScreenMode();

How can I disable the virtual keyboard for all my WPF apps?

I saw method to do this for current control but I need to do it for all app. I have touch scren and when i click on some textbox virtual keyboard from windows 7 shown. I don't need it because i how own keyboard in program.
Please help.
Thanks.
Not sure if you got an answer in the few months the question was online, but this worked for me.
First, you need a reference to Microsoft.Ink.dll.
var handle = new WindowInteropHelper(this).Handle;
TextInputPanel panel = new TextInputPanel(handle);
panel.InPlaceVisibleOnFocus = false;
That first line gets a Handle to the window of your app, and then you just need to create the TextInputPanel object and set it's InPlaceVisibleFocus to false. This will no longer show the TIP icon when a textbox is touched.

Hide the taskbar using C#

I am running Windows XP 64 bit. I want to hide the taskbar when I run my application.
I tried codes by searching the web. In all those, it hides the task bar. But the problem is, when i open a notepad and maximize it, it is not actually into full screen. Because the space where task bar was there is still blocked with empty space. I want it fit really into full screen mode.
If you like to replace the windows shell (taskbar) you'll have to change a registry key.
Changing the default shell (all users):
open regedit (start menu > run, and type in regedit)
go to: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon.
Change Shell from explorer.exe to your program path and name e.g. c:\myKioskApp\Kiosk.exe
Changing the default shell (only current user):
open regedit (start menu > run, and type in regedit).
go to: HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon.
add a new string value (Edit > New > String Value) called shell. and set the value to the path of the new shell e.g. c:\myKioskApp\Kiosk.exe
log out and log back in.
I've done this by making the application borderless, maximized, and setting it to be Topmost. Here's a perfect example from CodeProject.
As one of the commenters has said, replacing disabling Explorer and running your application might be the best way, security-wise.
You Can Hide your task bar by setting Following Properties of your C# Form.
WindowState : Maximized
FormBorderStyle : FixedDialog
on window 7 (or maybe higher) using FormWindowState.Maximized is wrong because the maximum size will be subtracted by Taskbar height but you can do this
this.WindowState = FormWindowState.Normal; // or default
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
// do it here
this.Location = new Point(0,0);
var fullscreenSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
this.Size = fullscreenSize;

How to set NotifyIcon behavior to AlwaysShow in C#?

Is it possible to modify NotifyIcon behavior to AlwaysShow in C#? A code snippet would be greatly appreciated:) Thanks in advance...
Cheers
---edited
One of our clients said quote "it seems necessary to customise icons to always show". What he meant was that he has to do it manually by r-clicking on task bar then click on Properties -> Task Bar -> Customize Notifications and then you can set behavior to Always Show / Always Hide / Hide when inactive for each taskbar icon on the list.
Can you do that programically in C#?
I want to ensure that my NotifyIcon is ALWAYS visible. I'm already setting icon.Visible = true but it looks like it doesn't work for him hence the complaint.
Is there any easy way of setting the behavior by altering [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify] IconsStream registry value?
NotifyIcon icon = ...;
icon.Visible = true;
Edit for updated information: There shouldn't be, and if for some reason it exists, don't use it. That's the user's preference, not yours.
I'm sure it's possible with enough Registry hacking, but not at all recommended. They added the collapsing-notification-area behavior in XP because so many applications were shoving themselves in that space. Much like Start Menu pinning behavior in XP/Vista/7, the lack of a public API means you're supposed to let the user decide that sort of thing.

Categories

Resources