C#中怎么使一幅图片直接在picturebox里显示出来
展开全部
楼上的方法管用。还有两个方法,如果你是把picturebox控件从控件栏拖入Form上,那么picturebox右上方有个向右的小箭头,点击就有设置图片。
另外就是点击picturebox控件,visual studio 的右下方将会有属性栏,里面选择backimage。
另外就是点击picturebox控件,visual studio 的右下方将会有属性栏,里面选择backimage。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
右键picturebox,在背景图片中选择你要的图片即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class ImgCtr : UserControl
{
private Image m_Image;
private float m_Scale;
public ImgCtr()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
this.m_Scale = 1.0f;
}
public Image Image
{
get
{
return m_Image;
}
set
{
m_Image = value;
SizeF size = new SizeF(this.m_Image.Width * this.m_Scale, this.m_Image.Height * this.m_Scale);
this.AutoScrollMinSize = Size.Ceiling(size);
}
}
public void ScaleImage(float scale)
{
SizeF size = new SizeF(this.m_Image.Width * this.m_Scale, this.m_Image.Height * this.m_Scale);
this.AutoScrollMinSize = Size.Ceiling(size);
this.Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (this.CanFocus)
{
this.Focus();
}
base.OnMouseDown(e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
PointF start = new PointF(this.AutoScrollPosition.X / this.m_Scale, this.AutoScrollPosition.Y / this.m_Scale);
this.drawImage(e.Graphics, start);
}
private void drawImage(Graphics g, PointF start)
{
g.ScaleTransform(this.m_Scale, this.m_Scale, MatrixOrder.Append);
g.DrawImage(this.m_Image, start.X, start.Y, this.m_Image.Width, this.m_Image.Height);
g.DrawRectangle(SystemPens.Desktop, start.X, start.Y, this.m_Image.Width - 1, this.m_Image.Height - 1);
}
}
{
private Image m_Image;
private float m_Scale;
public ImgCtr()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
this.m_Scale = 1.0f;
}
public Image Image
{
get
{
return m_Image;
}
set
{
m_Image = value;
SizeF size = new SizeF(this.m_Image.Width * this.m_Scale, this.m_Image.Height * this.m_Scale);
this.AutoScrollMinSize = Size.Ceiling(size);
}
}
public void ScaleImage(float scale)
{
SizeF size = new SizeF(this.m_Image.Width * this.m_Scale, this.m_Image.Height * this.m_Scale);
this.AutoScrollMinSize = Size.Ceiling(size);
this.Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (this.CanFocus)
{
this.Focus();
}
base.OnMouseDown(e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
PointF start = new PointF(this.AutoScrollPosition.X / this.m_Scale, this.AutoScrollPosition.Y / this.m_Scale);
this.drawImage(e.Graphics, start);
}
private void drawImage(Graphics g, PointF start)
{
g.ScaleTransform(this.m_Scale, this.m_Scale, MatrixOrder.Append);
g.DrawImage(this.m_Image, start.X, start.Y, this.m_Image.Width, this.m_Image.Height);
g.DrawRectangle(SystemPens.Desktop, start.X, start.Y, this.m_Image.Width - 1, this.m_Image.Height - 1);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |