在面板中选择图像 [英] Select image within Panel

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

问题描述

大家好...我目前正在构建一个应用程序来处理Windows窗体上的图像.我面临的问题是我希望选择加载到面板(有2个面板)上的图片,以便用户可以选择单个图片并将其合并,分割或删除.我正在使用c#.

在此先感谢
:confused:

Hi people... i am currently building an application to manipulate images on a windows form.The problem i am facing is that i want the pictures that are loaded onto the panels (there are 2 panels) to be selectable so that the user can select individual pictures and merge,split or delete them. i am using c# .

Thanks in advance
:confused:

推荐答案

面板没有Image属性-您将必须:
1)在每个面板中放置一个PictureBox(并将其固定以填充整个东西),然后使用PictureBox.Image属性

2)在Panel.Paint事件中自己绘制图像.

使用哪种取决于您的需要-如果您的图像始终是PictureBox知道的图像,那可能就足够了.如果要对面板中的图像执行任何操作(例如标题,颜色更改,线条,框等),请自己绘制.

[edit] V2.0
Paint事件或PictureBox都不会为您选择图像-您将必须为其添加自己的浏览代码.对于快速而又讨厌的想法解决方案,推入一两个图片框并为Click事件添加处理程序,然后将其路由到同一例程.
在此处理程序中,"sender"参数告诉您单击了哪个PictureBox,然后可以使用FileDialog类选择文件.
A Panel doesn''t have a Image property - you will either have to:
1) Put a PictureBox in each panel (and dock it to fill the whole thing) then work with the PictureBox.Image property,
or
2) Draw the image yourself in the Panel.Paint event.

Which you use will depend on what you need - if your images are always those a PictureBox knows, then that may be enough. If you want to do anything with the image in the panel (such as captions, colour changes, lines, boxes, etc), then draw it yourself.

[edit] V2.0
Neither the Paint event nor a PictureBox will select an image for you - you will have to add your own browse code for either. For a quick-and-nasty-but-give-you-the-idea solution, shove in a picture box or two and add a handler for the Click event which routes then both to the same routine.
In this handler, the "sender" parameter tells you which PictureBox was clicked, and you can use the FileDialog class to select a file.
private void pictureBox_Click(object sender, EventArgs e)
    {
    PictureBox pic = sender as PictureBox;
    if (pic != null)
        {
        OpenFileDialog ofd = new OpenFileDialog();
        if (ofd.ShowDialog() == DialogResult.OK)
            {
            pic.Image = Image.FromFile(ofd.FileName);
            }
        }
    }

此代码是完整的方法-您将要设置过滤器等,但它为您提供了一个起点.

[/edit]

This code is way from complete - your will want to set filters, etc., etc., but it give you a starting point

[/edit]


这篇关于在面板中选择图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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