C#: Three build errors that I can't figure out - c#

I am getting three errors that are preventing my program from running and I cant figure out what they mean? I must be stupid because I even have my C# book next to me and it still doesn't make sense. Any help would be great. The errors are:
Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe' has more than one entry point defined: 'WindowsFormsApplication1.Program.Main()'. Compile with /main to specify the type that contains the entry point.
'WindowsFormsApplication1.Form1.Dispose(bool)': no suitable method found to override
Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe' has more than one entry point defined: 'Text.Main()'. Compile with /main to specify the type that contains the entry point.
Code:
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;
public class Text : Form
{
private Font arialBold24 = new Font("Arial", 24, FontStyle.Bold);
private Font timesItalic14 = new Font("Times New Roman", 14, FontStyle.Italic);
private Font courierPlain18 = new Font("Courier New", 18, FontStyle.Strikeout);
private Font genericSerifBI20 = new Font(FontFamily.GenericSerif, 20, FontStyle.Bold | FontStyle.Italic);
private Font verdanaPlain18 = new Font("Verdana", 18, FontStyle.Regular | FontStyle.Underline);
public Text()
{
Size = new Size(400, 200);
Text = "Text";
BackColor = Color.White;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
int w = (int)g.MeasureString(arialBold24.Name, arialBold24).Width;
int arialStart = (Width - w) / 2;
int otherStart = Width / 4;
int h = DisplayRectangle.Height;
g.DrawString(arialBold24.Name, arialBold24, Brushes.Blue, arialStart, 0);
g.DrawString(timesItalic14.Name, timesItalic14, Brushes.Blue, otherStart, h / 5);
g.DrawString(courierPlain18.Name, courierPlain18, Brushes.Blue, otherStart, 2 * h / 5);
g.DrawString(genericSerifBI20.Name, genericSerifBI20, Brushes.Blue, otherStart, 3 * h / 5);
g.DrawString(verdanaPlain18.Name, verdanaPlain18, Brushes.Blue, otherStart, 4 * h / 5);
base.OnPaint(e);
}
public static void Main()
{
Application.Run(new Text());
}
}
The program.cs code is:
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Updated Code of Form1:
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
}
}
Program.CS code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Text());
}
}
}

First of all, you don't need another Main method in class Text, as it is already defined in the Program.cs file if you use the built-in template to create a WinForms app.
I hope removing the redundant Main method from class Text may be enough to run the app successfully.
EDIT
In the Program.cs file, instantiate the Text class instead of Form1 like below:
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Text());
}
}
}
Also you need to enclose the class Text with the following namespace:
namespace WindowsFormsApplication1
{
public class Text : Form
{
// ...
}
}
EDIT 2:
Please override the Dispose() method inside class Form1 like below:
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

Related

How do i change the easy tabs page title to webBrowser1.DocumentTitle Reupload

This is what it should look like:
https://i.stack.imgur.com/j7jks.png
This is what it should look like 2nd Picture:
https://i.stack.imgur.com/v2k3k.png
Program.cs
using EasyTabs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Luke_Browser_Beta_Retry_2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppContainer container = new AppContainer();
container.Tabs.Add(
new TitleBarTab(container)
{
Content = new frmBrowser
{
Text = "New Tab"
}
}
);
container.SelectedTabIndex = 0;
TitleBarTabsApplicationContext applicationContext = new TitleBarTabsApplicationContext();
applicationContext.Start(container);
Application.Run(applicationContext);
}
}
}
Heres my attempt
Content.Text = webBrowser1.DocumentTitle + | + New Tab;
So someone pls help me fix this I wanna make a really cool browser!

winform doesn't apear when code is run

