Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1550 | Anzahl registrierter User: 1841 | Besucher online: 15
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Fenster am Bildschirmrand andocken


Autor: Xqgene
Sprache: C#
Bewertung:
5.44 (2 votes)
Anzahl der Aufrufe: 10845
  
Kick it on dotnet-kicks.de  

Beschreibung:

Das Beispiel reserviert 100 Pixel Desktop Platz (oben) und positioniert das aktuelle Form in diesem Bereich

Abgelegt unter: AppBar, Andocken, Docken, Fenster, Rand, Bildschirmrand.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
    /// <sumary>
    /// Beinhaltet Information über die Application Bar.
    /// Eine ausführliche Beschreibung finden Sie in MSDN APPBARDATA Dokumentation.
    /// </sumary> 
    [StructLayout(LayoutKind.Sequential)]
    public struct APPBARDATA
    {
        public uint cbSize;
        public IntPtr hWnd;
        public uint uCallbackMessage;
        public uint uEdge;
        public RECT rc;
        public int lParam;
    }
    /// <sumary>
    /// Speichert Größe und Position der AppBAr.
    /// </sumary>
    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }
    public partial class Form1 : Form
    {
        const int ABM_NEW         = 0x00000000;
        const int ABM_REMOVE      = 0x00000001;
        const int ABM_SETPOS      = 0x00000003;
        const int ABM_QUERYPOS    = 0x00000002;

        const int ABE_TOP = 1;

        public Form1()
        {
            InitializeComponent();
            FormBorderStyle = FormBorderStyle.SizableToolWindow;
        }
        /// <sumary>
        /// OnLoad wird überschrieben, um die ApplicationBar zu initialisieren.
        /// Dabei wird am oberen Rand des Desktops ein Bereich reserviert, in dem das Fenster dann platziert wird.
        /// </sumary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Datenstruktur für AppBar erzeugen und initialisieren.
            APPBARDATA abd = new APPBARDATA();
            abd.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA));
            abd.hWnd = this.Handle;
            abd.uCallbackMessage = RegisterWindowMessage(Guid.NewGuid().ToString()); 

            // AppBar beim System registrieren.
            SHAppBarMessage(ABM_NEW, ref abd);

            // Größe und Position festlegen.
            // In dem Beispiel wird oben am Desktop 100 Pixel Platz reserviert.
            abd.rc = new RECT();
            abd.uEdge = ABE_TOP;
            abd.rc.top = 0;
            abd.rc.left = 0;
            abd.rc.bottom = 100;
            abd.rc.right = SystemInformation.PrimaryMonitorSize.Width;

            // Die Gröse und Position der AppBar prüfen.
            // Wenn diese nicht gültig sind, werden die 
            // korrigierte Werte zurückgegeben.
            SHAppBarMessage(ABM_QUERYPOS, ref abd);
            // Größe und Position der AppBarsetzen
            SHAppBarMessage(ABM_SETPOS, ref abd);
            // Größe und Position des Anwendungsfenster im AppBar Bereich positionieren
            Location = new Point(abd.rc.left, abd.rc.top);
            Size = new Size(abd.rc.right, abd.rc.bottom);
        }

        /// <sumary>
        /// Beim Beenden des Programms wieder aufräumen.
        /// </sumary>
        protected override void OnClosed(EventArgs e)
        {
            APPBARDATA abd = new APPBARDATA();
            abd.cbSize = (uint)Marshal.SizeOf(typeof(APPBARDATA));
            abd.hWnd = this.Handle;

            SHAppBarMessage(ABM_REMOVE, ref abd);
            
            base.OnClosed(e);
        }
        [DllImport("shell32.dll")]
        static extern IntPtr SHAppBarMessage(uint dwMessage,
           ref APPBARDATA pData);
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern uint RegisterWindowMessage(string lpString);
    }
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)

Rainbird schrieb am:  05.11.2006 12:27:34

Bei so einem komplexen Snippet, sollten Kommentare und XML-Doku-Tags nicht fehlen.
crokale schrieb am:  20.10.2010 22:34:04

Bei mir wird die Form nicht in dem neuen erzeugtem Bereich angezeigt sondern ist im desktop zu sehe. Wo ran liegt das?


schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.