cscの作法 その55
1598 ワード
概要
cscの作法、調べてみた。
走る人やってみた。
写真
サンプルコード
using System;
using System.Windows.Forms;
using System.Drawing;
class form1: Form {
PictureBox pb0;
Image img;
int ind;
form1() {
Text = "WebBrowser";
ClientSize = new Size(420, 320);
pb0 = new PictureBox();
pb0.Width = 85;
pb0.Height = 102;
img = Image.FromFile("sprite-animation4.png");
pb0.Image = img;
ind = 0;
Controls.AddRange(new Control[] {
pb0
});
Timer timer = new Timer();
timer.Interval = 100;
timer.Tick += new EventHandler(timerTick);
timer.Start();
}
void timerTick(object sender, EventArgs e) {
int x;
int y;
Text = DateTime.Now.ToString("HH:mm:ss");
ind = ind + 1;
if (ind > 29)
ind = 0;
x = (ind % 6) * 85;
y = (ind / 6) * 102;
Bitmap canvas = new Bitmap(pb0.Width, pb0.Height);
Graphics g = Graphics.FromImage(canvas);
Rectangle srcRect = new Rectangle(x, y, 85, 102);
Rectangle desRect = new Rectangle(0, 0, srcRect.Width, srcRect.Height);
g.DrawImage(img, desRect, srcRect, GraphicsUnit.Pixel);
g.Dispose();
pb0.Image = canvas;
this.Invalidate();
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
using System;
using System.Windows.Forms;
using System.Drawing;
class form1: Form {
PictureBox pb0;
Image img;
int ind;
form1() {
Text = "WebBrowser";
ClientSize = new Size(420, 320);
pb0 = new PictureBox();
pb0.Width = 85;
pb0.Height = 102;
img = Image.FromFile("sprite-animation4.png");
pb0.Image = img;
ind = 0;
Controls.AddRange(new Control[] {
pb0
});
Timer timer = new Timer();
timer.Interval = 100;
timer.Tick += new EventHandler(timerTick);
timer.Start();
}
void timerTick(object sender, EventArgs e) {
int x;
int y;
Text = DateTime.Now.ToString("HH:mm:ss");
ind = ind + 1;
if (ind > 29)
ind = 0;
x = (ind % 6) * 85;
y = (ind / 6) * 102;
Bitmap canvas = new Bitmap(pb0.Width, pb0.Height);
Graphics g = Graphics.FromImage(canvas);
Rectangle srcRect = new Rectangle(x, y, 85, 102);
Rectangle desRect = new Rectangle(0, 0, srcRect.Width, srcRect.Height);
g.DrawImage(img, desRect, srcRect, GraphicsUnit.Pixel);
g.Dispose();
pb0.Image = canvas;
this.Invalidate();
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
以上。
Author And Source
この問題について(cscの作法 その55), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/b6d56cc730246516555f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .