본문 바로가기

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

WPF & C# - Progressbar 예제 5가지 ( 프로그래스바 / 프로그레스바 )

728x90
반응형


 WPF & C# - Progressbar 예제 5가지 ( 프로그래스바 / 프로그레스바  )



progressbar.zip





MainWindow.xaml.



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
<Grid>
<Grid.ColumnDefinitions>
    <ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition/>
</Grid.RowDefinitions>
 
<TextBlock Margin="10,0,0,3" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.Row="0" FontSize="20">Progress Bars</TextBlock>
 
<TextBlock Margin="10,0,0,3" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Grid.Row="1" FontSize="12" TextWrapping="WrapWithOverflow">
    Progress bars indicate the progress of an operation.
    Some progress bars do not repeat others make many iterations. This example allows you to choose the number of times that the progress bar repeats.
</TextBlock>
 
<StackPanel Grid.Column="0" Grid.Row="2">
    <Label>Choose number of ProgressBar iterations.</Label>
    <RadioButton Content="One" Click="MakeOne"/>
    <RadioButton Content="Three" Click="MakeThree"/>
    <RadioButton Content="Five" Click="MakeFive"/>
    <RadioButton Content="Forever" Click="MakeForever"/>
    <RadioButton Content="Indeterminate" Click="MakeIndeterminate"/>
</StackPanel>
<!--<Snippet2>-->
<StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" 
            VerticalAlignment="Bottom" Background="Beige" >
    <StatusBarItem>
    <TextBlock>StatusBar</TextBlock>
    </StatusBarItem>
</StatusBar>
<!--</Snippet2>-->
</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
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
private void MakeOne(object sender, RoutedEventArgs e)
{
sbar.Items.Clear();
Label lbl = new Label();
lbl.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
lbl.Content = "ProgressBar with one iteration.";
sbar.Items.Add(lbl);
//<Snippet1>
ProgressBar progbar = new ProgressBar();
progbar.IsIndeterminate = false;
progbar.Orientation = Orientation.Horizontal;
progbar.Width = 150;
progbar.Height = 15;
Duration duration = new Duration(TimeSpan.FromSeconds(10));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
//</Snippet1>
sbar.Items.Add(progbar);
 
private void MakeThree(object sender, RoutedEventArgs e)
{
sbar.Items.Clear();
Label lbl = new Label();
lbl.Background = new LinearGradientBrush(Colors.Pink, Colors.Red, 90);
lbl.Content = "ProgressBar with three iterations.";
sbar.Items.Add(lbl);
ProgressBar progbar = new ProgressBar();
progbar.Background = Brushes.Gray;
progbar.Foreground = Brushes.Red;
progbar.Width = 150;
progbar.Height = 15;
Duration duration = new Duration(TimeSpan.FromMilliseconds(2000));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
doubleanimation.RepeatBehavior = new RepeatBehavior(3);
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
sbar.Items.Add(progbar);
}
        
private void MakeFive(object sender, RoutedEventArgs e)
{
sbar.Items.Clear();
TextBlock txtb = new TextBlock();
txtb.Text = "ProgressBar with five iterations.";
sbar.Items.Add(txtb);
Image image = new Image();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"pack://application:,,,/data/sunset.png");
bi.EndInit();
image.Source = bi;
ImageBrush imagebrush = new ImageBrush(bi);
 
ProgressBar progbar = new ProgressBar();
progbar.Background = imagebrush;
progbar.Width = 150;
progbar.Height = 15;
Duration duration = new Duration(TimeSpan.FromMilliseconds(2000));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
doubleanimation.RepeatBehavior = new RepeatBehavior(5);
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
sbar.Items.Add(progbar);
}
 
private void MakeForever(object sender, RoutedEventArgs e)
{
sbar.Items.Clear();
Label lbl = new Label();
lbl.Background = new LinearGradientBrush(Colors.LightBlue,        
                                        Colors.SlateBlue, 90);
lbl.Content = "ProgressBar with infinite iterations.";
sbar.Items.Add(lbl);
ProgressBar progbar = new ProgressBar();
progbar.Width = 150;
progbar.Height = 15;
Duration duration = new Duration(TimeSpan.FromSeconds(1));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
doubleanimation.RepeatBehavior = RepeatBehavior.Forever;
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
sbar.Items.Add(progbar);
          
}
 
private void MakeIndeterminate(object sender, RoutedEventArgs e)
{
    sbar.Items.Clear();
    Label lbl = new Label();
    lbl.Background = new LinearGradientBrush(Colors.Pink, Colors.Red, 90);
    lbl.Content = "Indeterminate ProgressBar.";
    sbar.Items.Add(lbl);
    //<Snippet3>
    ProgressBar progbar = new ProgressBar();
    progbar.Background = Brushes.Gray;
    progbar.Foreground = Brushes.Red;
    progbar.Width = 150;
    progbar.Height = 15;
    progbar.IsIndeterminate = true;
    //</Snippet3>
    sbar.Items.Add(progbar);
}
cs


출처 : MS ... 상세 주소를 읽어버렸네요... ㅠㅠ

728x90
반응형