⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picture.cs

📁 电子像册: 采用C#和SQL编写
💻 CS
字号:
using System;
using System.Drawing;
using System.Windows.Forms;


namespace EAlbum
{
	//显示图片,继承了PictureBox,Observer两个类
	public class picture : PictureBox,Observer
	{
		//将模型类实例化
		private Model model;

		//构造函数
		public picture()
		{
		}

		//实现自己的dataUpdate方法
		public void dataUpdate(Model model,string str,int npara)
		{
			this.model = model;
			//画图
			Drawpic();
		}	
	
		//设置视图对应的模型
		public void SetModel(Model model)
		{
			this.model = model;
		}		

		//将模型中的照片画到PictureBox中
		private void Drawpic()
		{
			//将模型中的图片取出
			Image bmp=model.image;
			Rectangle rc = this.ClientRectangle;

			//将图片以一定的比例(选比值大的那个作为标准)画出
			if(bmp!=null)
			{
				SizeF size = new SizeF( bmp.Width / bmp.HorizontalResolution, bmp.Height / bmp.VerticalResolution);
				float fScale = Math.Min( rc.Width / size.Width, rc.Height / size.Height);

				size.Width *= fScale;
				size.Height *= fScale;

				this.Image = new Bitmap(bmp, size.ToSize());
			}
			else
				this.Image=null;
		}	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -