-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyWindow.cs
executable file
·143 lines (131 loc) · 5.64 KB
/
MyWindow.cs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Data;
using NCMMS.CommonClass;
namespace NCMMS
{
public class MyWindow : Window
{
Button max;
Grid windowGrid;
Border resize;
bool isResizeWork;
Point oldPoint, newPoint;
public Brush BannerBackground
{
get { return (Brush)GetValue(BannerBackgroundProperty); }
set { SetValue(BannerBackgroundProperty, value); }
}
public static readonly DependencyProperty BannerBackgroundProperty =
DependencyProperty.Register("BannerBackground", typeof(Brush), typeof(MyWindow));
public bool BtnMaxFlag
{
get { return (bool)GetValue(BtnMaxFlagProperty); }
set { SetValue(BtnMaxFlagProperty, value); }
}
public static readonly DependencyProperty BtnMaxFlagProperty =
DependencyProperty.Register("BtnMaxFlag", typeof(bool), typeof(MyWindow), new UIPropertyMetadata(true));
public string WindowTitle
{
get { return (string)GetValue(WindowTitleProperty); }
set { SetValue(WindowTitleProperty, value); }
}
public static readonly DependencyProperty WindowTitleProperty =
DependencyProperty.Register("WindowTitle", typeof(string), typeof(MyWindow));
public MyWindow()
{
this.Loaded += new RoutedEventHandler(MyWindow_Loaded);
Binding bind = new Binding() { Path = new PropertyPath("WindowBannerColor"), Source = Properties.Settings.Default };
bind.Converter = new ColorStringToBrushForWindowBannerBackgroundConverter();
this.SetBinding(BannerBackgroundProperty, bind);
}
void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
Title = WindowTitle;
Button min = this.Template.FindName("btnMin", this) as Button;
max = this.Template.FindName("btnMax", this) as Button;
Button close = this.Template.FindName("btnClose", this) as Button;
Grid titleGrid = this.Template.FindName("titleGrid", this) as Grid;
windowGrid = this.Template.FindName("windowGrid", this) as Grid;
min.Click += new RoutedEventHandler(btnMin_Click);
max.Click += new RoutedEventHandler(btnMax_Click);
close.Click += new RoutedEventHandler(btnClose_Click);
titleGrid.MouseLeftButtonDown += new MouseButtonEventHandler(titleGrid_MouseLeftButtonDown);
if (BtnMaxFlag)
{
resize = this.Template.FindName("resize", this) as Border;
resize.Visibility = Visibility.Visible;
resize.Cursor = Cursors.SizeNWSE;
resize.MouseDown += new MouseButtonEventHandler(resize_MouseDown);
resize.MouseUp += new MouseButtonEventHandler(resize_MouseUp);
resize.MouseMove += new MouseEventHandler(resize_MouseMove);
}
}
void resize_MouseDown(object sender, MouseButtonEventArgs e)
{
resize.CaptureMouse();
isResizeWork = true;
oldPoint = e.GetPosition(this);
}
void resize_MouseUp(object sender, MouseButtonEventArgs e)
{
resize.ReleaseMouseCapture();
isResizeWork = false;
}
void resize_MouseMove(object sender, MouseEventArgs e)
{
if (isResizeWork)
{
newPoint = e.GetPosition(this);
this.Height += newPoint.Y - oldPoint.Y;
this.Width += newPoint.X - oldPoint.X;
oldPoint = newPoint;
}
}
void titleGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
//oldPosition = e.GetPosition(this);
if (BtnMaxFlag && e.ClickCount == 2)
{
//btnMax_Click(max, null);
max.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
}
private void btnMin_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void btnMax_Click(object sender, RoutedEventArgs e)
{
Button btnMax = sender as Button;
Image _imageMaximize = btnMax.Template.FindName("imageMaximize", btnMax) as Image;
Image _imageRestore = btnMax.Template.FindName("imageRestore", btnMax) as Image;
if (this.WindowState == WindowState.Maximized)
{
windowGrid.Margin = new Thickness(10, 0, 10, 10);
this.WindowState = WindowState.Normal;
_imageMaximize.Visibility = Visibility.Visible;
_imageRestore.Visibility = Visibility.Hidden;
}
else
{
int taskbarHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
windowGrid.Margin = new Thickness(0, 0, 0, taskbarHeight);
this.WindowState = WindowState.Maximized;
_imageMaximize.Visibility = Visibility.Hidden;
_imageRestore.Visibility = Visibility.Visible;
}
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}