Click here to Skip to main content
15,908,841 members
Home / Discussions / C#
   

C#

 
AnswerRe: SQL Query Issue Pin
J4amieC19-Feb-09 3:28
J4amieC19-Feb-09 3:28 
Questionpasting data in datagridview possible..? Pin
Mubeen.asim19-Feb-09 2:54
Mubeen.asim19-Feb-09 2:54 
Questionhow to use treeview tool in C#.net? Pin
poonam jagdale19-Feb-09 2:46
poonam jagdale19-Feb-09 2:46 
AnswerRe: how to use treeview tool in C#.net? Pin
Calin Tatar19-Feb-09 3:05
Calin Tatar19-Feb-09 3:05 
Questionconnectivity with remote server Pin
Digubha19-Feb-09 2:41
Digubha19-Feb-09 2:41 
AnswerRe: connectivity with remote server Pin
poonam jagdale19-Feb-09 2:51
poonam jagdale19-Feb-09 2:51 
AnswerRe: connectivity with remote server Pin
Mubeen.asim19-Feb-09 2:56
Mubeen.asim19-Feb-09 2:56 
QuestionC# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
samskiter19-Feb-09 2:39
samskiter19-Feb-09 2:39 
Hey, first post here so sorry if im all over the place here. my previous experience is VB6 and picaxe chips! (lol: "goto main")

I have started my C# (2008) project and made some progress. At the minute i have 3 main classes: Program.cs, SerPort.cs (essentially input into the program) and Output.cs (output from the program). I can deal will the input and output alright, i have an event in serport.cs when data arrives, it grabs the data and sends it to a method in my output.cs that deals with it.

I started this project as a blank C# project as i dont need a form most of the time. I have added code into Program.cs to stick a notify icon in the notify area, fine. The right click menu of this notify icon has 'Exit' and 'Settings'. I have coded the exit event fine, but am having trouble with settings. I need it to open a form which i have made but i need it to do it so the user can only open it once (try right clicking the system clock and clicking properties twice - i want it to work like that)

im pretty new to C# and im picking up as i go along and the problem with showing the form seems to be that the method for the event is a static one (whatever static means), if i try and make it not static, i get an error in my Main method(which is also static), if i try and make my Main method not static it says there isnt a valid static main entry point - GRRR :P

im using this command at the minute: Form Setting = new Settings(); Setting.ShowDialog(); i understand that if i use this in the brackets of showdialog, it should make it modal, but for that my method needs to be non-static. basically i have nothing to own the form, so i can just open as many as i like!

my program is started by "Application.Run();" at the minute, should i make it like a project would be if it were started as a windows forms project and use "Application.Run(form);" and define my notify icon within the form, then hide the form until someone hits the "settings" button? is this bad practise to have the form sat there all the time it isnt being used? should i just stick an if statement before the ShowDialog command to check if the form is already there and activate it if it is (is this what happens when you right click the clock and click properties?)

thanks so much for any help and im sorry this is such an essay, ive just got so many questions and i dont know the conventions. after this is sorted i should be able to deal with the settings (so long as they work in a similar way to VB6 lol) and finish everything off

thanks, Sam

here is my current program.cs, (MediaCenterController is my output.cs):

namespace Video_Duke_Box
{
    class Program
    {
        public Thread trd;
        static void Main()
        {
            if (SerPort.OpenPort())
            {
                icn = new NotifyIcon();
                ContextMenuStrip menu = new ContextMenuStrip();
                icn.ContextMenuStrip = menu;

                ToolStripMenuItem COMMenuItem = new ToolStripMenuItem("COM Port", null, new EventHandler(COMMenuItem_Click));
                ToolStripMenuItem ExitMenuItem = new ToolStripMenuItem("Exit", null, new EventHandler(ExitMenuItem_Click));
                ToolStripSeparator separator = new ToolStripSeparator();
                menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { COMMenuItem, separator, ExitMenuItem });
                icn.Visible = true;
                icn.Icon = Properties.Resources.ehshell_IDI_APP1;
                icn.ShowBalloonTip(3000, "Connected", "Duke Box is Connected", ToolTipIcon.Info);
                //could add code for "not show this tooltip message in future"
                MediaCenterController MCC = new MediaCenterController();
                MCC.MediaStateChange += new MediaCenterController.MediaCenterHandler(SerPort.MediaCenter_Running);
                MCC.MediaStateChange += new MediaCenterController.MediaCenterHandler(MediaCenter_Running);
                Thread trd = new Thread(new ThreadStart(MCC.MediaCenterRunning));
                trd.IsBackground = true;
                trd.Start();
                Application.Run();
            }
            else
            {
                //could create an event for new ports detection
            }
        }

