C#中的绑定类(Windows) [英] Binding Class in c#(Windows)

查看:83
本文介绍了C#中的绑定类(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个需要使用Binding类但该类构造函数为
的方案
接受三个参数属性名,数据源,数据成员"

但是我只有一个对象byte [].我需要在Binding class中设置这个byte [].
并在控制中显示byte []的结果.

//code//////



i have a scenario in which i need to use Binding class but this class constructor

accepts three parameter "propertname,DataSource,Datamember"

but i have only single object a byte[] .i need to set this byte[] in Binding class

and show the result of byte[] in control how it is possible.

//code/////

byte[] image;

mmViewer.DataBindings.Add(new Binding("",image,null))

//这里我需要设置图像

绑定并在查看器中显示图像.

问候,

sajit

//here i need to set the image

in binding and show the image in viewer.

Regards,

sajit

推荐答案

假定字节数组是一个图像(即已从位图或包含受支持图像格式的文件中加载),然后将其转换为图像并通过:

Assuming that the byte array is an image (i.e. has been loaded from a bitmap, or a file containing a supported image format) then just convert it to an Image and pass it through:

MemoryStream ms = new MemoryStream(bytes);
Image myImage = Image.FromStream(ms);
mmViewer.DataBindings.Add(new Binding("",myImage,null));


您好,..

要将对象绑定到任何可绑定控件,您可以使用简单的方式将它们(可绑定控件和源对象)都设置为可绑定属性的对象类型相同!
例如:

我有一个类,其中有一个名为[Picture]的属性,并且有一个图片框,我想将其绑定到!
所以这是执行此任务的示例代码:

Hello there ..

To bind an object to any bindable control you can use the easy way they both (the bindable control and source object) should have the same object type for the bindable property !
Ex:

I have a class where it has a property named [Picture] , and have a picture box that I would like to bind it to !
so here is an example code to do this mission :

using System.Drawing;
namespace Test{
    class a
    {
        public a() { }

        private Image picture;
        public Image Picture
        {
            get { return picture; }
            set { picture = value; }
        }
    }
}

// this picture box is on another form class and named pictureBox1

a aTest = new a();
this.pictureBox1.DataBindings.Add("Image", a, "Picture");



希望您能理解,如果不输入答复,我会尽快回发.

干杯和良好的编码之旅! ;)



hope you get the point , if not type a reply and I will post back as soon as possible.

Cheers and good coding journey ! ;)


这篇关于C#中的绑定类(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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