Propertygrid gontrol出口 [英] Propertygrid gontrol export

查看:63
本文介绍了Propertygrid gontrol出口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用属性网格控件来显示图像的统计值。

我想导出显示的那些值得擅长。

它是一个窗口应用程序,位于我正在使用的代码下方的c#中,并且工作正常。它显示属性网格控件中的图像统计信息...





我不知道如何将这些统计值从属性网格导出到excel ...





我需要有关如何将属性网格中的显示值导出为ex​​cel或其他任何其他代码的代码





hi ,

I am using property grid control which display the stat values of an image .
I want to export those displayed values to excel.
its a window application in c# below the code I'm using and its working fine.It display statistics of image in property grid control...


I dont know how to export these statistic values from property grid to excel ...


I need code for how to export displayed values in property grid to excel or any other


public class ImageStatisticsWindow : Content
{
    private System.Windows.Forms.PropertyGrid propertyGrid;
    private System.ComponentModel.Container components = null;
    private SaveFileDialog saveFileDialog1;
    private Button button1;
    private SaveFileDialog saveFileDialog2;
    private int currentImageHash = 0;
    public ImageStatisticsWindow()
        
    {
        InitializeComponent();
    }

    internal class ColorImageStatisticsDescription
    {
        private ImageStatistics statRGB;
        private ImageStatisticsHSL statHSL;
        private ImageStatisticsYCbCr statYCbCr;
     
        [Category("0: General")]
        public int PixelsCount
        {
            get { return statRGB.PixelsCount; }
        }
       
        [Category("0: General")]
        public int PixelsWithoutBlack
        {
            get { return statRGB.PixelsCountWithoutBlack; }
        }

        [Category("1: Red ")]
        public int RedMin
        {
            get { return statRGB.Red.Min; }
        }
       
        [Category("1: Red ")]
        public int RedMax
        {
            get { return statRGB.Red.Max; }
        }
    }


    public void GatherStatistics(Bitmap image)
    {
        if (image != null)
        {
            if (currentImageHash == image.GetHashCode())
                return;
            currentImageHash = image.GetHashCode();
        }
        else
        {
            propertyGrid.SelectedObject = null;
            return;
        }

        System.Diagnostics.Debug.WriteLine("--- Gathering stastics");

        if (image.PixelFormat == PixelFormat.Format24bppRgb)
        {
    
            Capture = true;
            Cursor = Cursors.WaitCursor;

            ColorImageStatisticsDescription statDesc = new ColorImageStatisticsDescription(image);
      
            propertyGrid.SelectedObject = statDesc;
            propertyGrid.ExpandAllGridItems();
            
            Cursor = Cursors.Arrow;
            Capture = false;
        }
        else
        {
            propertyGrid.SelectedObject = null;
        }
    }


    public ColorImageStatisticsDescription(Bitmap image)
    {
        int width = image.Width;
        int height = image.Height;
  
        BitmapData imgData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    
        statRGB = new ImageStatistics(imgData);
        statHSL = new ImageStatisticsHSL(imgData);
        statYCbCr = new ImageStatisticsYCbCr(imgData);

        image.UnlockBits(imgData);
    }
}

推荐答案

您真的不想使用PropertyGrid导出。相反,网格是一组数据(您的图像)的视图。您想要创建另一个保存到磁盘而不是在屏幕上显示的视图。



PropertyGrid严重依赖于反射 [ ^ ]。通过这种方式,它可以显示各种对象的属性。



既然你提到了一种给定类型的数据(图像),很可能它更容易编写专门为您正在使用的图像类导出。



请更新您的问题(使用改善问题链接)并提供一些显示您想要的内容的代码出口。



然后就是优秀部分。我从来没有这样做过。总是使用一种CSV文件格式或另一种格式。
You don't really want to export using the PropertyGrid. Instead, the grid is a view on a set of data (your image). You want to create another view that's saved to disk instead of displayed on-screen.

PropertyGrid heavily relies on Reflection[^]. This way, it can display properties of a wide variety of objects.

Since you're mentioning a given type of data (image), most likely it's easier to write an export specifically for the image class you're using.

Please update your question (using the "Improve question" link) and provide some code that shows what you want to export.

And then there's the "to excel" part. I've never done that. Always got away with one sort of CSV file format or the other.


这篇关于Propertygrid gontrol出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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