Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
860 views
in Technique[技术] by (71.8m points)

winforms - C# picturebox load image with an offset

I have a resource file (in .png format) which contain several images. They are sized and spaced in a way to where they should be relatively easy to call based on their offsets.

I can size the picturebox to fit one image just fine; however, I don't know how to load the image based on its offsets, so I will always just get the one in the top left.

I'm really fine with using just about any method, but haven't been able to turn up with anything useful in my searches -- since I didn't really know what to search for exactly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can put the PictureBox in a Panel, using the panel as your viewport. Make sure the panel's AutoScroll property is false so you don't get scroll bars appearing. Then, load the image in the PictureBox, and set it's location relative to the Panel so only the area you'd like to show is visible.

pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBox1.Image = Image.FromFile(@"C:MyPicture.png");
pictureBox1.Location = new Point(-100, -100);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...