반응형
소스 코드
MainWindow.xaml
<Window x:Class="시계_가젯.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:시계_가젯"
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
Loaded="Window_Loaded"
Title="MainWindow" Height="200" Width="150">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Ellipse
MouseDown="Ellipse_MouseDown"
Opacity="0.2"
Grid.RowSpan="6"
Fill="Cyan"/>
<TextBlock
Name="tb_eh"
Foreground="Red"
FontWeight="Heavy"
HorizontalAlignment="Center"
Text="http://ehpub.co.kr"
Grid.Row="1"/>
<TextBlock
Name="tb_date"
HorizontalAlignment="Center"
Text="0000-00-00"
Grid.Row="2"/>
<TextBlock
Name="tb_time"
HorizontalAlignment="Center"
Text="오전 00:00:00"
Grid.Row="3"/>
<Button
Click="Button_Click"
Grid.Row="4"
Width="100"
Content="닫기"/>
</Grid>
</Window>
MainWindow.cs
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
namespace 시계_가젯
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SetDateTime();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
timer.Start();
}
private void SetDateTime()
{
tb_date.Text = DateTime.Now.ToShortDateString();
tb_time.Text = DateTime.Now.ToLongTimeString();
}
private void Timer_Tick(object sender, EventArgs e)
{
SetDateTime();
}
}
}
반응형
'.NET > WPF' 카테고리의 다른 글
WPF에서 WebBrowser 컨트롤 스크립트 오류 없애기 (0) | 2020.07.31 |
---|---|
Grid 패널에 배치하기 – CS 코드로 작성하기 [언제나 WPF] (0) | 2020.07.08 |
Grid 패널에 배치하기 [언제나 WPF] (0) | 2020.05.28 |
Kakao API를 이용한 위치 검색 프로그램 만들기 [WPF] (0) | 2020.04.27 |