C#用于组件的背景图像布局的5个选项分别是什么意思?(None,Tile,Center,stretch away,Zoom)

C#课程教学8_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
C#课程教学8
上传于||文档简介
&&C​#​课​程​教​学
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
下载文档到电脑,查找使用更方便
还剩27页未读,继续阅读
你可能喜欢1844人阅读
功能说明:Windows窗体控件,非WPF控件。把图片文件拖入框内即可显示。把图片拖出框即可删除。开发工具:Visual Studio v2010.NET Framework 4 Client Profile版本历史:V1.0&&& 日基于winform,实现一个具有拖入和删除功能的图片框控件下载地址:演示程序:源代码:FingerPictureBox.cs/* ----------------------------------------------------------
文件名称:FingerPictureBox.cs
作者:秦建辉
博客:http://blog.csdn.net/jhqin
开发环境:
Visual Studio V2010
.NET Framework 4 Client Profile
产品类型:
基于C#的Windows窗体控件
版本历史:
基于winform,实现一个具有拖入和删除功能的图片框控件
------------------------------------------------------------ */
using System.D
using System.Windows.F
namespace Splash
/// &summary&
/// 方便手指操作的用户控件,轻松完成图像拖入和删除
/// 主要属性:
ImageLayout:设置图像布局(None、Tile、Center、Stretch、Zoom)
ImageSize:控件大小
InitialImage:初始图像
ActiveImage:活动图像
/// &/summary&
public partial class FingerPictureBox : UserControl
private Int32 mouseX;
private Int32 mouseY;
private Image _InitialImage =
public FingerPictureBox()
InitializeComponent();
// 设置用户控件属性,允许用户在上面拖放数据
this.AllowDrop =
// 设置装载事件处理器
this.Load += new EventHandler(this.FingerPictureBox_Load);
// 设置拖动事件处理器
this.DragDrop += new DragEventHandler(this.FingerPictureBox_DragDrop);
this.DragEnter += new DragEventHandler(this.FingerPictureBox_DragEnter);
private void FingerPictureBox_Load(object sender, EventArgs e)
// 设置图片框停靠位置和方式
this.Controls[0].Dock = DockStyle.N
// 设定图片框背景图像布局
this.Controls[0].BackgroundImageLayout = ImageLayout.S
// 设置图片框的起始位置和大小
this.Controls[0].Location = new Point(0, 0);
this.Controls[0].Size = this.S
// 设置背景图像改变事件处理器
this.Controls[0].BackgroundImageChanged += new EventHandler(this.FingerPictureBox_BackgroundImageChanged);
private void FingerPictureBox_DragDrop(object sender, DragEventArgs e)
获取拖入的文件
String[] DropFiles = (String[])(e.Data.GetData(DataFormats.FileDrop));
if (DropFiles != null)
// 设置控件背景图像
this.Controls[0].BackgroundImage = Image.FromFile(DropFiles[0]);
private void FingerPictureBox_DragEnter(object sender, DragEventArgs e)
// 拖放时显示的效果
e.Effect = DragDropEffects.L
private void FingerPictureBox_MouseDown(object sender, MouseEventArgs e)
// 记录鼠标单击时的初始位置
mouseX = Cursor.Position.X;
mouseY = Cursor.Position.Y;
private void FingerPictureBox_MouseMove(object sender, MouseEventArgs e)
if (e.Button == MouseButtons.Left)
((PictureBox)sender).Left = Cursor.Position.X - mouseX;
((PictureBox)sender).Top = Cursor.Position.Y - mouseY;
private void FingerPictureBox_MouseUp(object sender, MouseEventArgs e)
// 判断图像是否移出边界
if (((PictureBox)sender).Left & this.Width || ((PictureBox)sender).Right & 0 ||
((PictureBox)sender).Top & this.Height || ((PictureBox)sender).Bottom & 0)
// 图像已经移出边界,恢复初始图像
((PictureBox)sender).BackgroundImage = _InitialI
// 图片框复位
this.Controls[0].Location = new Point(0, 0);
private void FingerPictureBox_BackgroundImageChanged(object sender, EventArgs e)
if (this.Controls[0].BackgroundImage == _InitialImage)
// 禁止图像拖动删除功能
((PictureBox)sender).MouseDown -= FingerPictureBox_MouseD
((PictureBox)sender).MouseMove -= FingerPictureBox_MouseM
((PictureBox)sender).MouseUp -= FingerPictureBox_MouseUp;
// 恢复图像拖动删除功能
((PictureBox)sender).MouseDown += FingerPictureBox_MouseD
((PictureBox)sender).MouseMove += FingerPictureBox_MouseM
((PictureBox)sender).MouseUp += FingerPictureBox_MouseUp;
/// &summary&
/// 控件上图像的布局
/// &/summary&
public ImageLayout ImageLayout
return this.Controls[0].BackgroundImageL
this.Controls[0].BackgroundImageLayout =
/// &summary&
/// 控件大小
/// &/summary&
public Size ImageSize
return this.S
this.Controls[0].Size = this.Size =
/// &summary&
/// 初始图像
/// &/summary&
public Image InitialImage
return _InitialI
this.Controls[0].BackgroundImage = _InitialImage =
/// &summary&
/// 活动图像
/// &/summary&
public Image ActiveImage
return this.Controls[0].BackgroundI
this.Controls[0].BackgroundImage =
FingerPictureBox.Designer.csnamespace Splash
partial class FingerPictureBox
/// &summary&
/// 必需的设计器变量。
/// &/summary&
ponentModel.IContainer components =
/// &summary&
/// 清理所有正在使用的资源。
/// &/summary&
/// &param name=&disposing&&如果应释放托管资源,为 true;否则为 false。&/param&
protected override void Dispose(bool disposing)
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
#region 组件设计器生成的代码
/// &summary&
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// &/summary&
private void InitializeComponent()
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((ponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
// pictureBox1
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = &pictureBox1&;
this.pictureBox1.Size = new System.Drawing.Size(127, 144);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchI
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop =
// FingerPictureBox
this.AllowDrop =
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.F
this.Controls.Add(this.pictureBox1);
this.Name = &FingerPictureBox&;
this.Size = new System.Drawing.Size(173, 196);
((ponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:368351次
积分:5066
积分:5066
排名:第3269名
原创:116篇
评论:264条
(2)(1)(2)(2)(1)(5)(12)(6)(5)(2)(14)(6)(5)(6)(5)(9)(6)(1)(1)(1)(3)(2)(4)(3)(2)(8)(2)}

我要回帖

更多关于 stretch away 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信