i'm building a quick and dirty program to basically turn on a light in my room from a website as a code kata. during the programming i decided i would temporarily use a winform to test instead of hooking the physical light up (and having all sorts of possible problems there). but when i run my program the winform doesn't show, I've tried to run the executable but still nothing. when debugging i can see all the code works fine it's just that the winform doesn't show up. here is all the code:
form1.cs:
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace alarm_light_test
{
public partial class Form1 : Form
{
WebClient client = new WebClient();
public Form1()
{
InitializeComponent();
while (true)
{
if (CheckData())
{
TurnSirenOn();
client.DownloadString("**link to .php file to reset the .txt file**");
Thread.Sleep(5000);
TurnSirenOff();
}
else
{
Thread.Sleep(1000);
}
}
}
public bool CheckData()
{
bool retval = false;
Stream stream = client.OpenRead("**link to online .txt file**");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
if(content == "1")
{
retval = true;
}
return retval;
}
public void TurnSirenOn()
{
pictureBox1.BackColor = Color.Green;
}
public void TurnSirenOff()
{
pictureBox1.BackColor = Color.Red;
}
}
}
program.cs:
using System;
using System.Windows.Forms;
namespace alarm_light_test
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.Designer.cs
namespace alarm_light_test
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(13, 13);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(235, 235);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(260, 260);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
}
}
In your constructor public Form1(), you have a loop for-ever (a.k.a an infinite loop).
The while(true) will prevent the constructor from finishing the construction of the form object, and therefore will not be able to display anything.
public Form1()
{
InitializeComponent();
while (true) // This loop will never exit, and will run forever
{
...
}
}
Edit: Sample of how to run your code Asynchronously, therefore allowing the form to fully initialise and display as expected.
public Form1()
{
InitializeComponent();
DoWorkAsynchronously();
}
private async Task DoWorkAsynchronously()
{
await Task.Run(() =>
{
while (true)
{
if (CheckData())
{
TurnSirenOn();
client.DownloadString("**link to .php file to reset the .txt file**");
Thread.Sleep(5000);
TurnSirenOff();
}
else
{
Thread.Sleep(1000);
}
}
});
}

Use program class from my dynamically compiled form

I have a class that Read/Write from registry. But how can i use this class from dynamically compiled form. I can execute function and even get var valuables from dynamically compiled form, but how can i execute my program function or get var valuable from my dynamically compiled form.
RegistryHelper class
using Microsoft.Win32;
namespace myForm
{
class RegistryHelper
{
public void WriteKey(string k, string value)
{
RegistryKey key = Registry.CurrentUser.CreateSubKey("rGO");
key.SetValue(k, value);
key.Close();
}
public string ReadKey(string k)
{
RegistryKey op = Registry.CurrentUser.OpenSubKey("rGO");
return (string)op.GetValue(k);
}
}
}
Example where i execute test function inside Form1 class
using System;
using System.CodeDom.Compiler;
using System.IO;
using Microsoft.CSharp;
namespace myForm
{
class Program
{
static void Main(string[] args)
{
using (var foo = new CSharpCodeProvider())
{
var parameters = new CompilerParameters
{
GenerateInMemory = true,
GenerateExecutable = false
};
parameters.ReferencedAssemblies.Add("System.dll");
parameters.ReferencedAssemblies.Add("System.Core.dll");
parameters.ReferencedAssemblies.Add("System.Drawing.dll");
parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
var source = File.ReadAllText("form.txt");
CompilerResults results = foo.CompileAssemblyFromSource(parameters, source);
Type type = results.CompiledAssembly.GetType("myForm.Form1");
object compiledObject = Activator.CreateInstance(type);
// Execure test function from dynamically compiled form
type.GetMethod("test").Invoke(compiledObject, new object[] { });
}
}
}
}
form.txt source
using System.Windows.Forms;
namespace myForm
{
public partial class Form1 : Form
{
public static int _testVar = 0; // how can i get this var value?
public Form1()
{
InitializeComponent();
}
public void test()
{
MessageBox.Show("test");
}
}
}
namespace myForm
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(12, 12);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(260, 204);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 222);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(260, 40);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 274);
this.Controls.Add(this.button1);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button1;
}
}
To do this, you just need to add a reference to itself in the references compiled code:
using System;
using System.CodeDom.Compiler;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.CSharp;
namespace ConsoleApplication212
{
class Program
{
static void Main(string[] args)
{
//dynamic code
var source = #"
static class Program
{
public static void Start()
{
//We call the Test method of the class Console Application 212.Helper
ConsoleApplication212.Helper.Test();
}
}";
//compile and run
Run(source);
Console.ReadLine();
}
static void Run(string source)
{
using (var provider = new CSharpCodeProvider())
{
var parameters = new CompilerParameters { GenerateInMemory = true };
parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
//link your self
parameters.ReferencedAssemblies.Add(Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase));
//compile
var result = provider.CompileAssemblyFromSource(parameters, source);
if (result.Errors.Count > 0)
throw new Exception(result.Errors[0].ErrorText);
//Find class Program
var type = result.CompiledAssembly.GetType("Program");
//вызыаем метод Start
type.GetMethod("Start").Invoke(null, null);
}
}
}
/// <summary>
/// Public class that will be used in dynamically compiled code
/// </summary>
public static class Helper
{
public static void Test()
{
MessageBox.Show("Hi from Helper");
}
}
}

Windows Forms and Background Images

