
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/*********************************************************/
/*★ リソースで取り込んだイメージを描画する 前田 稔 ★*/
/*********************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
public MyForm()
{
Text = "リソースで取り込んだ Image を表示する";
BackColor = SystemColors.AppWorkspace;
Width = 800;
Height = 640;
Paint += new PaintEventHandler(MyHandler);
}
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
try
{
g.DrawImage(new Bitmap(GetType(),"ImageResource.test.gif"), new PointF(50F,50F));
}
catch
{
MessageBox.Show("イメージが取得できません","Error");
return;
}
}
}
class ImageResource
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
![]()
public partial class Form1 : Form
{ public Form1()
{ InitializeComponent();
Paint += new PaintEventHandler(MyHandler);
}
private void MyHandler(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawLine(new Pen(Color.Red),10,50,280,50);
g.DrawLine(new Pen(Color.Green,10),10,150,280,150);
}
}
|
private void MyHandler(object sender, PaintEventArgs e)
{ Graphics g = e.Graphics;
try
{ System.Drawing.Bitmap bitmap1 =
WindowsApplication1.Properties.Resources.test;
g.DrawImage(bitmap1, new PointF(50F, 50F));
}
catch
{ MessageBox.Show("イメージが取得できません","Error");
return;
}
}
|
![]()