Autor Beitrag
JohnDyr
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56
Erhaltene Danke: 1

Win 10
C# (VS 2017)
BeitragVerfasst: Sa 29.12.18 21:27 
Moin Community,

ich möchte für meine Anwendung nur zwei Window States erlauben: Minimiert und Maximiert. Kein Fenstermodus. Kriege ich das mit "normalen" Mitteln hin? Notfalls würde ich mir mit einem UserControl eine eigene "Top" Leiste bauen, wo ich dann nur diese beiden Buttons implementiere.
Yankyy02
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 138
Erhaltene Danke: 21

Win 11 x64
C# (VS 2022 - Rider)
BeitragVerfasst: Sa 29.12.18 23:41 
Hallo,

ich würde in den Einstellungen des Forms-Designers folgende Properties setzen:

SizeGripStyle = Hide
FormBorderStyle = Fixed Single
MaximizeBox = False
WindowState = Maximized
Locked = True

in deiner Codebehind folgenden Code einfügen:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
protected override void WndProc(ref Message m)
        {

            const int WM_NCLBUTTONDOWN = 161;
            const int WM_SYSCOMMAND = 274;
            const int HTCAPTION = 2;
            const int SC_MOVE = 61456;

            if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))
            {
                return;
            }

            if ((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))
            {
                return;
            }

            base.WndProc(ref m);
        }


sollte deinen Anforderungen genügen.

LG Gery

_________________
the quiter you become, the more you are able to hear
JohnDyr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56
Erhaltene Danke: 1

Win 10
C# (VS 2017)
BeitragVerfasst: Sa 29.12.18 23:58 
Wo soll der Code eingefügt werden? Bei welchem Form Event?
Yankyy02
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 138
Erhaltene Danke: 21

Win 11 x64
C# (VS 2022 - Rider)
BeitragVerfasst: So 30.12.18 00:05 
In der Codebehind Datei deiner Form.

Sollte dann so aussehen .....

ausblenden C#-Quelltext
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:
public partial class Form1 : Form
    {

        protected override void WndProc(ref Message m)
        {

            const int WM_NCLBUTTONDOWN = 161;
            const int WM_SYSCOMMAND = 274;
            const int HTCAPTION = 2;
            const int SC_MOVE = 61456;

            if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))
            {
                return;
            }

            if ((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))
            {
                return;
            }

            base.WndProc(ref m);
        }

        public Form1()
        {
            InitializeComponent();
        }
    }

_________________
the quiter you become, the more you are able to hear
JohnDyr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56
Erhaltene Danke: 1

Win 10
C# (VS 2017)
BeitragVerfasst: So 30.12.18 13:37 
Ah okay, hatte den Begriff "codebehind" noch nicht vorher gehört. Es funktioniert so "halb". Das mittlere Symbol (Maximieren, Fenster) wird zwar deaktiviert dargestellt, allerdings kann der Nutzer diese Funktion mit einem Doppelklick auf die Leiste nachvollziehen. Kann ich das auch irgendwie abschalten?

Zusätzlich hatte ich vorher immer die Windows Taskleiste (unten) immer noch sichtbar gehabt. Das würde ich beibehalten wollen.
Yankyy02
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 138
Erhaltene Danke: 21

Win 11 x64
C# (VS 2022 - Rider)
BeitragVerfasst: So 30.12.18 14:22 
Um die Taskleiste nicht zu verdecken setze in den Eigenschaften des Fensters den FormBorderStyle auf Sizeable und ändere in der Codebehind deiner Form den Code folgendermaßen ab:
ausblenden C#-Quelltext
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:
protected override void WndProc(ref Message m)
        {

            const int WM_NCLBUTTONDOWN = 161;
            const int WM_SYSCOMMAND = 274;
            const int HTCAPTION = 2;
            const int SC_MOVE = 61456;
            const int WM_NCLBUTTONDBLCLK = 163;

            if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE))
            {
                return;
            }

            if ((m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION))
            {
                return;
            }

            if ((m.Msg == WM_NCLBUTTONDBLCLK) && (m.WParam.ToInt32() == HTCAPTION))
            {
                return;
            }


            base.WndProc(ref m);
        }


nun dürfte auch der doppelte Mausklick dein Fenster nicht verändern und die Taskleiste sichtbar sein.

_________________
the quiter you become, the more you are able to hear

Für diesen Beitrag haben gedankt: JohnDyr
JohnDyr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56
Erhaltene Danke: 1

Win 10
C# (VS 2017)
BeitragVerfasst: So 30.12.18 14:41 
Jetzt ist die Taskleiste vor dem Programm und verdeckt den untersten Teil. Das heißt ich muss die Größe noch dahingehend anpassen, dass sie den gesamten Bildschirm füllt - mit Ausnahme der Taskleiste.
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 30.12.18 15:35 
Dazu kannst du Screen.WorkingArea benutzen.

Für diesen Beitrag haben gedankt: JohnDyr
JohnDyr Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56
Erhaltene Danke: 1

Win 10
C# (VS 2017)
BeitragVerfasst: So 30.12.18 16:09 
Hab es jetzt hinbekommen. Danke!
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 31.12.18 00:37 
- Nachträglich durch die Entwickler-Ecke gelöscht -