I'm using SlimDX to render to a Windows Panel within a form using Visual C# Express. SlimDX derives a class from System.Windows.Forms.Form called SlimDX.Windows.RenderForm. I need to use this class in order to handle the windows message loop. I in turn must derive a class from SlimDX.Windows.RenderForm in order to add controls. My derived class looks like this:
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;
using SlimDX;
using SlimDX.Windows;
namespace SceneGenerator
{
public partial class ApplicationForm : RenderForm
{
public ApplicationForm() { }
public ApplicationForm( string text )
{
InitializeComponent();
this.Text = text;
}
public Panel GetViewport() { return this.ViewportPanel; }
}
}
Now though my background image does not show up in Visual C# environment( nor during runtime ). The background image is set in the usual InitializeComponent() function of the base class...Here are my designer and entry point codes:
namespace SceneGenerator
{
partial class ApplicationForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ApplicationForm));
this.ViewportPanel = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// ViewportPanel
//
this.ViewportPanel.Location = new System.Drawing.Point(410, 12);
this.ViewportPanel.Name = "ViewportPanel";
this.ViewportPanel.Size = new System.Drawing.Size(475, 345);
this.ViewportPanel.TabIndex = 0;
//
// ApplicationForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(897, 788);
this.Controls.Add(this.ViewportPanel);
this.DoubleBuffered = true;
this.Name = "ApplicationForm";
this.Text = "ApplicationForm";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel ViewportPanel;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using SlimDX.Windows;
using SlimDX.Direct3D9;
using Device = SlimDX.Direct3D9.Device;
using Resource = SlimDX.Direct3D9.Resource;
namespace SceneGenerator
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
// form
var form = new ApplicationForm("Scene Generator");
Panel viewportPanel = form.GetViewport();
// device
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, viewportPanel.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
{
BackBufferWidth = viewportPanel.Width,
BackBufferHeight = viewportPanel.Height
});
MessagePump.Run(form, () =>
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Green, 1.0f, 0);
device.BeginScene();
device.EndScene();
device.Present();
});
}
}
}
Why might this occur? Seems related to Visual C# Express and my lack of instructions to use the background image...
This is a problem caused by this RenderForm class. It overrides the OnPaintBackground() method and does nothing. So you don't see the BackgroundImage, you don't see BackColor either. You do get interesting LSD-style psychedelic effects in the designer. You can fix thix by writing your own:
protected override void OnPaintBackground(PaintEventArgs e) {
if (this.BackgroundImage != null) {
e.Graphics.DrawImage(this.BackgroundImage, this.DisplayRectangle);
}
}
But you'd better work from the assumption that this was done intentionally to solve some kind of drawing interference problem. Which you'll probably get back by using a Panel, you'd have to derive your own and in turn override its OnPaintBackground() method:
using System;
using System.Windows.Forms;
class RenderPanel : Panel {
protected override void OnPaintBackground(PaintEventArgs e) {
// Do nothing, like RenderForm
}
}
Might work, but this is pretty iffy stuff, not entirely uncommon for open source. This just doesn't look like it was made to do what you like to do. Best to avoid trouble and pass the form's Handle to the Device constructor.
Try referencing it as an external resource as in via a direct path or something. The way I'd try it is:
Environment.CurrentDirectory + #"\backgroundimage.png"
And if it still doesn't work like that one of two things might be happening.
Your background image is corrupt somehow
SlimDX might not accept BackgroundImages properly
Now I've never used SlimDX before so I'm not entirely sure on this but you could also try referencing it via the designer.

Hide form at launch

