如何使用Windows窗体控件操作自定义类 [英] How to manipulate the custom class with windows form controls

查看:103
本文介绍了如何使用Windows窗体控件操作自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我从不同的2篇文章中多次阅读oops概念,概念对我来说很清楚。我在软件开发人员工作7年以来一直使用c#dot net技术,但仍然无法知道如何使用Windows窗体控件来操作自定义类来检索数据并将数据保存到数据库,因为无法从自定义类访问窗体控件​​,生成运行时错误或给出意想不到的结果。



所以在这里我想知道,我如何使用自定义类的Windows控件。我的意思是,我想定义一些函数,如ADO.NET/Sql命令,以获取并将数据保存到数据库和自定义类中的其他所需函数,并使用Windows窗体控件操作这些函数,如TEXT BOX,COMBO BOX,BUTTON,DATAGRIDVIEW ,LIST VIEW,RADIONBUTTON等。



请建议任何解决方案。



谢谢



我尝试了什么:



我试图通过自我实践做到这一点,但不能得到解决方案。

Hi,

I have read oops concept many times from different-2 articles and concept is clear to me. I am working as software developer since last 7 years using c# dot net technology but still could not know how to manipulate the custom class with windows form controls to retrieve and save data to database as windows form controls are not accessible from custom class, either this generates run time error or gives unexpected result.

So here i want to know, how can i use windows controls with custom classes. I mean, I want to define some functions like ADO.NET/Sql command to get and save the data to database and other required functions in custom class and to manipulate these functions with windows forms controls like TEXT BOX, COMBO BOX, BUTTON, DATAGRIDVIEW, LIST VIEW, RADIONBUTTON etc.

Please suggest any solution.

Thanks

What I have tried:

I tried to do this by Self Practice but could not get solution.

推荐答案

为了使用Windows控件并显示,你的类必须是一个Control本身 - 即它必须从Control派生才能获得一个窗口和一个消息循环。通常的方法是创建一个UserControl类,并将表单控件放到该类上。 UserControl Class(System.Windows.Forms) [ ^ ]

如果您没有尝试创建可以显示的控件,那么您可以将其视为普通类:通过属性获取和设置数据,以及使它通过方法做事。我们可以向你解释这一切 - 如果你是一名开发人员已有7年而且你不了解这些非常非常基本的东西,那么你真的需要一本书并从头到尾阅读,因为它很清楚你错过了远远的,太多的东西......
In order to work with Windows controls and to be displayed, your class must be a Control itself - i.e. it must derive from Control in order to get a windows and a message loop. The usual way this is done is to create a UserControl class, and drop your form controls onto that. UserControl Class (System.Windows.Forms)[^]
If you are not trying to create a control that can be displayed, then you would treat it as a normal class: you get and set data via properties, and cause it to do things via methods. We can;t explain all that to you - if you have been a developer for 7 years and you don't understand such very, very basic things then you really need to get a book and read it from cover to cover, because it's clear you have missed out far, far too much stuff somewhere...


这篇关于如何使用Windows窗体控件操作自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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