2009-06-18 11 views
6

संभव डुप्लिकेट:
Writing a Windows system tray application with .NETसी # में फॉर्म के बिना आवेदन कैसे करें?

हाय,
मैं नेट में एक आवेदन प्रोग्रामिंग कर रहा हूँ और मैं इसे एक विंडोज़ इंटरफ़ेस डाल करने के लिए नहीं करना चाहती।
मुझे कुछ समय पहले याद आया मैंने इसे एप्लिकेशन कॉन्टेक्स्ट क्लास से विरासत में प्राप्त किया था, लेकिन अब मैं इसे प्राप्त नहीं कर सकता।

मैं इसे कैसे कर सकता हूं?

धन्यवाद!

संपादित करें: यह है कि एक को सूचित आइकन द्वारा किया जाता है एक आवेदन पत्र है। यह सिस्टम घड़ी के पास आइकन दिखाई देना चाहिए, लेकिन एक फॉर्म नहीं। मैं यह कर रहा हूं:

class Sync : ApplicationContext 
{ 
    public Sync() 
    { 
     ... 
    } 
} 

[STAThread] 
static void Main() 
{ 
    Application.EnableVisualStyles(); 
    Application.SetCompatibleTextRenderingDefault(false); 
    Application.Run(new Sync()); 
} 
+0

आप किस प्रकार का एप्लीकेशन विकसित कर रहे हैं? कंसोल विंडो, विंडोज सेवा, पुस्तकालय? –

+2

डुप्लिकेट? http://stackoverflow.com/questions/995195/writing-a- विन्डोज़- सिस्टम-tray-plication-with-net – ChrisF

उत्तर

9

आप एक कंसोल एप्लिकेशन या सेवा या उस तरह के कुछ लिख सकते हैं। आप वास्तव में क्या करना चाहते हैं?

19

(अब है कि आप systray राज्य के लिए प्रश्न संपादित किया है अप्रचलित; संदर्भ के लिए छोड़ दिया है केवल)

आप किसी भी यूआई (यहां तक ​​कि एक सांत्वना नहीं) के बिना एक exe चाहते हैं, लेकिन बिना यह एक सेवा आदि किया जा रहा है - फिर एक विंडोज़ फॉर्म ऐप लिखें, लेकिन बस कोई फॉर्म न दिखाएं! तथ्य यह है कि यह एक Winform ऐप है इसका मतलब है कि आपको कंसोल विंडो नहीं मिलती है - लेकिन जो भी आप लिखते हैं उसे छोड़कर कोई UI दिखाया नहीं जाता है। मेरा मतलब यह देखने के लिए Main विधि (आमतौर पर वीएस टेम्पलेट्स में Program.cs में) देखें।

+0

इतना आसान है। बस फॉर्म को हटाएं और 'मुख्य() '-code को प्रतिस्थापित करें। इसके लिए धन्यवाद! – C4u

1

यहाँ देखें: http://bluehouse.wordpress.com/2006/01/24/how-to-create-a-notify-icon-in-c-without-a-form/

संपादित करें: इस उत्तर के मामले में कड़ी मर जाता है के लिए लिंक में कोड गयी। क्रेडिट इस कोड के लिए लेखक के पास जाता है।

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Text; 
using System.Windows.Forms; 
using System.ComponentModel; 
using System.Drawing; 

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; 
    } 
} 

class MainEntryClass 
{ 
    static void Main(string[] args) 
    { 
     SomeClass sc = new SomeClass(); 
     Application.Run(); 
    } 
} 

class SomeClass 
{ 
    ControlContainer container = new ControlContainer(); 
    private System.Windows.Forms.NotifyIcon notifyIcon1; 

    public SomeClass() 
    { 
     this.notifyIcon1 = new NotifyIcon(container); 
    } 
} 
संबंधित मुद्दे