请教:如何从openfiledialog读取一个图片到picturebox上呀. 不是有个filename吗,那个是路径,用picturebox.image= 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 OpenFileDialog dlg = new OpenFileDialog();dlg.ShowDialog();FileStream fs = new FileStream( dlg.FileName, FileMode.Open, FileAccess.Read);System.Drawing.Image img = System.Drawing.Image.FromStream(fs);pictureBox1.Image = img;fs.Close(); 初始化:this.button1 = new System.Windows.Forms.Button();this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();this.pictureBox1 = new System.Windows.Forms.PictureBox();this.openFileDialog1.DefaultExt = "jpg";this.openFileDialog1.Filter = "JPEG and GIF Images(*.jpg;*.gif)|*.jpg;*.gif";this.openFileDialog1.InitialDirectory = "c:\\";//自己定义this.openFileDialog1.RestoreDirectory = true;this.button1.Location = new System.Drawing.Point(24, 32);//自己定义this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(184, 32);this.button1.TabIndex = 0;this.button1.Text = "Show OpenFileDialog";this.button1.Click += new System.EventHandler(this.button1_Click);this.pictureBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right);this.pictureBox1.Location = new System.Drawing.Point(8, 0);//自己定义this.pictureBox1.Name = "pictureBox1";this.pictureBox1.Size = new System.Drawing.Size(264, 352);this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;this.pictureBox1.TabIndex = 0;this.pictureBox1.TabStop = false;应用:private void button1_Click(object sender, System.EventArgs e){System.Windows.Forms.DialogResult dr = openFileDialog1.ShowDialog();if (dr == System.Windows.Forms.DialogResult.OK) pictureBox1.Image=Image.FromFile(openFileDialog1.FileName);} winform窗体.... c#键盘事件,我的程序没反应啊 socket 怪异问题 C# 连接ORACLE的时候.本地机需要安装ORACLE客户端吗? C#的codebehind的变量如何传递给客户端的javascript代码中? 关于制作安装程序时的“无法找到注册接口”的问题 HttpWebRequest和HttpWebResponse下载地址不正确的问题 请问怎么样才能让自己写的控件响应键盘! 求一个C#的算法,关于数组拷贝 怎样写一个系统的需求分析?一般都包括哪些内容呢? 怎样把DataSet占用的内存释放 在论坛中集成C#编译器如何?
dlg.ShowDialog();
FileStream fs = new FileStream( dlg.FileName, FileMode.Open, FileAccess.Read);
System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
pictureBox1.Image = img;
fs.Close();
this.button1 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.openFileDialog1.DefaultExt = "jpg";
this.openFileDialog1.Filter = "JPEG and GIF Images(*.jpg;*.gif)|*.jpg;*.gif";
this.openFileDialog1.InitialDirectory = "c:\\";//自己定义
this.openFileDialog1.RestoreDirectory = true;
this.button1.Location = new System.Drawing.Point(24, 32);//自己定义
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(184, 32);
this.button1.TabIndex = 0;
this.button1.Text = "Show OpenFileDialog";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.pictureBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.pictureBox1.Location = new System.Drawing.Point(8, 0);//自己定义
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(264, 352);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;应用:
private void button1_Click(object sender, System.EventArgs e)
{
System.Windows.Forms.DialogResult dr = openFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
pictureBox1.Image=Image.FromFile(openFileDialog1.FileName);
}