概要
cscの作法、調べてみた。
スクリーンセーバー作ってみた。
サンプルコード
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing.Drawing2D;
public class Form1: Form {
public Form1() {
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.KeyDown += new KeyEventHandler(this.MyKeyDown);
this.MouseDown += new MouseEventHandler(this.MyMouseDown);
this.ClientSize = new Size(640, 480);
Opacity = 0.3;
Timer timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timerTick);
timer.Start();
}
private void MyMouseDown(object sender, MouseEventArgs ev) {
Application.Exit();
}
private void MyKeyDown(object sender, KeyEventArgs ev) {
Application.Exit();
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
g.TranslateTransform(ClientSize.Width / 2, ClientSize.Height / 2, MatrixOrder.Append);
Pen BPen = new Pen(Color.Blue, 5);
Pen GPen = new Pen(Color.Green, 5);
Pen RPen = new Pen(Color.Red, 3);
Point center = new Point(0, 0);
DateTime time = DateTime.Now;
double secAng = 2.0 * Math.PI * time.Second / 60.0;
double minAng = 2.0 * Math.PI * (time.Minute + time.Second / 60.0) / 60.0;
double hourAng = 2.0 * Math.PI * (time.Hour + time.Minute / 60.0) / 12.0;
int r = Math.Min(ClientSize.Width, ClientSize.Height) / 2;
int secHandLength = (int) (0.9 * r);
int minHandLength = (int) (0.9 * r);
int hourHandLength = (int) (0.7 * r);
Point secHand = new Point((int) (secHandLength * Math.Sin(secAng)), (int) (-secHandLength * Math.Cos(secAng)));
Point minHand = new Point((int) (minHandLength * Math.Sin(minAng)), (int) (-minHandLength * Math.Cos(minAng)));
Point hourHand = new Point((int) (hourHandLength * Math.Sin(hourAng)), (int) (-hourHandLength * Math.Cos(hourAng)));
g.DrawLine(RPen, center, secHand);
g.DrawLine(GPen, center, minHand);
g.DrawLine(BPen, center, hourHand);
}
void timerTick(object sender, EventArgs e) {
this.Invalidate();
}
[STAThread]
static void Main(string[] args) {
if (args.Length == 0 || string.Compare(args[0], "/s", true) == 0)
{
Form form = new Form1();
form.ShowDialog();
}
Application.Exit();
}
}
以上。