Make Notifyicon Appear on the MDIParent - c#

In my Application I had a Main Menu Which is the MDIParent It has a menustrip in top to navigate to different forms and a panel in the bottom which contains a labelcontrol used to dispaly error messages and status.
My requirement is when there is any pending jobs left for the user ( it will be optained by a select query) I want to show a pop up like "You have pending jobs ", I wish to use a notify icon for that .
But my problem is the notify icon is always apperaing in the start bar of my Pc not on my application mdiparent
Can anyone suggest any remedy for that or any better ideas

I wish to use a notify icon for that
Use a ToolTip class:
var toolTip = new ToolTip
{
IsBalloon = true,
ToolTipIcon = ToolTipIcon.Info,
ToolTipTitle = "Pending jobs"
};
// 'this' means form
toolTip.Show("You have pending jobs", this, yourMdiParent.Location);

Related

how to make wpfapp always on top and not blocked by taskbar

I used a wpf and set Topmost=true, this works for other applications but I want to put the form in taskbar, when the task bar get focus, the form is blocked.
I want to know if there is any method to make the form always on top?
enter image description here
enter image description here
Another question is that I want to add some buttons on taskbar so that I can click them easily, but I only found trayIcon which is limited in functions.
YourCustomWindow cw = new YourCustomWindow ();
cw.Owner = Application.Current.MainWindow;
cw.ShowInTaskbar = false;
cw.ShowDialog() ;

WPF setting the owner of a window to its parent window MVVM

Hypothetically let's say I have an application where I have Users and Tasks, each User have different Tasks assigned to them. I have a MainWindow that lists the users, and when you click on a User a ManageTasksWindow is opened, showing the Tasks assigned to the User and on this ManageTasksWindow you can remove, update and assign Tasks to this User. If I want to add a new Task to the User an AddTaskToUserWindow will be opened on a button click. My problem is that the logic that handles the opening of this AddTaskToUserWindow is in a class called TaskLogic and I have no idea how to reference the currently opened SubWindow, so that I can set the AddTaskToUserWindow's Owner property to the SubWindow.
I have tried this:
AddTaskToUserWindow window = new AddTaskToUserWindow();
window.Owner = Application.Current.Windows.OfType<ManageTasksWindow>().First();
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
But I want a solution, where each AddTaskToUserWindow's Owner property can be set to the corresponding SubWindow.
You can add a property to ViewModel of the main window (say SelectedWindow or ActiveWindow) and set its value whenever you select a user. Then, listening to the NotifyPropertyChanged of the main window, your TaskLogic can find the ActiveWindow whenever it changes automatically.

Is this a way to show a modeless dialog from a dockable pane using WPF?

I'm building a Revit plugin. It consists of a dockable pane that (among other elements) has a button. I want to open a new, separate window when a user clicks this button.
At the moment, i create a new Window, but i don't know if that's the right way to go, because now i see two Revit icons on a task bar. I do not have experience as Revit user, i'm new to Revit development, so i'm not sure if this should be the case (two icons) and as silly as it sounds, i do not have admin rights to install random addins and get a feeling of expected user experience.
I create a Window using the following code:
ParametersMissingValueWindow parametersMissingValueWindow = new ParametersMissingValueWindow();
parametersMissingValueWindow.Show();
Based on the understanding of a dockable pane that i have, i think i do not want to create another dockable pane, but just a simple modeless dialog. I wasn't able to find any examples using WPF. Hence, any information whether this is the way to go or help on how to achieve this is highly appreciated.
The Show method takes an optional parent window argument. Specify the Revit main window as the parent window, and your modeless dialogue will be recognised as belonging to the running Revit process. It is accessible from the MainWindowHandle property.
var MyWindow = new MyWindow();
HwndSource hwndSource = HwndSource.FromHwnd(UIApplication.MainWindowHandle);
Window wnd = hwndSource.RootVisual as Window;
if (wnd != null)
{
MyWindow.Owner = wnd;
//MyWindow.ShowInTaskbar = false;
MyWindow.Show();
}
It's not necessary to assign a value to ShowInTaskbar property, but it actually achieves what i wanted to do from the beginning (have only one program open in taskbar), so i left it as part of the solution, but commentted out.
Big thanks to Jeremy Tammik for pointing out the parent property.
You can use WPF to setup a window to use in revit.
MyWPF menu = new menu();
System.Windows.Window wind = new System.Windows.Window();
wind.ShowDialog(); //--> the window shows up and make stuff for revit
if you need the menu to be a dockable one check this source.
Perhaps is not up to date and you will need to adapt the code to the new api.

