How can I maximize the form at run time - c#

How can I maximize the form at run time?
I have one panel in form 1 . I want to show form 2 (Rule_form) in this panel on button click.
I have write this code on button click:
Rule_form rule = new Rule_form();
rule.Show();
rule.TopLevel = false;
rule.WindowState = FormWindowState.Maximized;
rule.FormBorderStyle = FormBorderStyle.None;
internal_pannel.Controls.Add(rule);
But it doesn't work. When I click on button form 2 (Rule_form) opens with it's default size.
How can I maximize a form 2 (Rule_form) with panel size at start up?

I think you should run rule.Show(); at last.
Because now the form get showed before it is maximized.
That explains your problem.
What if you call rule.show after setting the windowstate or formborderstyle.
That is supposed to work.
You can also create an load event for the new form. And in this load event set the form to be maximized. Like this:
private void Rule_form_Load(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}

Related

Taskbar icon disappears when minimizing form application c#

When I'm changing windows(forms), my application's icon disappears from taskbar. So for opening the application, users need to click ALT+TAB to select the form which is hidden from taskbar. After users choose application, icon comes to taskbar again. I don't want my applcation icon disappears from taskbar.
My codes are below:
//Program.cs
[STAThread]
static void Main()
{
Application.Run(new LoginPage());
}
Login Page is application's first screen that gets username and password. After clicking submit button application is going to main page.
//LoginPage.cs
private void submitBtn_Click(object sender, EventArgs e)
{
MainPage mainPage= new MainPage();
mainPage.Show();
this.Hide();
}
Lets say I have a button on main page for going to another form. Here when I click the page1 button taskbar icon disappears.
//MainPage.cs
private void page1Btn_Click(object sender, EventArgs e)
{
Page1 page1 = new Page1();
page1.Show();
this.Hide();
}
After some research I found one solution for that but there is another problem which I cannot minimize the form correctly.
When I change the codes above with below
//MainPage.cs
private void page1Btn_Click(object sender, EventArgs e)
{
Page1 page1= new Page1();
page1.ShowInTaskbar = false;
page1.Owner = this;
page1.ShowDialog();
this.Hide();
}
Here, I also need to modify Page1 as below
//Page1.cs
private void Page1_FormClosed(object sender, FormClosedEventArgs e)
{
MainPage mainPage = new MainPage();
mainPage.Show();
}
Here I can successfully go to page1 step by step (without disappearing the taskbar icon). When I minimize the page1, it minimizes the application as expected but when I maximize the application from taskbar, I expect Page1 should maximizes but MainPage maximizes with an minimized Page one like below image.
I only want to correct these problems. I hope there is experts which experienced these things there.
Problem is solved.
The problem was, I was maximizing the form from properties of the page.
Instead of maximizing it from properties, I do it manually from Page Load and its solved.
this.Bounds = Screen.PrimaryScreen.WorkingArea;
In MetroFramework, I have the same problem. When my application starts (in the FORM_LOAD) , I programmatically maximize and the icon disappears. Checking the MetroFramework code, the problem is caused by ShadowType. If you change the ShadowType to None:
this.ShadowType= MetroFormShadowType.None;
the issue is resolved. I hope the solution works

How to create a full-screen form with max/min/close button in c#?

I made full-screen by: FormBorderStyle = FormBorderStyle.None;
but there is no max/min/close button? How to get it?
Set the WindowState property of your form to Maximized instead of removing the form border if you want a full screen form to retain the controls.
private void Form1_Shown(object sender, EventArgs e)
{
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}
If you actually want a full screen form with no border the best way to do this would likely be a custom user control to emulate the standard min/max/close functions.

How do I make a button make a form in another form?

