Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9703

cscの作法 その96

$
0
0
概要 cscの作法、調べてみた。 アイコンエディタやってみた。 参考にしたページ 写真 サンプルコード using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; public class PictureBoxEx : PictureBox { public PictureBoxEx() { this.Click += PictureBoxEx_Click; } private void PictureBoxEx_Click(object sender, EventArgs e) { Form1 f = (Form1) FindForm(); this.BackColor = f.CurColor; } } public class Form1 : Form { Panel panel1; PictureBox pictureBox1; ColorDialog colorDialog1; Button button1; Button buttonColor; PictureBoxEx[,] pictureBox = new PictureBoxEx[32, 32]; PictureBoxEx CreatePictureBox(int i, int j) { int size = 10; PictureBoxEx box = new PictureBoxEx(); box.Size = new Size(size, size); box.Location = new Point(size * i, size * j); box.Parent = panel1; box.BorderStyle = BorderStyle.FixedSingle; return box; } Color curColor = new Color(); public Color CurColor { get { return curColor; } set { curColor = value; pictureBox1.BackColor = value; } } public Form1() { Text = "icon editor"; ClientSize = new Size(500, 400); colorDialog1 = new ColorDialog(); panel1 = new Panel(); panel1.Location = new Point(40, 40); panel1.Width = 320; panel1.Height = 320; this.Controls.Add(panel1); pictureBox1 = new PictureBoxEx(); pictureBox1.Size = new Size(20, 20); pictureBox1.Location = new Point(420, 20); this.Controls.Add(pictureBox1); for (int row = 0; row < 32; row++) { for (int column = 0; column < 32; column++) { PictureBoxEx box = CreatePictureBox(column, row); pictureBox[column, row] = box; } } CurColor = Color.Black; button1 = new Button(); button1.Location = new Point(400, 150); button1.Size = new Size(50, 20); button1.Text = "save"; this.Controls.Add(button1); button1.Click += button1_Click; buttonColor = new Button(); buttonColor.Location = new Point(400, 50); buttonColor.Size = new Size(50, 20); buttonColor.Text = "Color"; this.Controls.Add(buttonColor); buttonColor.Click += buttonColor_Click; } private void button1_Click(object sender, EventArgs e) { Bitmap bmp = new Bitmap(32, 32); for (int row = 0; row < 32; row++) { for (int column = 0; column < 32; column++) { bmp.SetPixel(column, row, pictureBox[column, row].BackColor); } } SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "アイコン| *.ico"; if (dlg.ShowDialog() != DialogResult.OK) return; Icon icon = Icon.FromHandle(bmp.GetHicon()); Stream outStream = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write); icon.Save(outStream); outStream.Dispose(); bmp.Dispose(); icon.Dispose(); } private void buttonColor_Click(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.OK) CurColor = colorDialog1.Color; } [STAThread] public static void Main() { Application.Run(new Form1()); } } 以上。

Viewing all articles
Browse latest Browse all 9703

Trending Articles