我想在pictrueBox中放入图片、图片是每次一张往里放的、、但是怎样才能在pictureBox中的指定位置放入想要的图片呢?
急~~~~~

解决方案 »

  1.   

    用 Graphic.DrawImage() 函数画。
      

  2.   


    string Path = @"D:\文档\My Pictures\1.jpg";
                Image b=new Bitmap(Image.FromFile(Path),new Size(200,   200));
                this.pictureBox1.Image = b;
      

  3.   

    显示多张时
            int i = 1;
           private void button1_Click(object sender, EventArgs e)
            {
                
                if (i < 20)
                {
                    string Path = @"D:\文档\My Pictures\" + i.ToString() + ".jpg";
                    Image b = new Bitmap(Image.FromFile(Path), new Size(200, 200));
                    this.pictureBox1.Image = b;
                    i++;
                }
                else
                {
                    i = 1;
                }  
            }
      

  4.   

    你要在picturebox里面同时放多个图片?根据字节指定的位置、大小?这样很有难度!
    一般做法:picturebox+comboBox:把要显示的图片文件名先存放到comboBox,然后:        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                try
                {
                    string picFile = comboBox1.SelectedItem.ToString();
                    pictureBox1.Image = Image.FromFile(picFile);
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
      

  5.   

    同意一楼 如果你是在PictureBox中放一张图片的话 设置 图片的居中位置就可以了 如果是放多张图片的话 就要动Graphic了 在pictureBox的paint事件中 e.Graphic就是当前触发事件的控件的绘图笔 你可以来绘图 绘制线 绘制各种图形 以及文字 每一个函数都有参数的详细使用介绍 如果要用transform的的话 要注意transform的使用顺序和消除
      

  6.   

    transform 我使用的时候主要是针对文字的倾斜使用的 如果不消除transform 它会对你下面的代码产生影响
      

  7.   

    if (string.IsNullOrEmpty(txtRecHeight.Text) || string.IsNullOrEmpty(txtRecWidth.Text)) {
    return;
    }
    float drawRecHeight = (float)(txtRecHeight.ToDouble());
    float drawRecWidth = (float)(txtRecWidth.ToDouble()); float height = this.picDwg.Height - 70;
    float width = this.picDwg.Width - 50;
    if (drawRecHeight / drawRecWidth > 1) {
    width = height * (drawRecWidth / drawRecHeight);
    } else if (drawRecHeight / drawRecWidth < 1) {
    height = width * (drawRecHeight / drawRecWidth);
    } else {
    width = height;
    }
    Brush bs = new SolidBrush(Color.FromArgb(0, 255, 0));
    float x = (picDwg.Width - width) / 2;
    float y = (picDwg.Height - height) / 2;
    e.Graphics.DrawRectangle(new Pen(Color.White), x, y, width, height);
    e.Graphics.DrawLine(new Pen(bs), new Point((int)x - 5, (int)(y + height + 20)), new Point((int)(x + width + 5), (int)(y + height + 20)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)x, (int)(y + height + 10)), new Point((int)x, (int)(y + height + 25)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width), (int)(y + height + 10)), new Point((int)(x + width), (int)(y + height + 25)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width + 5), (int)(y + height + 15)), new Point((int)(x + width - 5), (int)(y + height + 25)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + 5), (int)(y + height + 15)), new Point((int)(x - 5), (int)(y + height + 25)));
    e.Graphics.DrawString("W", new Font("宋体", 10), bs, new PointF(x + width / 2, y + height + 8));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width + 20), (int)(y - 5)), new Point((int)(x + width + 20), (int)(y + height + 5)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width + 10), (int)y), new Point((int)(x + width + 25), (int)y));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width + 10), (int)(y + height)), new Point((int)(x + width + 25), (int)(y + height)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width + 15), (int)(y - 5)), new Point((int)(x + width + 25), (int)(y + 5)));
    e.Graphics.DrawLine(new Pen(bs), new Point((int)(x + width + 15), (int)(y + height - 5)), new Point((int)(x + width + 25), (int)(y + height + 5))); System.Drawing.Drawing2D.Matrix transform = e.Graphics.Transform;
    transform.RotateAt(-90, new PointF(x + width + 8, y + height / 2));
    e.Graphics.Transform = transform;
    e.Graphics.DrawString("H", new Font("宋体", 10), bs, new PointF(x + width + 8, y + height / 2));
      

  8.   

    我觉得你不如自己写一个 picture box list 控件,来实现显示多个 image。
      

  9.   

    我存放到了一个imagelist中了、、跟你的性质一样、、可是不能多张显示到picturebox中、、我想在pictureBox中任意位置放置图片并且不清空的时候一直存在、、点一个按钮出来一个图片、
      

  10.   

    这种需求,跟用不用picturebox已经没有什么关系了,只要有个面板就行!如:panel、form等!
    需要你自己用代码精确控制图片显示位置:Graphics.DrawImage()
      

  11.   

    这个要求,需要重画PICBOX了。但是这样你在清除的时候,很复杂啊!
      

  12.   

    接收picturebox的Paint事件  在事件处理程序中绘图pictureBox1_Paint(sender,e)
    {
      e.Graphices.DrawImage(image,x,y...); // x,y为位置
      // ............  可以重叠的画  picturebox为画布   任你表演
    }
      

  13.   

    graphics.drawimage具体用法先翻看《GDI+中文帮助》
    再翻看msdn graphics类的所有成员和方法。都看完还不会,就别写了。
      

  14.   

    1.GDI+ 绘图,比较高效
    2.多个PictureBox,改变层叠位置(SetToBack()和BrintToFront()),符合面向对象,而起易于扩展