cscの作法 その543

# 概要
cscの作法、調べてみた。
練習問題やってみた。

# 練習問題
iconを取得せよ。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/01bf6c5c-9f3f-f4c1-5e5f-0e3777c67630.png)


# サンプルコード

```

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
	public partial class Form1: Form {
		private OpenFileDialog openFileDialog1;
		private TextBox textBoxPath;
		private PictureBox pictureBox1;
		private Button buttonReference;
		private Button buttonShow;
		private System.ComponentModel.IContainer components = null;
		public Form1() {
			InitializeComponent();
		}
		protected override void Dispose(bool disposing) {
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent() {
			this.openFileDialog1 = new OpenFileDialog();
			this.textBoxPath = new TextBox();
			this.pictureBox1 = new PictureBox();
			this.buttonReference = new Button();
			this.buttonShow = new Button();
			((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
			this.SuspendLayout();
			this.openFileDialog1.FileName = "openFileDialog1";
			this.textBoxPath.Location = new Point(12, 13);
			this.textBoxPath.Name = "textBoxPath";
			this.textBoxPath.Size = new Size(221, 19);
			this.textBoxPath.TabIndex = 7;
			this.textBoxPath.Text = "C:\\WINDOWS\\system32\\notepad.exe";
			this.pictureBox1.BorderStyle = BorderStyle.Fixed3D;
			this.pictureBox1.Location = new Point(13, 76);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new Size(267, 179);
			this.pictureBox1.TabIndex = 6;
			this.pictureBox1.TabStop = false;
			this.buttonReference.Location = new Point(239, 11);
			this.buttonReference.Name = "buttonReference";
			this.buttonReference.Size = new Size(41, 23);
			this.buttonReference.TabIndex = 4;
			this.buttonReference.Text = "参照";
			this.buttonReference.UseVisualStyleBackColor = true;
			this.buttonReference.Click += new System.EventHandler(this.buttonReference_Click);
			this.buttonShow.Location = new Point(62, 47);
			this.buttonShow.Name = "buttonShow";
			this.buttonShow.Size = new Size(168, 23);
			this.buttonShow.TabIndex = 5;
			this.buttonShow.Text = "アイコンのビットマップを表示...";
			this.buttonShow.UseVisualStyleBackColor = true;
			this.buttonShow.Click += new System.EventHandler(this.buttonShow_Click);
			this.AutoScaleDimensions = new SizeF(6F, 12F);
			this.AutoScaleMode = AutoScaleMode.Font;
			this.ClientSize = new Size(292, 266);
			this.Controls.Add(this.textBoxPath);
			this.Controls.Add(this.pictureBox1);
			this.Controls.Add(this.buttonReference);
			this.Controls.Add(this.buttonShow);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
			this.ResumeLayout(false);
			this.PerformLayout();
		}
		private void buttonReference_Click(object sender, EventArgs e) {
			openFileDialog1.FileName = textBoxPath.Text;
			DialogResult ret = openFileDialog1.ShowDialog();
			if (ret == DialogResult.OK)
			{
				textBoxPath.Text = openFileDialog1.FileName;
			}
		}
		private void buttonShow_Click(object sender, EventArgs e) {
			string path = textBoxPath.Text;
			Icon appIcon = Icon.ExtractAssociatedIcon(path);
			pictureBox1.Image = appIcon.ToBitmap();
		}
		[STAThread]
		public static void Main() {
			Application.Run(new Form1());
		}
	}
}





```


以上。