2009-03-17 12 views
11

मैंने अपने ऐप में एक नोटिफ़िक आइकन जोड़ा है, और अक्सर मैं अपने सिस्ट्रे में अधिसूचना आइकन की 3 प्रतियां देखता हूं। क्या इसका कोई कारण है?मैं एकाधिक सिस्ट्रे आइकन क्यों देख रहा हूं?

ऐसा होने से रोकने का एक तरीका है।

अक्सर यह मेरे ऐप बंद होने के बाद बनी रहती है, जब तक कि मैं सिस्ट्रे पर न जाता हूं और सिस्टे फैलता है और एसएनडी गिर जाता है तो वे सभी नापसंद होते हैं।

+0

आपने NotifyIcon कैसे जोड़ा? डिजाइनर या कोड में? – OregonGhost

+0

... और एप्लिकेशन के दौरान आप इसे कैसे हटाते हैं? –

+0

डिज़ाइनर और मैं इसे हटा नहीं सकता हूं? –

उत्तर

21

क्या यह आपके आवेदन को डिबग कर रहा है? यदि ऐसा है तो सिस्टम सिस्टम से आइकन को हटाने वाले संदेश केवल तभी भेजे जाते हैं जब एप्लिकेशन सामान्य रूप से बाहर निकलता है, यदि यह अपवाद के कारण समाप्त हो जाता है या क्योंकि आप इसे विजुअल स्टूडियो से समाप्त करते हैं तो आइकन तब तक रहेगा जब तक कि आप उस पर माउस न रखें।

+0

मुझे उन ऐप्स पर काम करने से नफरत है जिनमें सिस्ट्रे में आइकन हैं और उन्हें विजुअल स्टूडियो के साथ रोकना है। अगर मैं उन पर माउस नहीं डालता तो उनमें से दर्जनों के साथ समाप्त होता है। – Samuel

+6

हालांकि थोड़ी देर में आपकी बांह थोड़ी देर में चल रही है स्वस्थ हो सकती है: पी – Svish

+2

हाँ, लेकिन 24 इंच की मॉनिटर पर, यह माउस के लिए काफी यात्रा है। ;) – Samuel

9

आप पैरेंट विंडो के बंद ईवेंट का उपयोग करके आइकन को मार सकते हैं। यह मेरी WPF अनुप्रयोग में काम करता है, तब भी जब (मेरे मामले में 2010) दृश्य स्टूडियो में परीक्षण:

 parentWindow.Closing += (object sender, CancelEventArgs e) => 
     { 
      notifyIcon.Visible = false; 
      notifyIcon.Icon = null; 
      notifyIcon.Dispose(); 
     }; 
2

मैं क्या किया:

  1. कि सिस्टम ट्रे को अपडेट करता वर्ग पुस्तकालय बनाएँ।

    using System; 
    using System.Diagnostics; 
    using System.Runtime.InteropServices; 
    
    namespace SystrayUtil 
    { 
        internal enum MessageEnum 
        { 
         WM_MOUSEMOVE = 0x0200, 
         WM_CLOSE = 0x0010, 
        } 
    
        internal struct RECT 
        { 
         internal int Left; 
         internal int Top; 
         internal int Right; 
         internal int Bottom; 
    
         internal RECT(int left, int top, int right, int bottom) 
         { 
          Left = left; 
          Top = top; 
          Right = right; 
          Bottom = bottom; 
         } 
        } 
    
        public sealed class Systray 
        { 
         [DllImport("user32.dll", SetLastError = true)] 
         private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 
    
         [DllImport("user32.dll", SetLastError = true)] 
         private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, IntPtr lpszWindow); 
    
         [DllImport("user32.dll", SetLastError = true)] 
         private static extern IntPtr SendMessage(IntPtr hWnd, int message, uint wParam, long lParam); 
    
         [DllImport("user32.dll", SetLastError = true)] 
         private static extern bool GetClientRect(IntPtr hWnd, out RECT usrTray); 
    
         public static void Cleanup() 
         { 
          RECT sysTrayRect = new RECT(); 
          IntPtr sysTrayHandle = FindWindow("Shell_TrayWnd", null); 
          if (sysTrayHandle != IntPtr.Zero) 
          { 
           IntPtr childHandle = FindWindowEx(sysTrayHandle, IntPtr.Zero, "TrayNotifyWnd", IntPtr.Zero); 
           if (childHandle != IntPtr.Zero) 
           { 
            childHandle = FindWindowEx(childHandle, IntPtr.Zero, "SysPager", IntPtr.Zero); 
            if (childHandle != IntPtr.Zero) 
            { 
             childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ToolbarWindow32", IntPtr.Zero); 
             if (childHandle != IntPtr.Zero) 
             { 
              bool systrayWindowFound = GetClientRect(childHandle, out sysTrayRect); 
              if (systrayWindowFound) 
              { 
               for (int x = 0; x < sysTrayRect.Right; x += 5) 
               { 
                for (int y = 0; y < sysTrayRect.Bottom; y += 5) 
                { 
                 SendMessage(childHandle, (int)MessageEnum.WM_MOUSEMOVE, 0, (y << 16) + x); 
                } 
               } 
              } 
             } 
            } 
           } 
          } 
         } 
        } 
    } 
    
  2. कॉपी "%ProgramFiles%\Microsoft Visual Studio x.x\Common7\IDE\PublicAssemblies\SystrayUtil.dll"

    को dll जहां xx दृश्य स्टूडियो की संस्करण संख्या

  3. रिकार्ड एक मैक्रो है और उसे सहेजें

  4. संपादित मैक्रो

    जोड़ें बनाए गए डीएलएल का संदर्भ।

    मॉड्यूल पर्यावरण एवेन्ट्स के शीर्ष पर आयात की सूची में Imports SystrayUtil जोड़ें।

    अवांछित आइटम निकालें और

    Public Sub DebuggerEvents_OnEnterDesignMode(ByVal Reason As EnvDTE.dbgEventReason) Handles DebuggerEvents.OnEnterDesignMode 
    Systray.Cleanup() 
    MsgBox("Entered design mode!") 
    End Sub 
    
  5. EnvironmentEvents मॉड्यूल के लिए निम्न कोड जोड़ने यह MsgBox("Entered design mode!") हटाने, क्योंकि यह एक संदेश बॉक्स आप एक डिबगिंग सत्र से लौटने हर समय पॉपिंग के लिए कष्टप्रद है काम करता है।

0

यह काम करना चाहिए जब आप सामान्य रूप से अनुप्रयोग बंद: जब आप दृश्य स्टूडियो बंद डिबग बटन से अनुप्रयोग रोक

// in form's constructor 
Application.ApplicationExit += new EventHandler(this.OnApplicationExit); 

private void OnApplicationExit(object sender, EventArgs e) 
{ 
    try 
    { 
     if (notifyIcon1!= null) 
     { 
      notifyIcon1.Visible = false; 
      notifyIcon1.Icon = null; 
      notifyIcon1.Dispose(); 
      notifyIcon1= null; 
     } 
    } 
    catch { } 
} 

- प्रक्रिया मार दिया जाता है और कोई निपटाने घटनाओं निकाल दिया जाता है।

संबंधित मुद्दे

 संबंधित मुद्दे