quelqu'un peut-il s'il vous plaît suggérer un bon exemple de code de vb.net/c# code pour mettre l'application dans la barre d'état système lors de la miniaturisation.comment mettre une application .net dans la barre d'état système lorsque minimisé?
Répondre
Ajouter un contrôle NotifyIcon à votre formulaire, puis utilisez le code suivant:
private void frm_main_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.Hide();
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
notifyIcon1.Visible = false;
}
Vous ne pouvez pas besoin de définir la propriété ShowInTaskbar.
Vous pouvez tirer parti d'un contrôle intégré appelé NotifyIcon. Cela crée une icône de plateau lorsqu'il est affiché. @Phillip a un exemple de code qui est quelque peu complet.
Il y a un Gotcha si:
Vous devez remplacer vos applications principale méthode Dispose de formulaire pour appeler Dispose sur NotifyIcon, sinon il restera dans la barre après la sortie de l'application.
public void Form_Dispose(object sender, EventArgs e)
{
if (this.Disposing)
notifyIcon1.Dispose();
}
Quelque chose comme ça.
Merci pour une pièce manquante. – bugBurger
Cela ne devrait pas être nécessaire si vous mettez l'icône notifier sur le formulaire en utilisant le concepteur - le Dispose() généré par VS appellera components.Dispose() qui doit disposer tous les composants qui ont été créés avec lui en tant que conteneur. –
Vous pouvez le faire en ajoutant un NotifyIcon à votre formulaire et en gérant l'événement de redimensionnement du formulaire. Pour revenir à partir du bac gérer l'événement double-cliquez NotifyIcon.
Si vous voulez ajouter un peu d'animation, vous pouvez le faire aussi ...
1) Ajouter le module suivant:
Module AnimatedMinimizeToTray
Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Structure APPBARDATA
Public cbSize As Integer
Public hWnd As IntPtr
Public uCallbackMessage As Integer
Public uEdge As ABEdge
Public rc As RECT
Public lParam As IntPtr
End Structure
Enum ABMsg
ABM_NEW = 0
ABM_REMOVE = 1
ABM_QUERYPOS = 2
ABM_SETPOS = 3
ABM_GETSTATE = 4
ABM_GETTASKBARPOS = 5
ABM_ACTIVATE = 6
ABM_GETAUTOHIDEBAR = 7
ABM_SETAUTOHIDEBAR = 8
ABM_WINDOWPOSCHANGED = 9
ABM_SETSTATE = 10
End Enum
Enum ABNotify
ABN_STATECHANGE = 0
ABN_POSCHANGED
ABN_FULLSCREENAPP
ABN_WINDOWARRANGE
End Enum
Enum ABEdge
ABE_LEFT = 0
ABE_TOP
ABE_RIGHT
ABE_BOTTOM
End Enum
Public Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As Integer
Public Const ABM_GETTASKBARPOS As Integer = &H5&
Public Const WM_SYSCOMMAND As Integer = &H112
Public Const SC_MINIMIZE As Integer = &HF020
Public Sub AnimateWindow(ByVal ToTray As Boolean, ByRef frm As Form, ByRef icon As NotifyIcon)
' get the screen dimensions
Dim screenRect As Rectangle = Screen.GetBounds(frm.Location)
' figure out where the taskbar is (and consequently the tray)
Dim destPoint As Point
Dim BarData As APPBARDATA
BarData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(BarData)
SHAppBarMessage(ABMsg.ABM_GETTASKBARPOS, BarData)
Select Case BarData.uEdge
Case ABEdge.ABE_BOTTOM, ABEdge.ABE_RIGHT
' Tray is to the Bottom Right
destPoint = New Point(screenRect.Width, screenRect.Height)
Case ABEdge.ABE_LEFT
' Tray is to the Bottom Left
destPoint = New Point(0, screenRect.Height)
Case ABEdge.ABE_TOP
' Tray is to the Top Right
destPoint = New Point(screenRect.Width, 0)
End Select
' setup our loop based on the direction
Dim a, b, s As Single
If ToTray Then
a = 0
b = 1
s = 0.05
Else
a = 1
b = 0
s = -0.05
End If
' "animate" the window
Dim curPoint As Point, curSize As Size
Dim startPoint As Point = frm.Location
Dim dWidth As Integer = destPoint.X - startPoint.X
Dim dHeight As Integer = destPoint.Y - startPoint.Y
Dim startWidth As Integer = frm.Width
Dim startHeight As Integer = frm.Height
Dim i As Single
For i = a To b Step s
curPoint = New Point(startPoint.X + i * dWidth, startPoint.Y + i * dHeight)
curSize = New Size((1 - i) * startWidth, (1 - i) * startHeight)
ControlPaint.DrawReversibleFrame(New Rectangle(curPoint, curSize), frm.BackColor, FrameStyle.Thick)
System.Threading.Thread.Sleep(15)
ControlPaint.DrawReversibleFrame(New Rectangle(curPoint, curSize), frm.BackColor, FrameStyle.Thick)
Next
If ToTray Then
' hide the form and show the notifyicon
frm.Hide()
icon.Visible = True
Else
' hide the notifyicon and show the form
icon.Visible = False
frm.Show()
End If
End Sub
End Module
2) Ajouter un NotifyIcon à votre formulaire d'ajouter ce qui suit :
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32() = SC_MINIMIZE Then
AnimateWindow(True, Me, NotifyIcon1)
Exit Sub
End If
MyBase.WndProc(m)
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
AnimateWindow(False, Me, NotifyIcon1)
End Sub
- 1. Comment mettre une barre de menu dans une application
- 2. Mettre un programme dans la barre d'état système au démarrage
- 3. Comment afficher une application réduite dans la barre Applications en cours dans Windows Mobile?
- 4. Comment mettre à jour une barre de progression OnSelectedIndexChanged?
- 5. Mettre un NSPopUpButton dans une barre NSTool
- 6. Masquage de la boîte de dialogue au démarrage pour une application de la barre d'état système
- 7. Application de barre d'état système .NET à lancer lorsqu'un périphérique USB est branché
- 8. Comment puis-je énumérer des objets dans la barre d'état système Windows dans .Net?
- 9. Définir le système sur mon application
- 10. Comment trouver l'emplacement de l'icône dans la barre d'état système
- 11. Avoir l'application de minimiser à la barre d'état système lorsque le bouton est cliqué?
- 12. Comment faire pour afficher une application Windows Forms .NET en tant qu'icône de barre d'état?
- 13. PyQt: Afficher le menu dans une application de barre d'état système
- 14. Comment masquer le formulaire pour que l'application affiche uniquement une icône dans la barre d'état système?
- 15. Empêche l'icône de la barre d'état système de dérober le focus lorsque vous cliquez sur
- 16. Comment changer XIB dans une application de barre d'onglets?
- 17. Excel COM - .NET COM AddIn se comporte différemment lorsque Excel est incorporé dans une application
- 18. instance unique et notifier dans la barre d'état système
- 19. comment faire autostart lorsque le système redémarre
- 20. Comment joindre mon application dans une autre application .Net?
- 21. Comment puis-je accéder à la barre de progression dans la barre d'état d'une application Office?
- 22. Ajouter une barre de progression dans la barre de navigation
- 23. Restaurer WindowState à partir de minimisé
- 24. Comment puis-je faire afficher mon service Windows dans la barre d'état système?
- 25. Comment afficher le texte dans l'icône de la barre d'état système avec l'API win32?
- 26. Comment mettre à jour la date du système et/ou du temps en utilisant .NET
- 27. Comment masquer une clé de chiffrement dans une application .NET?
- 28. Comment puis-je faire clignoter la barre des tâches à partir d'une application .NET partiellement approuvée?
- 29. Comment profiler une application lorsque l'exécution différée le rend difficile?
- 30. Comment puis-je partager la configuration de l'application dans une application .net?
Cela semble être un double de http://stackoverflow.com/questions/46918/whats-the-proper-way-to-minimize-to-tray-ac-winforms-app. –