在Windows中使用图片框 [英] using picturebox in windows

查看:76
本文介绍了在Windows中使用图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在Windows中使用图片框,但不知道该怎么做.我是编程新手(已经做了5天了).我制作了一个图片框作为第一个项目(WooHoo!),并想向我的妻子展示我的创作.数量不多,但我为此感到自豪.我曾经尝试自己做,但是碰壁了.你能帮我吗?我可以在Windows中查看图片框,但是无法像在C#中调试时那样在其上加载任何图片.请理解,我绝不是技术人员.但是自退休以来,要么要么学习新技能,要么发疯.

当我调试C#中的代码时,可以从我的媒体库"中的图片"中加载图片.在文档"中显示图片框时,可以查看图片框,但不能在其上放置任何图片.我所能做的就是按一下图片框上的按钮.

I want to be able to use picturebox in windows but don''t know how to do it. I am new to programming( Been doing it for 5 days now). I made a picturebox as a first project(WooHoo!)and would like to demonstrate my creation to my wife. It''s not much, but I''m proud of it. I''ve tried to do it on my own but have hit a wall. Can you help? I can view the picturebox in windows, but I can''t load any pictures on it like I can when I Debug in C#. Please understand, I am not technical in any way. But since Retiring, it is either learn a new skill, or go crazy.

When I Debug the code in C#, I can load a picture on it from "pictures" in My Library. When I bring the picturebox up in "Documents", I can view the picturebox, but I can''t put any pictures on it. All I can do is push the buttons on the picturebox.

推荐答案

当您将图片框牢牢抓住时,图片框非常简单-对您来说重要的属性是Image和SizeMode.
其中第一个确定要显示的图片,第二个确定图片的显示方式.

向后,将SizeMode设置为StretchImage-您可以在设计器中通过属性"窗格或通过以下方式在代码中进行此操作:
Picture boxes are pretty simple when you get the hang of them - the important properties for you are Image and SizeMode.
The first of these determines which picture will be displayed, and the second says how it it shown.

Going backwards, set the SizeMode to StretchImage - you can do this in the designer via the Properties pane, or in code by:
myPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;

StrechImage模式意味着图片将被调整大小以适合PictureBox.

现在,设置图像.同样,您可以在设计器中通过属性窗格或代码执行此操作:

StrechImage mode means that the picture will be re-sized to fit in the PictureBox.

Now, set the Image. Again, you can do this in the designer, via the properties pane, or in code:

myPictureBox.Image = Image.FromFile(@"D:\Temp\MyPic.jpg");

双引号中的位是文件的完整路径和名称.开头的"@"仅表示关闭特殊字符处理",并允许您使用单个反斜杠字符键入路径.

运行!它应该在PictureBox控件中显示文件中的图像.

错别字.很多虫子. -OriginalGriff [/edit]

Where the bit in the double quotes is the full path and name of the file. The ''@'' at the start just says "turn off special character processing" and lets you type the path with single backslash characters.

Run it! It should display the image from the file in your PictureBox control.

[edit]Typos. Lots of the buggers. - OriginalGriff[/edit]


这篇关于在Windows中使用图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