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() ;
Related
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.
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);
How can I have a black form as a background and some modal forms opened one at a time whose owner is the black form? I need these two to retain their order together (when minimized and maximized) that's why I have chosen the modal form.
I have made a simple main form with black background, and opened a form in dialog (modal) form. The main form provides a black background for me and the modal form stays in front of the black background. But when opening new forms, I can't set the owner of new modal form to the aforementioned black form. I have tried passing the black form object and also registering events to no avail.
Do you know any mechanism to implement the following scenario:
A black form as a background and a series of modal forms opened one at a time in front of the black one in a way that the black form is the owner of every modal form.
Thanks
Edit
Please consider this scenario: I have 3 forms named frmBlack, Form1 and Form2. I use frmBlack as the main blacked form. After placing a button on this form I call the Form1Object.ShowDialog(this). Now suppose that I want to navigate to the third form (Form2), [this means that I must close the Form1Object] I put a button on the second form (Form1) and when this button is pressed I must close the Form1 object and navigate to the Form2Object while its owner in the ShowDialog() function must be set to frmBlack.
This is done using MDI Forms.
Your application will look like this: http://www.datadynamics.com/Help/AB3/Images/MDI%20Child%20menu.gif
This works in winform projects, not in WPF project (at least not by default).
Parent or Owner? That's a difference. Parent is only used in MDI-Applications (see Luigi's post). The owner can be set in the call to ShowDialog( owningForm ).
What is it that you want to achieve?
hth
Mario
To achieve what you want from the window with the second button post pack to the frmBlack and let it do the work.
Or more specifically set a flag within the frmBlack, since in frm1.btnShowNextForm you need to close frm1...
And also take a look at Form.Owner
so something along these lines in frm1.buttonShowNextFormClicked()
{
if ( null != Owner )
{
FrmBlack frmBlackLocal = Owner as FrmBlack;
if ( null != frmBlackLocal )
{
frmBlackLocal.NextAction = FrmBLack.NextActions.ShowForm2; //an enum
}
}
Close();
}
and in frmBlack
{
frm1.ShowDialog(this);
if ( NextAction == NextActions.ShowForm2)
{
frm2.ShowDialog(this);
}
}
Well, of course it needs some brush-up (like extracting the next handler in a function of it's own, but you should get the idea.
hth
Mario
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
I am developing an application in C#. I have a Main Form where I have some buttons that give the user the possibility to start a new form into the Main Form.
When there are more of this kind of forms opened and the user choose to minimize one, it goes to back behind all opened forms. So if the user would want to open again that form he must close/minimise all forms.(for beeing able to see the minimized one)
How can I manage the minimised form location so it could be visible after it is minimised? I tried without any result stuff like that: bringToFront, Activate, Focus, etc.
My Main Form contains the buttons and a panel, so the forms are opening in the panel bellow the buttons.
why don't you go for MDI win-form ? I think they fit really well in what you are trying to achieve
http://msdn.microsoft.com/en-us/library/ms973874.aspx
Finally I did managed myself to solve the problem. It was so simple.
For the forms that opens in the panel child I removed
formName.Dock = DockStyle.Fill;
and I set the formName.Height = panelContainer-25; So now the little form minimized is visible.
I know this is late post but might be useful for someone like me.
Try this this was working for me to set minimized window location and size as well
https://social.msdn.microsoft.com/Forums/windows/en-US/d6014e48-2adb-4096-8bea-94c2f3b1c47c/how-to-change-the-location-of-a-minimized-mdichild-form?forum=winforms