        static public void MediaCenter_Running(object MCRObject, MediaCenterEventArg state)
        {
            if (state.on)
            { icn.Icon = Properties.Resources.ehshell_IDI_APP2; }
            else
            { icn.Icon = Properties.Resources.ehshell_IDI_APP1; }
        }
        static void COMMenuItem_Click(object sender, EventArgs e)
        {
            //using (Form Settings = new Form()) { Settings.ShowDialog(); }
            //Settings.Modal.Equals(true);
            Form Setting = new Settings();
            Setting.ShowDialog();
            //Form.ShowDialog(new Settings());
            //MessageBox.Show("HELLO", "Settings");
        }
        static void ExitMenuItem_Click(object sender, EventArgs e)
        {
            icn.Dispose();
            SerPort.comport.Close();
            Application.Exit();
        }
        private System.Windows.Forms.NotifyIcon notifyIcon1;
        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
        private System.Windows.Forms.ToolStripMenuItem cOMPOrtToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;

        public ContextMenuStrip menu;

        class ControlContainer : IContainer
        {
            ComponentCollection _components;

            public ControlContainer()
            {
                _components = new ComponentCollection(new IComponent[] { });
            }

            public void Add(IComponent component)
            { }

            public void Add(IComponent component, string Name)
            { }

            public void Remove(IComponent component)
            { }

            public ComponentCollection Components
            {
                get { return _components; }
            }

            public void Dispose()
            {
                _components = null;
            }
        }
        public static NotifyIcon icn;
    }
}

AnswerRe: C# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
Rob Philpott19-Feb-09 3:14
Rob Philpott19-Feb-09 3:14 
GeneralRe: C# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
samskiter19-Feb-09 3:33
samskiter19-Feb-09 3:33 
GeneralRe: C# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
Rob Philpott19-Feb-09 3:46
Rob Philpott19-Feb-09 3:46 
GeneralRe: C# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
samskiter19-Feb-09 5:44
samskiter19-Feb-09 5:44 
GeneralRe: C# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
Rob Philpott19-Feb-09 6:34
Rob Philpott19-Feb-09 6:34 
GeneralRe: C# program structuring problem - Run in background - Teach a noob to do it properly :P Pin
samskiter19-Feb-09 6:57
samskiter19-Feb-09 6:57 
Questionhow to drag and drop image in c#.net & how to resize it after drop the image? Pin
poonam jagdale19-Feb-09 2:32
poonam jagdale19-Feb-09 2:32 
AnswerRe: how to drag and drop image in c#.net & how to resize it after drop the image? Pin
Calin Tatar19-Feb-09 2:37
Calin Tatar19-Feb-09 2:37 
QuestionMin (110) must be less than or equal to max (-1) in a Range object. Pin
Priya Prk19-Feb-09 2:01
Priya Prk19-Feb-09 2:01 
GeneralRe: Min (110) must be less than or equal to max (-1) in a Range object. Pin
Luc Pattyn19-Feb-09 2:13
sitebuilderLuc Pattyn19-Feb-09 2:13 
AnswerRe: Min (110) must be less than or equal to max (-1) in a Range object. Pin
michal.drozdowicz23-Mar-09 5:03
michal.drozdowicz23-Mar-09 5:03 
QuestionCompare two .DAT file using C# Pin
Member 322226419-Feb-09 1:52
Member 322226419-Feb-09 1:52 
AnswerRe: Compare two .DAT file using C# Pin
Luc Pattyn19-Feb-09 2:20
sitebuilderLuc Pattyn19-Feb-09 2:20 
Questioncreating a setup file Pin
aratireddy19-Feb-09 1:26
aratireddy19-Feb-09 1:26 
AnswerRe: creating a setup file Pin
Ramkithepower19-Feb-09 1:38
Ramkithepower19-Feb-09 1:38 
GeneralRe: creating a setup file Pin
Calin Tatar19-Feb-09 1:52
Calin Tatar19-Feb-09 1:52 
AnswerRe: creating a setup file Pin
Nuri Ismail19-Feb-09 2:20
Nuri Ismail19-Feb-09 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.