Hi,
Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference that I require (masterForm) where as method 1 doesn't.
Any Ideas Anyone?
Method 1:
class FormHandler
{
public void ShowForm()
{
Application.Run(new MasterForm());
}
}
Method 2:
class FormHandler
{
private static MasterForm masterForm = new MasterForm();
public void ShowForm()
{
Application.Run(masterForm);
}
}
Thanx Josh 3 2258
What NotifyIcon? Since we don't know how your form is coded, we'll need more information (like revelant parts of source code).
-mike
MVP
"Joshua Russell" <jo**@ojmyster.uk.eu.org> wrote in message news:Ou**************@TK2MSFTNGP11.phx.gbl...
Hi,
Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference that I require (masterForm) where as method 1 doesn't.
Any Ideas Anyone?
Method 1:
class FormHandler
{
public void ShowForm()
{
Application.Run(new MasterForm());
}
}
Method 2:
class FormHandler
{
private static MasterForm masterForm = new MasterForm();
public void ShowForm()
{
Application.Run(masterForm);
}
}
Thanx Josh
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Threading_Server_WF
{
/// <summary>
/// Summary description for Master.
/// </summary>
public class MasterForm : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.ContextMenu notifyContext;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.Label label3;
private System.ComponentModel.IContainer components;
public MasterForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(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.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MasterForm ));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.notifyContext = new System.Windows.Forms.ContextMenu();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pict ureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(48, 48);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(80, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Mithril Server";
//
// label2
//
this.label2.Location = new System.Drawing.Point(80, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 2;
this.label2.Text = "Version 1.0 Beta";
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.notifyContext;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notify Icon1.Icon")));
this.notifyIcon1.Text = "Mithril Server";
this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// notifyContext
//
this.notifyContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4,
this.menuItem5});
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "Show Info";
this.menuItem4.Click += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.Text = "Close Server";
this.menuItem5.Click += new System.EventHandler(this.menuItem3_Click);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3});
this.menuItem1.Text = "Main";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Hide";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "Close Server";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(80, 56);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(104, 16);
this.label3.TabIndex = 3;
this.label3.Text = "Active Sessions: 0";
//
// MasterForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(208, 83);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label3,
this.label2,
this.label1,
this.pictureBox1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.Name = "MasterForm";
this.ShowInTaskbar = false;
this.Text = "Mithril Server";
this.Activated += new System.EventHandler(this.MasterForm_Activated);
this.ResumeLayout(false);
}
#endregion
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg != 0x0010)
{
base.WndProc(ref m);
}
else
{
this.WindowState = FormWindowState.Minimized;
}
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
// Show the form when the user double clicks on the notify icon.
// Set the WindowState to normal if the form is minimized.
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
// Activate the form.
this.Activate();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
// Clearup
this.notifyIcon1.Visible = false;
// Exit
Environment.Exit(0);
}
private void MasterForm_Activated(object sender, System.EventArgs e)
{
WorkerThreadHandler threadHandler = new WorkerThreadHandler();
int count = threadHandler.sessionCount();
this.label3.Text = "Active Sessions: " + count.ToString();
}
}
/// <summary>
/// Summary description for Master.
/// </summary>
public class MasterForm : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.ContextMenu notifyContext;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.Label label3;
private System.ComponentModel.IContainer components;
public MasterForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(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.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MasterForm ));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.notifyContext = new System.Windows.Forms.ContextMenu();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pict ureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(48, 48);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(80, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Mithril Server";
//
// label2
//
this.label2.Location = new System.Drawing.Point(80, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 2;
this.label2.Text = "Version 1.0 Beta";
//
// notifyIcon1
//
this.notifyIcon1.ContextMenu = this.notifyContext;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notify Icon1.Icon")));
this.notifyIcon1.Text = "Mithril Server";
this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// notifyContext
//
this.notifyContext.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4,
this.menuItem5});
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "Show Info";
this.menuItem4.Click += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.Text = "Close Server";
this.menuItem5.Click += new System.EventHandler(this.menuItem3_Click);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3});
this.menuItem1.Text = "Main";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Hide";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "Close Server";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(80, 56);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(104, 16);
this.label3.TabIndex = 3;
this.label3.Text = "Active Sessions: 0";
//
// MasterForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(208, 83);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label3,
this.label2,
this.label1,
this.pictureBox1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.Name = "MasterForm";
this.ShowInTaskbar = false;
this.Text = "Mithril Server";
this.Activated += new System.EventHandler(this.MasterForm_Activated);
this.ResumeLayout(false);
}
#endregion
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg != 0x0010)
{
base.WndProc(ref m);
}
else
{
this.WindowState = FormWindowState.Minimized;
}
}
private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
// Show the form when the user double clicks on the notify icon.
// Set the WindowState to normal if the form is minimized.
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
// Activate the form.
this.Activate();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
// Clearup
this.notifyIcon1.Visible = false;
// Exit
Environment.Exit(0);
}
private void MasterForm_Activated(object sender, System.EventArgs e)
{
WorkerThreadHandler threadHandler = new WorkerThreadHandler();
int count = threadHandler.sessionCount();
this.label3.Text = "Active Sessions: " + count.ToString();
}
}
}
"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message news:ue**************@TK2MSFTNGP10.phx.gbl...
What NotifyIcon? Since we don't know how your form is coded, we'll need more information (like revelant parts of source code).
-mike
MVP
"Joshua Russell" <jo**@ojmyster.uk.eu.org> wrote in message news:Ou**************@TK2MSFTNGP11.phx.gbl...
Hi,
Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference that I require (masterForm) where as method 1 doesn't.
Any Ideas Anyone?
Method 1:
class FormHandler
{
public void ShowForm()
{
Application.Run(new MasterForm());
}
}
Method 2:
class FormHandler
{
private static MasterForm masterForm = new MasterForm();
public void ShowForm()
{
Application.Run(masterForm);
}
}
Thanx Josh
Sorry, I meant *relevant* parts of source code. Can you show us your problem without pasting 451 lines of code?
-mike
MVP
"Joshua Russell" <jo**@ojmyster.uk.eu.org> wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl...
using System;
<snip>
}
"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message news:ue**************@TK2MSFTNGP10.phx.gbl...
What NotifyIcon? Since we don't know how your form is coded, we'll need more information (like revelant parts of source code).
-mike
MVP
"Joshua Russell" <jo**@ojmyster.uk.eu.org> wrote in message news:Ou**************@TK2MSFTNGP11.phx.gbl...
Hi,
Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of master form. Method 2 opens the form but when I right click on the Notify Icon I don't get the context menu that I should be seeing. I can interact with the main form window but I cannot interact with the NotifyIcon. Method 2 gives a object reference that I require (masterForm) where as method 1 doesn't.
Any Ideas Anyone?
Method 1:
class FormHandler
{
public void ShowForm()
{
Application.Run(new MasterForm());
}
}
Method 2:
class FormHandler
{
private static MasterForm masterForm = new MasterForm();
public void ShowForm()
{
Application.Run(masterForm);
}
}
Thanx Josh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eric Janzen |
last post by:
This is a very frustrating problem.
We have installed Developer Suite 10g on 4 machines. The Development suite
is in one Oracle home directory. On the same machines we also have a 9i
database...
|
by: James Fortune |
last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't
understand why people who know how to write code to completely replace
a front end do not write something that will automate...
|
by: Brian Keating EI9FXB |
last post by:
I wonder can anyone reccomment a solution to this problem.
Let me explain, I've services running on my system, my
application receives diagnostic messages from these services, what i want to
do...
|
by: Joshua Kendall |
last post by:
I have a script in which it keeps opening the same form
instead of only one instance. I also need help with a
form that has a password. Where do I put the actual
password? can I use a database for...
|
by: Jeff |
last post by:
I'm getting an Object Reference error before I even run my app, and
I'm not sure where to look to find the cause. I'd appreciate your
help.
When I open my Windows Application project, the...
|
by: question |
last post by:
Hi!
I have a requirement where I need to display multiple forms one after
the other like a slide show. These are in the same application.
Basicall on selection of a menu item it should start...
|
by: tshad |
last post by:
What would be a good way to check programmatically whether a service was
running?
We have a service that dies periodically and I need to check to see if this
service is running. I know how to...
|
by: esakal |
last post by:
Hello,
I'm programming an application based on CAB infrastructure in the
client side (c# .net 2005)
Since my application must be sequencally, i wrote all the code in the
UI thread.
my...
|
by: Academic |
last post by:
I have a MDI form, sometimes child forms and sometimes forms that are
neither
If I close the app the child forms closing and closed event happens followed
by the Mdi form receiving the...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |