본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# - 마우스 커서 변경 ( Mouse Cursor / Cursors Change / Cursors.Arrow )

728x90
반응형


 WPF & C# - 마우스 커서 변경 ( Mouse Cursor / Cursors Change / Cursors.Arrow )



testMouseCursor.zip




MainWindow.xaml



1
2
3
<Grid>
    <WrapPanel x:Name="wrp" Margin="10" />
</Grid>
cs



MainWindow.xaml.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
public MainWindow()
{
    InitializeComponent();
 
    // 버튼 생성
    for(int i = 0; i < 29;i++)
    {
        string str = "btn" + i.ToString("00");
        Button btn = new Button();
        btn.Name = str;
        btn.Height = btn.Width  = 100;
        btn.Margin = new Thickness(3);
        btn.Click += btn_Click;
 
        wrp.Children.Add(btn);
    }
}
 
private void btn_Click(object sender, RoutedEventArgs e)
{
    Button btn = sender as Button;
    if (btn.Name == "btn00"this.Cursor = Cursors.AppStarting;
    if (btn.Name == "btn01"this.Cursor = Cursors.Arrow;
    if (btn.Name == "btn02"this.Cursor = Cursors.ArrowCD;
    if (btn.Name == "btn03"this.Cursor = Cursors.Cross;
    if (btn.Name == "btn04"this.Cursor = Cursors.Hand;
    if (btn.Name == "btn05"this.Cursor = Cursors.Help;
    if (btn.Name == "btn06"this.Cursor = Cursors.IBeam;
    if (btn.Name == "btn07"this.Cursor = Cursors.No;
    if (btn.Name == "btn08"this.Cursor = Cursors.None;
    if (btn.Name == "btn09"this.Cursor = Cursors.Pen;
    if (btn.Name == "btn10"this.Cursor = Cursors.ScrollAll;
    if (btn.Name == "btn11"this.Cursor = Cursors.ScrollE;
    if (btn.Name == "btn12"this.Cursor = Cursors.ScrollN;
    if (btn.Name == "btn13"this.Cursor = Cursors.ScrollNE;
    if (btn.Name == "btn14"this.Cursor = Cursors.ScrollNS;
    if (btn.Name == "btn15"this.Cursor = Cursors.ScrollNW;
    if (btn.Name == "btn16"this.Cursor = Cursors.ScrollS;
    if (btn.Name == "btn17"this.Cursor = Cursors.ScrollSE;
    if (btn.Name == "btn18"this.Cursor = Cursors.ScrollSW;
    if (btn.Name == "btn19"this.Cursor = Cursors.ScrollW;
    if (btn.Name == "btn20"this.Cursor = Cursors.ScrollWE;
    if (btn.Name == "btn21"this.Cursor = Cursors.SizeAll;
    if (btn.Name == "btn22"this.Cursor = Cursors.SizeNESW;
    if (btn.Name == "btn23"this.Cursor = Cursors.SizeNS;
    if (btn.Name == "btn24"this.Cursor = Cursors.SizeNWSE;
    if (btn.Name == "btn25"this.Cursor = Cursors.SizeWE;
    if (btn.Name == "btn26"this.Cursor = Cursors.UpArrow;
    if (btn.Name == "btn27"this.Cursor = Cursors.Wait;
 
    // 커서 파일Path로 지정 시
    if (btn.Name == "btn28") Cursor = new Cursor(@"C:\Windows\Cursors\aero_arrow.cur");
 
    // 버튼에 해당 커서 종류 나타내기
    btn.Content = this.Cursor;
}
cs


프로그램 내에서만 커서를 변경한다.

전체 윈도우내에서 변경하려면 DLL 참조등의 설정이 추가로 필요하다.


728x90
반응형