supersnake

c#.net

导航

Supersnake.Components.TBHeader

Posted on 2005-03-15 09:23  supersnake  阅读(707)  评论(0编辑  收藏  举报

在与数据库打交道时的C#应用程序,给输入型控件添加一个该数据在数据库中对应的表属性,是非常有用的.

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;

namespace Supersnake.Components
{
    
/// <summary>
    
/// TBHeader 的摘要说明。
    
/// </summary>

    [ProvideProperty("TBHead",typeof(Control))]
    
public class TBHeader : System.ComponentModel.Component,IExtenderProvider
    
{
        
/// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.Container components = null;
        
private Hashtable tbheads = new Hashtable();

        
public TBHeader(System.ComponentModel.IContainer container)
        
{
            
///
            
/// Windows.Forms 类撰写设计器支持所必需的
            
///

            container.Add(this);
            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            
//
        }


        
public TBHeader()
        
{
            
///
            
/// Windows.Forms 类撰写设计器支持所必需的
            
///

            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            
//
        }


        
/// <summary> 
        
/// 清理所有正在使用的资源。
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if(components != null)
                
{
                    components.Dispose();
                }

                tbheads.Clear();
            }

            
base.Dispose( disposing );
        }



        
组件设计器生成的代码

        
IExtenderProvider 成员

        
internal class TBHeadInfo
        
{
            
public string head = null;
        }

        
/// <summary>
        
/// [TBHead]
        
/// </summary>
        
/// <param name="control"></param>
        
/// <param name="value"></param>

        public void SetTBHead(Control control,string value)
        
{
            TBHeadInfo info;
            
if(tbheads.Contains(control))
            
{
                info 
= ((TBHeadInfo)tbheads[control]);
            }

            
else
            
{
                info 
= new TBHeadInfo();
            }

            info.head 
= value;
            tbheads[control] 
= info;
        }

        
public string GetTBHead(Control control)
        
{
            
string head;
            
if(tbheads.Contains(control))
            
{
                head 
= ((TBHeadInfo)tbheads[control]).head;
            }

            
else
            
{
                head 
= null;
            }

            
return head;
        }

    }

}