在web中,一个背景图片的位置我们可以用CSS来控制,例如 background:url(xx.jpg) no-repeat 0(水平) -40(垂直);
现在,我想在winform中控制一个背景图片的垂直位置.容器是picturebox,有什么属性或者应该怎么设置呢?

解决方案 »

  1.   

    好像除了在Paint事件里重画没有办法来设置这个坐标。
      

  2.   

    这个简单啊,参考如下:public partial class Form3 : Form
    {
    private Point m_ImagePoint; public Point ImagePoint
    {
    get { return m_ImagePoint; }
    set { m_ImagePoint = value; }
    } private Image m_Image; public Image Image
    {
    get { return m_Image; }
    set { m_Image = value; }
    } public Form3()
    {
    InitializeComponent();
    this.DoubleBuffered = true;
    }
    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    if (this.m_Image != null)
    {
    e.Graphics.DrawImage(this.m_ImagePoint.X, this.m_ImagePoint.Y, this.m_Image.Width, this.m_Image.Height);
    }
    }
    }
      

  3.   

    改一下,代码有误:protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    if (this.m_Image != null)
    {
    e.Graphics.DrawImage(this.m_Image, this.m_ImagePoint.X, this.m_ImagePoint.Y, this.m_Image.Width, this.m_Image.Height);
    }
    }