PictureBox控件

常用属性:Image,ImageLocation,SizeMode

常用事件:Click

知识点1:

SizeMode,控制图片的显示方式,如下:

 

 

值得注意的时,只有Autosize模式会改变PictureBox的大小。

 

 

 

知识点2:

 

图片的加载方式:

 

方法1:使用ImageLocation方法

 

方法2:使用Image.FromFile方法

 

注意,不论使用哪种方法,都可以使用绝对地址和相对地址。使用相对地址时,要将图片复制到输出目录中,如下所示:

 

 

 

 

private void button1_Click(object sender, EventArgs e)
        {
            //方法1,使用ImageLocation属性
            //pictureBox1.ImageLocation = @"Resources\city.png";//使用相对地址
            //pictureBox1.ImageLocation = @"C:\Users\Administrator\Desktop\code\ControlsTest\Resources\city.png";//使用绝对地址

            //方法2,使用Image.FromFile方法
            //pictureBox1.Image = Image.FromFile(@"Resources\city.png");
            pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\code\ControlsTest\Resources\city.png");

        }

 

posted on 2022-10-16 22:16  hanzq_go  阅读(187)  评论(0编辑  收藏  举报

导航