473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Running Forms

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

Nov 15 '05 #1
3 2257
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

Nov 15 '05 #2
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

Nov 15 '05 #3
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

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
19
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...
14
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...
15
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...
2
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...
0
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...
4
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...
9
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...
13
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.