Has anyone got any idea why when I run the program, and go to click the taskbar item to open the small text entry area the icon disappears as soon as I get to it!!!
Thanks very much
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace systemTray
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
this.Visible = false;
}
private void Form1_Resize(object sender, System.EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
{
Hide();
}
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
var screen = Screen.PrimaryScreen;
this.Left = screen.WorkingArea.Right - this.Width;
this.Top = screen.WorkingArea.Bottom - this.Height;
Application.Run();
}
private void searchToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
}
}
edit: I am not sure if this helps but to make the application not open the form I changed the main method from
Application.run(new form1())
to
new form1()
Application.Run is use to run your windows form application,
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
when you delete the line Application.Run(new Form1()); then your application just started and call Main() and after that it closed because it has finished it's work.
the question is why you delete Application.Run(new Form1());??
Related
I have a form Modal ShowDialog. Trying the close the Form created if one of two things happen 1 button on the form is pushed or 2 a value changes in a static variable.So far the button works I can use another button to check the status of the value and view the change? How can I have the 2nd part close the form?
Main_Menu.cs
public void OverloadTripearly()
{
OverloadTripEarly overloadTripEarly = new OverloadTripEarly();
overloadTripEarly.Owner = this;
overloadTripEarly.ShowDialog();
// overloadTripEarly.Refresh();
// OLTrip = overloadTripEarly; // assign object to enter
}
OverloadTripEarly.cs code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormTitlepageNew
{
public partial class OverloadTripEarly : Form
{
public OverloadTripEarly()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy)
{
backgroundWorker1.CancelAsync();
}
else
{
this.Close(); // close if button is pressed
this.Dispose();
}
}
private void OverloadTripEarly_Load(object sender, EventArgs e)
{
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
do
{
Thread.Sleep(100);
GlobalVariables.OverloadTest = NIDMMPXIeSlot5ConsoleApplication.SingleResistance
MeasurementApp();
if (double.IsNaN(GlobalVariables.OverloadTest))
{
GlobalVariables.OverloadFlag = true;
this.Close();
e.Cancel = true;
}
if (backgroundWorker1.CancellationPending)
{
e.Cancel = true;
this.Close();
return;
}
} while (double.IsNaN(GlobalVariables.OverloadTest));
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void backgroundWorker1_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
if (e.Cancelled)
{ this.Close();
this.Dispose();
}
}
private void button1_Click(object sender, EventArgs e)
{
GlobalVariables.OverloadTest = NIDMMPXIeSlot5ConsoleApplication.SingleResistance
MeasurementApp();
if (double.IsNaN(GlobalVariables.OverloadTest))
{
textBox1.Text = "NaN".ToString();
}
else
{ textBox1.Text = GlobalVariables.OverloadTest.ToString(); }
}
}
}
i think your Problem is, that you change the 'Win Form' from another thread.
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled)
{ this.Close();
this.Dispose();
}
}
Backgroundworker is calling from another thread. So you have to check if InvokeIsRequired and if so then invoke the this.Close()
check this link
I'm not very versed in coding, let's say this is some kind of project I started without knowing anything about coding.
I have a Button which should read the selection in the comboBox and then open a specific form.
I've tried using following the switch (comboBox1.SelectedText)
While that didn't quite work, I tried another approach:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace The_Liberion_Magnicite
{
public partial class Form1 : The_Liberion_Magnicite.Character
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.SelectedText.ToString();
{ if (comboBox1.SelectedText.ToString() == "Shiroichi Kazami (PTS)")
{
this.Hide();
Shiro1 CShiro1 = new Shiro1();
CShiro1.Show();
}
else if (comboBox1.SelectedText.ToString() == "Shiroichi Kazami (ATS)")
{
this.Hide();
Shiro2 CShiro2 = new Shiro2();
CShiro2.Show();
}
else if (comboBox1.SelectedText.ToString() == "Akari Hondo")
{
this.Hide();
AkariHondo CAkari = new AkariHondo();
CAkari.Show();
}
else if (comboBox1.SelectedText.ToString() == "Aboa Sekihara")
{
this.Hide();
AobaSeki CAoba = new AobaSeki();
CAoba.Show();
}
}
}
}
}
I'm in some dire need for help ;)
I have a dotnet 2.0 app in C# that I have developed in Visual Studio 2008, it's pretty simple:
I would like to change the label name currently called "label1" to "Running" or "Stopped" when my process loop.exe is running or stopped.
When I press start, it will run loop.exe and the stop button will obviously stop it.
I've read a lot of topic on C# Winforms but I cannot get this working and I have no idea what do to now. I think that I need to add a backgroundworker but I don't know how to check the process and update the label programmatically.
Here's my clean/current code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace APP_NAME
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Process.Start("taskkill", "/F /IM loop.exe");
Process.Start("taskkill", "/F /IM azcopy.exe");
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, EventArgs e)
{
Process.Start("notepad.exe", #"C:\ProgramData\APP_NAME\settings\settings.xml");
}
private void button4_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", #"C:\ProgramData\APP_NAME\logs");
}
}
}
I hope I made myself clear, thank you.
You can update the text shown by a label by accessing it's Text property. So, change your method like:
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
label1.Text = "Running";
}
//hi
//Do this to see the label value changes in real time in the window
private void Start_Click(object sender, EventArgs e)
{
Process.Start("loop.exe");
label1.Text = "Running";
lable1.Refresh();
}
So i've just started learning C#, and I came across a error saying that Form5 "is a variable but is used like a type". I have shown the page of code that has the error, but if you want to look at the bigger picture, here's my github repo ( I am a totally noob at gihub, so if anything is mispelled or totally wrong, I'm Sorry! : https://github.com/ValorZard/Chocobomb
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace animal_years
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
/*
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
*/
Form Form1 = new Form1();
Form1.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Form Form3 = new Form3();
Form3.Show();
}
private void button3_Click(object sender, EventArgs e)
{
Form Form2 = new Form2();
Form2.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Form Form4 = new Form4();
Form4.Show();
}
private void button5_Click(object sender, EventArgs e)
{
Form Form5 = new Form5();
Form5.Show();
}
}
}
Form5 "is a variable but is used like a type"
That is precisely correct. And clear. You're using the type name Form5 (which is a terrible, undescriptive name by the way) as a variable name too. A simple alternative is to write new Form5().Show(); -- why do you need a local variable in the first place?
Your class name in form5.cs file is outputDescriptionLabel. So you have to call that class name here. Use below code:
private void button5_Click(object sender, EventArgs e)
{
outputDescriptionLabel f = new outputDescriptionLabel();
f.Show();
}
I have a windows Form Project that runs smoothly and fine on framework 4.5.1
But yet I have a project on framework 2.0 that is so laggy even after i changed the target framework to 4.5.1
so why is one project slow and the other is normal?
Update :
here is the Main From
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBaseLab_Library_Project
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button5_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show(" ", "About US");
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
Add AddForm = new Add();
AddForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
Search SearchForm = new Search();
SearchForm.Show();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
and here is its design
Update 2 :
Form "Add.cs" that dose not lag .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBaseLab_Library_Project
{
public partial class Add : Form
{
public Add()
{
InitializeComponent();
}
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
AddBook AddBookForm = new AddBook();
AddBookForm.Show();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
MainForm mainForm = new MainForm();
mainForm.Show();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void publisherButt_Click(object sender, EventArgs e)
{
this.Close();
AddPublishercs AddPublisherForm = new AddPublishercs();
AddPublisherForm.Show();
}
private void authorButt_Click(object sender, EventArgs e)
{
//this.Close();
//AddAuthor AddAuthorForm = new AddAuthor();
//AddAuthorForm.Show();
}
private void Add_Load(object sender, EventArgs e)
{
}
}
}
Try removing the panel1 paint eventhandler. This will get called (even tho its empty) ever time the panel has to draw itself, which is all the time in a designer environment.
Remove this code:
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
There will also be code inside of InitializeComponent() similar to this
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1);
Remove it as well. Clean and rebuild solution. Close all designer windows. Try again.