WPF MessageBox not waiting for result [WPF NotifyIcon]

I am using WPF NotifyIcon to create a System Tray service. When I show a messagebox, it shows up for half a second and then disappears immediately without waiting for input.
This kind of situation has happened before, and the usual advice is to use an overload which accepts a Window parameter. However, being a System Tray service, there is no window to use as a parent, and null is not accepted in its place.
Is there any way to make the MessageBox wait for user input short of creating a custom MessageBox window myself?
You don't need to create a proxy window for this. Just add MessageBoxOptions.DefaultDesktopOnly to your message box and it will fire on your desktop without disappearing.
Example
MessageBox.Show("My Message", "Title", MessageBoxButton.OK,
MessageBoxImage.Information, MessageBoxResult.OK,
MessageBoxOptions.DefaultDesktopOnly);
According to the answer here, a workaround is to actually open an invisible window and use that as the parent of the MessageBox:
Window window = new Window()
{
Visibility = Visibility.Hidden,
// Just hiding the window is not sufficient, as it still temporarily pops up the first time. Therefore, make it transparent.
AllowsTransparency = true,
Background = System.Windows.Media.Brushes.Transparent,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false
};
window.Show();
...then open the MessageBox with the appropriate parameter:
MessageBox.Show(window, "Titie", "Text");
...and don't forget to close the window when you're done (possibly on application exit):
window.close();
I tried this and it works well. It's undesirable to have to open an extra window, but it's better than making your own messagebox window just for the sake of making this work.

How to simulate a drop-down window in WinForms?

i know a Windows Combobox control is nothing but a Textbox and a ListBoxglued together.
i need to simulate the same thing in WinForms. i am trying to figure out Windows window options that must be set to achieve the proper effect.
the drop-down cannot be a child window - otherwise it is clipped to the parent's area
conceptually it must be a pop-up window - an overlapped window
it can be an owned window - An owned window is always above its owner in the z-order. The system automatically destroys an owned window when its owner is destroyed. An owned window is hidden when its owner is minimized.
The best i've managed so far is to create
a borderless (this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None)
topmost (this.TopMost = true)
form that doesn't show in the taskbar (this.ShowInTaskbar = false)
this borderless topmost form contains my "drop-down" control. i "hide" my dropdown when the dropdown form loses focus:
this.Deactivate += new EventHandler(TheDropDownForm_Deactivate);
void TheDropDownForm_Deactivate(object sender, EventArgs e)
{
...
this.Close();
}
This conglomeration of mess works well enough...
...except that "drop-down" takes focus away from the owner form.
And this is my question, what properties should my popup window have?
SW_SHOWNOACTIVATE?
But then how do i hide my drop-down form when it loses focus - when it cannot lose focus?
How do i simulate a combo-box drop-down in .NET?
Note: Don't confuse what you see in the example screenshot with something else. i am asking how to create "drop-down" form in Winforms - the contents can be different than the screenshot above:
Using a ToolStripControlHost and a ToolStripDropDown can achieve the same effect.
From this answer:
Private Sub ShowControl(ByVal fromControl As Control, ByVal whichControl As Control)
'\\ whichControl needs MinimumSize set:'
whichControl.MinimumSize = whichControl.Size
Dim toolDrop As New ToolStripDropDown()
Dim toolHost As New ToolStripControlHost(whichControl)
toolHost.Margin = New Padding(0)
toolDrop.Padding = New Padding(0)
toolDrop.Items.Add(toolHost)
toolDrop.Show(Me, New Point(fromControl.Left, fromControl.Bottom))
End Sub

Categories