So in my current situation I have my Desktop form set to open things inside that form through the MDI.Container.
I have a form automatically open when the Desktop form is started. After reading that form you would click "next" on the form button and it SHOULD open the new form in the same mdi container, but instead it opens it in a new window in my actual OS. I want it to open in the original MDI container in the Desktop form.
If you can help me out please do!
I've tried the following:
this.IsMdiContainer = true;
Welcome welcome = new Welcome();
welcome.MdiParent = this;
welcome.Show();
Would this help? I'm not sure to get your question
// C#
protected void MDIChildNew_Click(object sender, System.EventArgs e)
{
Form2 newMDIChild = new Form2();
// Set the Parent Form of the Child window.
newMDIChild.MdiParent = this;
// Display the new form.
newMDIChild.Show();
}
the problem is you make the form ismdicontainer = true inside code you should make form ismdicontainer true while designing, not in run time.

Resizing mdiChild form affects the other mdiChild form

I am creating an MDI application in which it has multiple mdiChild forms. When I resize one mdiChild form, it affects the other mdiChild forms.. How can I solve this? There are a lot of questions about mdichild forms here but none of them seems to be the same case as i have.
Example :
When i maximize one mdiChild form, the other will maximize too even though they are set to normal window state already..
EDIT
This is the mdiParent codes where i call the mdiChild forms.
private void editAccountToolStripMenuItem_Click(object sender, EventArgs e)
{
AdminForms.Dialogs.FrmAdminEdit adminedit = new AdminForms.Dialogs.FrmAdminEdit();
adminedit.Show();
adminedit.MdiParent = this;
}
private void listOfCandidatesToolStripMenuItem_Click(object sender, EventArgs e)
{
AdminForms.Dialogs.FrmCandidate cand = new AdminForms.Dialogs.FrmCandidate();
cand.Show();
cand.MdiParent = this;
}
But in run-time, when i resize one of the mdichild, the other mdichild forms are resizing too.. if maximize button is clicked, all of the mdichild will be maximized.
I want the mdiChild that I resize, do not affect the other mdiChild forms..

Minimizing a system windows form in tray in C# without seeing it hanging where taskbar

this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
//this.visible = false (Hotkeys stop working forever but the grey rest of the form would disappear from above taskbar)
ReRegisterHotkeys();
I use the code above to minimize my application with a tray icon. Now the minimized rest of my form hangs still in the left right corner a little above the taskbar where the start button resides. Visible is only the forms grey titlebar with the little "x" to close it and its caption text above the title bar.
This is very weird. I set my form to "mimimized" and set not to show in taskbar and it still does.
I have registered Hotkeys with my form so I may not set it to "invisible" else the hotkeys somehow cease to work even if I re-register the Hotkeys afterwards again.
I found no alternative yet to remove this minimized form caption other than set it to "invisible"
or removing its titlebar what I also don't want to do. I need titlebar, titlebar icon and titlebar control area in this program, the form shall not become a toolwindow or without borders.
How do I make this grey rest of the form above the taskbar disappearing without setting my form to a toolwindow and without setting it totally invisible. My Hotkeys must still work after it and the form must still keep its titlebar, icon and control area when I set it back to normal again.
I took my hotkey code from this example. The only difference is that I packed the procedure to register the hotkey into a sub-function named "ReRegisterHotkeys()".
Important:
The issue with the titlebar showing when form is minimized is not connected with the registered hotkeys.
It's a common "C# issue". If I have a form and minimize it and set it to invisible in taskbar
it is still shown the titlebar with the "x" in the taskbar. This I want to remove without making
the form invisible or without removing the window style.
"this.show" or "this.hide" behaves the same fatal as "this.visible=true/false" since the hotkeys are gone. I create my form as shown by default and want not to create it hidden already.
This is what shall be not there - how to remove it without hurting:
All you have to do is call Hide() and Show() when you want to hide and show your form.
NOTE: Hide() will hide from taskbar as well.
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
Hide();
}
You may hide and show the NotifyIcon opposite to the form to not have a icon when the form is shown.
Obviously you need a NotifyIcon to display your app in the system tray.
Finally your code will look like this:
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
notifyIcon1.Visible = false;
WindowState = FormWindowState.Normal;
}

Categories

Resources