我想在pictrueBox中放入图片、图片是每次一张往里放的、、但是怎样才能在pictureBox中的指定位置放入想要的图片呢?
急~~~~~
急~~~~~
解决方案 »
- c#窗体程序的问题
- 关于serialport的属性ReceivedBytesThreshold
- 自定义组件 (继承ListView) 里面设置透明色时加入以下代码,结果是透明了,但是里面的文字也看不到了,请问咋整?
- 如何在画3d图形啊
- 属性问题
- 请教各位在C#中有没有比Split效率更高的函数,如果自己写循环函数效率会不会更高些,有者方面经验的兄弟们请指教啊
- 求教一个很简单的重定向问题
- Global.asax文件有何妙用?
- DataGrid 如何限制用户添加新行,但是又要可以修改原来的内容?
- 昨天还没有解决问题,今天继续追问,小女子没办法了,我的MIS系统完不成了
- SendKeys.Send("");和真正的键盘输入有什么不一样,应用程序怎么判断是真正键盘输入还是程序。
- sql server 2008中数据库的麻烦
string Path = @"D:\文档\My Pictures\1.jpg";
Image b=new Bitmap(Image.FromFile(Path),new Size(200, 200));
this.pictureBox1.Image = b;
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;
}
}
一般做法: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);
}
}
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));
需要你自己用代码精确控制图片显示位置:Graphics.DrawImage()
{
e.Graphices.DrawImage(image,x,y...); // x,y为位置
// ............ 可以重叠的画 picturebox为画布 任你表演
}
再翻看msdn graphics类的所有成员和方法。都看完还不会,就别写了。
2.多个PictureBox,改变层叠位置(SetToBack()和BrintToFront()),符合面向对象,而起易于扩展