c# how to FormWindowState.Normal - c#

i have this code:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
about About = new about();
About.ShowDialog();
}
it minimizes the parent window state to minimized and displays a splash form.
my question is when the splash screen closes how do i get back to parentwindowstate.normal?

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
about About = new about();
About.ShowDialog();
this.WindowState = FormWindowState.Normal;
}

If you're using ShowDialog instead of Show; you can add
this.WindowState = FormWindowState.Normal;
after the ShowDialog call. (ShowDialog is blocking, unlike Show.)

Call ShowDialog() like this:
About.ShowDialog(this);
Then, in the About form's FormClosing event, put:
this.Parent.WindowState = WindowState.Normal;

Related

c# Why can I not return my application from minimize?

I have googled this and all the sites I have seen tell me the same thing for minimizing my app and then returning it to normal. I can minimize it fine but when I click on the icon in the tray then nothing happens. Here is my code.
private void Form1_SizeChanged(object sender, EventArgs e)
{
bool PointerNotOnTaskbar = Screen.GetWorkingArea(this).Contains(Cursor.Position);
if (this.WindowState == FormWindowState.Minimized && PointerNotOnTaskbar)
{
notifyIcon1.Icon = SystemIcons.Application;
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.ShowInTaskbar = true;
WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
}
I have also tried
this.WindowState = FormWindowState.Normal;
Comment out this: this.ShowInTaskbar = false;
If the form is minimized and not visible in taskbar will take a spell to bring it back!

Disabling a button when a form is loaded and enabling when the form is closed

I want to disable a button (button3) on a primary form when a second, modeless form (Form2) is loaded, and then re-enable the button when the modeless form is closed.
Here is what I've tried:
private void button3_Click(object sender, EventArgs e)
{
Form2 p = new Form2(label1.Text);
p.Show();
if (p.Shown)
this.button3.Click += new System.EventHandler(this.button3_Click);
else
this.button3.Click -= new System.EventHandler(this.button3_Click);
}
The best method for achieving this would be to disable button3 prior to showing Form2, and using the FormClosed event on Form2 to re-enable button3 once the form is closed:
public partial class Form1 : Form
{
...
private void button3_Click(object sender, EventArgs e)
{
// Instantiate the form and assign the FormClosed event
var form = new Form2(label1.Text);
form.FormClosed += Form2_FormClosed;
// Disable button3
button3.Enabled = false;
// Show the form
form.Show();
}
// Occurs when Form2 is closed
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
// Re-enable button3
button3.Enabled = true;
}
}
An alternative method, that assigns a lambda expression to the FormClosed event:
private void button3_Click(object sender, EventArgs e)
{
// Instantiate the form
var form = new Form2(label1.Text);
// Assign a lambda method to the FormClosed event to re-enable button3
form.FormClosed += (s, a) => button3.Enabled = true;
// Disable button3
button3.Enabled = false;
// Show the form
form.Show();
}
I did a similar thing, i m not sure to understand what you want to do but maybe it will help you.
public partial class Form2 : Form
{
private void button3_Click(object sender, EventArgs e)
{
Button3.Enabled = false;
Form2 p = new Form2(label1.Text);
p.ShowDialog();
//the code will stop here until you finish your work on form2
Button3.Enabled=true;
}
it works with me.
But if your form3 is just a short label use:
Button3.Enabled= false;
MessageBox.show ("blabla");
Button3.Enabled=true;

How to make Application ontop of all windows and allow message box to be shown correctly

I am writing an application, that on specific conditions must make my application ontop of all other windows applications.
I do this in timer code as shown below that runs every 10 ms. That is fine. However if i need to throw a message box if there is an error then the messagebox ok button cannot be pressed because the form is made topmost every 10 ms - The button can be seen but you cant click ok.
Assumably because the first time you click the button brings the errorbox modal and by the time you click the ok button 10 ms has passed and the form is now ontop again.
How can i fix this issue ?
Timer
private void timer1_Tick(object sender, EventArgs e)
{
this.Visible = true;
this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
Show an Error
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Some error occured");
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!this.TopMost == true)
this.TopMost = true;
this.Visible = true;
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Some error occured");
}

How to minimize and maximize in C#.Net?

I want to minimize and maximize manually in C#.net.
I changed form's BorderStyle into none.
So there are no maximize,minimize and close button from bar.
I want to manually create with button like those functions.
I want to do three functions in button click events.
You have to set the forms WindowState property something like this:
In Windows Forms:
private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
In WPF:
private void button1_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
Form.WindowState Property
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.windowstate%28v=VS.90%29.aspx
public FormWindowState WindowState { get; set; }
For example -
var form = new Form();
form.WindowState = FormWindowState.Maximized;
form.WindowState = FormWindowState.Minimized;
form.WindowState = FormWindowState.Normal;
However, if you are in the code behind on the main form (or any form) just do this -
WindowState = FormWindowState.Maximized;
If you're using WindowsForms you have to change the WindowState property :)
private void button4_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Normal)
{
this.WindowState = FormWindowState.Maximized;
}
else
{
this.WindowState = FormWindowState.Normal;
}

Completely Maximized C# WinForm

Is there a way to make the C# form completely covers the whole screen? I would be doing this without explorer.exe running, if that makes it easier. I don't want it to be full screen, because I want other programs to be able to run above it. Thanks!
private void frm_Load(object sender, EventArgs e)
{
ControlBox = false;
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
}
private void frm_KeyDown(object sender, KeyEventArgs e)
{
// restore form on Escape key press.
if (e.KeyCode == Keys.Escape)
{
ControlBox = true;
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Normal;
}
}

Categories