I have a program which only needs a NotifyIcon to work as intended. So I've been trying to get the main form to hide when the program starts.
In frmMain_Load, I tried both
this.Hide();
this.Visible = false;
without success.
They work in other methods, like in the NotifyIcon_MouseClick-method, but I want it to hide at Load.
I saw in another question here at SO where Matias suggested this:
BeginInvoke(new MethodInvoker(delegate
{
Hide();
}));
This works, but when I launch the program I can see the form flashing real fast. It's better than nothing, but I wonder if there is any better solution to this.
Thanks.
// In Your Program.cs Convert This
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
// To This
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 TheForm = new Form1();
Application.Run();
}
// Call Application.Exit() From Anywhere To Stop Application.Run() Message Pump and Exit Application
There is an easy way, if your program has the default Visual Studio generated Program.cs file:
[STAThread]
static void Main()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault (false);
Application.Run (new MainForm ());
}
the simple fact of calling Run will, indeed make the form visible. Try doing the following in the properties of your form:
Set WindowState to Minimized
Set ShowInTaskbar to false
This should do the trick!
Don't call Show or ShowDialog on your form, you can have your Application.Run target a custom class that then instantiates a form and doesn't show or creates a NotifyIcon instance and handles everything from there.
You can also put this.hide = true in the form_shown event. I believe that event is fired once only and after the load event. You might see alittle flicker though if your form has a lot of controls and/or the computer is slow.
If your program doesn't require a form to run, then the best method is to not have a form at all.
Setup your NotifyIcon in the Program code, and enter a loop until you want to exit the program by setting some value, or calling some method.
In this example setting UserExitCalled to true (Program.UserExitCalled = true) will cause the program to quit.
Here is a brief example:
static class Program {
internal static Boolean UserExitCalled;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Setup your tray icon here
while (!UserExitCalled) {
Application.DoEvents(); // Process windows messages
Thread.Sleep(1);
}
return;
}
}
Here the full program class from one of my system tray applications as a working example.
// *********************************************************************
// [DCOM Productions .NET]
// [DPDN], [Visual Studio Launcher]
//
// THIS FILE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND. ANY
// MODIFICATIONS TO THIS FILE IN ANY WAY ARE YOUR SOLE RESPONSIBILITY.
//
// [Copyright (C) DCOM Productions .NET All rights reserved.]
// *********************************************************************
namespace VisualStudioLauncher
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using VisualStudioLauncher.Common.Objects;
using VisualStudioLauncher.Forms;
using System.Drawing;
using VisualStudioLauncher.Common.Data;
using System.IO;
static class Program
{
#region Properties
private static ProjectLocationList m_ProjectLocationList;
/// <summary>
/// Gets or Sets the ProjectsLocationList
/// </summary>
public static ProjectLocationList ProjectLocationList
{
get
{
return m_ProjectLocationList;
}
set
{
m_ProjectLocationList = value;
}
}
private static ShellProcessList m_ShellProcessList = null;
/// <summary>
/// Gets or Sets the ShellProcessList
/// </summary>
public static ShellProcessList ShellProcessList
{
get
{
return m_ShellProcessList;
}
set
{
m_ShellProcessList = value;
}
}
private static NotifyIcon m_TrayIcon;
/// <summary>
/// Gets the programs tray application.
/// </summary>
public static NotifyIcon TrayIcon
{
get
{
return m_TrayIcon;
}
}
private static bool m_UserExitCalled;
/// <summary>
/// Gets a value indicating whether the user has called for an Application.Exit
/// </summary>
public static bool UserExitCalled
{
get
{
return m_UserExitCalled;
}
set
{
m_UserExitCalled = value;
}
}
// TODO: Finish implementation, then use this for real.
private static ApplicationConfiguration m_ApplicationConfiguration = null;
/// <summary>
/// Gets the application configuration
/// </summary>
public static ApplicationConfiguration ApplicationConfiguration
{
get
{
if (m_ApplicationConfiguration == null)
m_ApplicationConfiguration = ApplicationConfiguration.LoadConfigSection(#"./settings.config");
return m_ApplicationConfiguration;
}
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0].ToLower() == "-rmvptr")
{
for (int i = 1; i < args.Length; i++) {
try {
if (File.Exists(Application.StartupPath + #"\\" + args[i])) {
File.Delete(Application.StartupPath + #"\\" + args[i]);
}
}
catch { /* this isn't critical, just convenient */ }
}
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SplashForm splashForm = new SplashForm();
splashForm.Show();
while (!UserExitCalled)
{
Application.DoEvents();
Thread.Sleep(1);
}
if (m_TrayIcon != null)
{
m_TrayIcon.Icon = null;
m_TrayIcon.Visible = false;
m_TrayIcon.Dispose();
GC.Collect();
}
}
#region System Tray Management
public static void SetupTrayIcon()
{
m_TrayIcon = new NotifyIcon();
m_TrayIcon.Text = Resources.UserInterfaceStrings.ApplicationName;
m_TrayIcon.Visible = false; // This will be set visible when the context menu is generated
m_TrayIcon.MouseDoubleClick += new MouseEventHandler(m_TrayIcon_MouseDoubleClick);
if (Orcas.IsInstalled)
{
m_TrayIcon.Icon = Orcas.Icon;
}
else if (Whidbey.IsInstalled) {
m_TrayIcon.Icon = Whidbey.Icon;
}
else {
m_TrayIcon.Icon = SystemIcons.Warning;
m_TrayIcon.Text = "Visual Studio is not installed. VSL cannot run properly.";
}
}
static void m_TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
SettingsForm settingsForm = new SettingsForm();
settingsForm.Show();
}
#endregion
}
}

Categories

Resources