Reputation: 309
I'm trying to make a simple app showing reminder (just a text label) in the middle of the screen. How to show this outside of a window? I'm trying to get main window with settings minimised, while the label shows up in the middle of a screen at specific time. I'm trying to achieve this in WPF, but if that's not possible I'll move to Winforms.
EDIT:
I'll make the window transparent with the technique from here: How to create a semi transparent window in WPF that allows mouse events to pass through but how to hide any signs of a window, and make just the label visible?
Upvotes: 0
Views: 296
Reputation: 570
Short answer: you can't show a control outside of a window. Every control needs to be parented to some window. That window might not have any borders or title bar, but you can't display a control without a window.
For a notification, you need to create a new window that is separate from your application's main window to display the label in. You can then show and hide this window whenever you want to display the notification, even if your main window is hidden.
Upvotes: 0
Reputation: 169420
Instead of trying to show something "outside of a window", you could display the label in a transparent invisible window that you bring up by calling the Show()
method:
private void Button_Click(object sender, RoutedEventArgs e)
{
Window window = new Window();
window.WindowStyle = WindowStyle.None;
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.AllowsTransparency = true;
window.Background = Brushes.Transparent;
window.SizeToContent = SizeToContent.WidthAndHeight;
window.ShowInTaskbar = false;
window.Content = new TextBlock() { Text = "Floating...", FontSize = 20, Foreground = Brushes.Red };
window.Show();
}
You can minimize the main window without affecting the floating label and the invisible window won't get a taskbar button provided that you set the ShowInTaskbar
property to false
.
Upvotes: 1