Taskbar Issue for My App - c#

When I click on my Winforms app then its forms are opened in separate section in Taskbar with default C# icon. How can I solve this issue?
Update:
At first I open my login form as bellow:
Application.Run(new frmLogin());
Then I open my main form from the login form as bellow:
this.Hide();
frmMain frmMain = new frmMain();
frmMain.Show();

This sounds like a system problem. Here are 3 solutions:
Restart your computer.
Restart explorer.exe or File Explorer. How to do it.
Unpin then re-pin your program on the taskbar.

first solution: you can set this property of the form
and another solution :
Did you try parent form and child form?
Set Parent of the forms, So they will be open as child of your main form
For Example(In the main form when You want to open another form) :
FrmChild frmChild= new FrmChild ();
frmChild.Parent = this;
FrmChild.Show();

Related

Form closing before new shows

Hello I'm making my first Windows Forms app in C# using Visual Studio and I have a little problem.
While I'm opening a new form and closing the previous one, when I run the app it looks like it's closing the previous form before it opens a new one.
It doesn't look good and I want to avoid it.
UserPanel MDIUserPanel = new UserPanel(Username);
MDIUserPanel.MdiParent = this.MdiParent;
MDIUserPanel.Show();
this.Close();
I don't know what is going wrong. I will be thankful for any help.
Wirth regards,
DarQScreaM
#Edit
This doesn't seem to be the case actually. Propably its that :
I have 3 forms MainForm, Login, LoggedUser.
MainForm is MDI container with FormBorderStyle set on Fixed Single
Login is child of MainForm with FormBorderStyle set on None
LoggedUser is child of MainForm with FormBorderStyle set on None
When application is runned Login form is created in MainForm. MainForm is never closed since its container.
But when i move from Login form to LoggedUser form and vice-versa its created with FormBorderStyle = Fixed Single (normal windows window) and after 0.5~second its changed into None.
Editing it into that didn't really help :
MDIUserPanel.FormBorderStyle = FormBorderStyle.None;
MDIUserPanel.Show();
#Edit2
This change fixed it for me. I don't know why setting it on Form properties didn't work properly. It looked like form was created as FormBorderStyle.FixedSingle and then it was changed into FormBorderStyle.None. If I made this manually in Load it worked but U had to fix the size of my window too. It doesn't seem to be good though. It should work from the beginning since Form properties in Designer are like that from the very beginning.
private void UserPanel_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.Size = new Size(649, 357);
}
You can use the form's Shown event to ensure that the new form have been showed before you close the old one.
UserPanel MDIUserPanel = new UserPanel();
MDIUserPanel.Shown += ((s, ee) =>
{
this.Close();
});
MDIUserPanel.Show();
If this form you are trying to close, is the main form that opens when you run your application, then that's the reason. Closing the main form will exit your application. Try instead to just hide this form instead of closing it. And to make sure you can exit your application ('cause you've hidden your main form), just override the closing event of your current form, and put an "Application.Exit()" in it.
Hope this helps you !
First Step:
this.Hide();
Second Step:
MDIUserPanel.Show();

WinForms: Show form modal over other application's main window

Is it possible to show a WinForms modal form over another process's main window?
For example my WinForms application consists of one form which is modal over another process's main window with PID x.
You can show it as a dialog, like so:
Form1 frm = new Form1();
frm.ShowDialog(this);
frm.Dispose();
You pass the current IWin32Window or form you want to be the owner, so if you're calling it from say a button click on the parent form, just pass through this.
You want to be able to get the IWin32Window for another process, which is possible, but I don't know if showing a form as a modal over that is.
var proc = Process.GetProcesses().Where(x => x.ProcessName == "notepad").First();
IWin32Window w = Control.FromHandle(proc.MainWindowHandle);
using (Form1 frm = new Form1())
{
frm.ShowDialog(w);
}
This is how it would work, if it was possible, however, it doesn't seem to work for me.
This link may shed a bit more information on the subject: How can I make a child process window to appear modal in my process?

close the form from mdi parent when i click to open any other form

i have an administrator form and in this form lot of menu items and all open a new form. but when I open a new from again i will open a new from then new form will be open but old form will not be closed.there are many form open in administrator form. i wand when i open any form on click a menu item the other form close.
Simply you have to know each form object then you can close it, for example when you want to open one windows you write
new MyForm().ShowDialog();
Ok instead you can declare a form object in the top of your administrator form:
Form oldForm;
when user press one of your forms list:
if (oldForm != null)
oldForm.Close();
Form newOne = new UsersForm();
oldForm = newOne;
newOne.ShowDialog();

How to bring "all forms" to foreground (WindowsMobile/C#)

(C# / WindowsMobile 6)
Let's take an application with 3 STATIC forms: Form1, Form2, Form3, where Form1 opens Form2 by calling Form2.Show(), and Form2 does the same with Form3. Form2 and Form3 have a "Exit" button, that just hides the form (not "close", just hide).
So, we execute these steps:
open the application;
go to Form2, by clicking "Form2" button on Form1;
go to Form3, by clicking "Form3" button on Form2;
open File Explorer, and "re-open" application by clicking on it's file. Form3 appears;
hide Form3 by clicking on "Exit" button on Form3 ( this.Hide() ). That's the problem: file explorer appears instead Form2.
I don't want to call "callingform".Show() every time I hide a form. This "works", but file explorer screen appears after "this.Hide()" and before "callinform.Show()" and I need to "control" who's calling who.
How to solve this? Is there any way to bring all application's form to foreground in the same order they appeared?
Thanks in advance.
There really isn't a way. You could implement a way to store forms in a similar way to the first answer, but when you switch you need to do:
"callingform".BringToFront();
"callingform".Show();
That will put all of your forms in front of Explorer.
You might need to do some investigation into this, but off the top of my head you could try looking at the Application.Forms[] collection.
Maybe someone can confirm or deny this but I think usually, Application.OpenForms[0] will be the main/initial form with subsequent Form appearances being in Application.OpenForms[1], Application.OpenForms[2], etc...
So you could simply try navigating backwards through this Forms collections.
Something like (or a variation of),
public void BringLastOpenedFormToFront()
{
if(Application.OpenForms.Count > 0)
{
Form form = Application.OpenForms[Application.OpenForms.Count - 1];
BringToFront(form); // your bring to front method.
}
}
This would allow you to ensure the last Form that appeared was brought to the front and immediately visible to the user. Let me know if you need any clarification.
Link to MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx

restart Function in visual C#

I have a windows application I need to create a button that unload/close/restart the currunt form while its running and reload/reopen/restart the same form.
How ??
I tried the hide show thing but it keeps the old form running in the background
Application.Restart();
I found it ....
Application.Restart() will restart your entire application.
Hide() will only do what it says, hide the form. If you just want a fresh version of your form to reappear, you can just create a new one, Show() it, and Close() your current form.
public void Restart()
{
var window = new MyForm();
window.Show();
this.Close();
}
You'll have 2 forms open for a very short time, so if you have any data connections that need to be closed, do so before reopening the form. To the end-user, it will happen so fast that they won't know 2 forms were open.

Categories

Resources