友好连接

2008年9月19日星期五

An Autobiography of a Windows Forms custom control in its own words [ComboView]



Introduction
Who am I? What am I doing here at CodeProject? Well, I’ll answer myself all these questions and others.
I am a ComboView control. You might think, well what’s that? Well, I am a ComboBox with the capability of displaying columnar items in a ListView. Well, you might ask, there are lot of other similar controls available, then what’s so special about me. Nothing, the only difference being I am going to narrate to you how I had been brought to life, and on this journey to my creation, the lessons learned by my creator.
In the Beginning
It was all a few days back when a crazy developer thought of creating me. It was not out of love for me but out of greed. The greed to learn something, the greed to understand the intricacies of control development etc. etc. So, you see a man is very greedy. He does everything for his needs.
Well, let's see what all things were on his mind when he was planning to create me.
He needs to learn control creation in .NET (specifically in C#).
He needs to understand how to create a composite control.
He needs to understand the way ListView works.
He needs to understand the details of how to provide custom databinding.
He needs to understand how to work with custom events.
Etc…
Well, I need to admit one thing. I am not one of the best controls, not even closest to them. But I am happy because to certain degree, it was through me the creator of me understood all the above objectives (or I assume he understood).
Let's dissect myself, and on the journey, you and me can learn a few things.
Dissecting myself
First things first. In order for me to come into existence, I needed to have a parent. The developer decided that the UserControl should be my parent.
So, I was inherited from System.Windows.Forms.Usercontrol. That would imply that I would be having all the attributes and behavior of my parent (UserControl).public class MyCombo : System.Windows.Forms.UserControl
{
Since I am a ComboView, in order for me to come into existence, I would require the support of a few other controls, specifically, a Button, a ListView and a TextBox. private System.Windows.Forms.ListView lvObject;
private System.Windows.Forms.TextBox txtObject;
private System.Windows.Forms.Button btnDropDown;
OK, I would explain why the above three controls are required:
The ListView would be used to display the data in multi-columnar form.
The TextBox would be used to display the selected value.
The Button would serve the purpose of drilling me up and down.
Then the developer needed certain variables to control my behavior. So, he declared it in its own region.#region MyCombo Variables
private object _dataSource;
private string _dataMember;
private string _displayMember;
private string _valueMember;
protected ArrayList _columnHeader = new ArrayList();
private object _selectedValue;
private object _selectedText;
//Size
const int MIN_WIDTH = 140;
const int MIN_HEIGHT = 22;
#endregion
Let me tell you what some of these variables mean to me, rest are obvious. (Later, we will add respective set/get property for the above variables.)
_dataSource
I need to be able to populate myself with data from different sources like custom class, a database, an XML file etc. Use this property to assign the data source.
_dataMember
A _dataSource can contain multiple tables. Specify which table I should pick up the data from through this property.
_displayMember
Since I would present myself in multi-column format, specify which column to display in the TextBox through this property.
_valueMember
This would ideally be the unique ID for each of the data elements within a single row of data. You would require this value for querying, saving etc.
_selectedValue
This returns the value from _valueMember variable.
_selectedText
This returns the value from _displayMember variable.
_columnHeader
This is an ArrayList. This will hold the columns' title with me.
Now comes the events part. Events are needed in order for the user of the control to know when something happens to me. Right now, the developer has provided only one custom event.#region MyCombo Events
public delegate void
SelectedItemChangedEventHandler(object sender, EventArgs e);
public event SelectedItemChangedEventHandler
OnSelectedItemChangedHandler;
#endregion
The OnSelectedItemChangedHandler will be raised whenever the user selects any of the list items from the ListView.
As I promised, here are my corresponding get/set accessors. The user of me would see this properties rather than the variables we have seen above. public string DisplayMember
{
get
{
return _displayMember;
}
set
{
_displayMember = value;
}

}
public string ValueMember
{
get
{
return _valueMember;
}
set
{
_valueMember = value;
}
}
public string DataMember
{
get
{
return _dataMember;
}
set
{
_dataMember = value;
}
}
public object DataSource
{
get
{
return _dataSource;
}
set
{
_dataSource = value;
OnDataBind();
}
}
public object SelectedText
{
get
{
return _selectedText;
}
set
{
_selectedText=value;
}
}
public object SelectedValue
{
get
{
return _selectedValue;
}
set
{
_selectedValue = value;
}
}
In the DataSource property, you see a method OnDataBind(). This would be explained as we go further.
Now, there should be a mechanism through which the user of me would assign columns to me. That’s taken care by the following function. The function takes two parameters, the name of the column and the width of the column. This function simply adds the column name to the ArrayList we just saw above. public void Columns(string columnName, int colWidth)
{
_columnHeader.Add(columnName);
OnHeaderBind(columnName,colWidth);
}
Now, lets see the OnHeaderBind() function. This function adds the columnName to the actual ListView object and also sets its width. protected void OnHeaderBind(object v, int colWidth)
{
lvObject.Columns.Add(v.ToString(), colWidth, HorizontalAlignment.Left);
}
There should also be a provision for manually adding data to me rather than using a data source and data member. This is achieved by the following function. This function takes an ID, and an array of items to be added to the ListView. So, the user of me can add an item to me like:.Add (“101”,”Rajesh”,”23) public void Add(string id, params string [] items)
{
ListViewItem lvi = new ListViewItem(id);
foreach(string s in items)
{
lvi.SubItems.Add(s);
}
lvObject.Items.Add(lvi);
}
Now, as promised earlier, let's come to the OnDataBind() method. This method is called whenever you assign a data source to me. This method would just fill the ListView the information from the data source. protected void OnDataBind()
{
if (_dataSource == null)
return;
IList iList = InnerDataSource();
Type type = iList.GetType();
string s;
for (int i = 0; i < s=" GetField(RuntimeHelpers.GetObjectValue(iList[i]),_valueMember);" lvi =" new" j =" 1;"> 0)
{
iList = ((IListSource)
((DataSet)_dataSource).Tables[_dataMember]).GetList();
}
else
{
iList = ((IListSource)((DataSet)_dataSource).Tables[0]).GetList();
}
}
else if (_dataSource is IListSource)
{
iList = ((IListSource)_dataSource).GetList();
}
else if (_dataSource is ICollection)
{
object[] objs = new object[((ICollection)_dataSource).Count];
((ICollection)_dataSource).CopyTo(objs,0);
iList = objs;
}
else
{
iList = (IList)_dataSource;
}
return iList;
}
IListSource: this interface provides functionality to an object to return a list that can be bound to a data source.
ICollection: this interface defines size, enumerators and synchronization methods for all collections.
Compile me, add a test project and add reference to me, and I am ready to face the world.
That’s it to me for now. There are lots of things that needs to be done to me. Probably, that would come later on.
I hope you enjoyed reading me. Any suggestions, criticism, ideas should be directed to the creator of me, so that he could improve me or learn a bit more.
For complete source code, check the sample project uploaded with this article.
Bye for now,
ComboView
Credits
InnerDataSource and related functions -> These functions has been taken from The Code Project/ or somewhere from the Internet. If any one knows the original author, please sent a comment to me, I would like to give credit to him.
Revision History
12-28-2003: Original article.

2008年4月9日星期三

很黄很暴力的N种说法

北京方言: 忒黄了,忒暴力了   
宁波话:交怪房,交怪薄利   
南京话版:黄的一逼,暴力的一逼吊糟。   
东北版:贼拉的黄,贼拉的暴力   
东北话版:哎呀妈呀黄,哎呀妈呀暴力啊。   
东北城区话版: 贼黄贼暴力   
纯正东北话:太J8黄,太J8暴力了~   
河南版:可球黄,可球暴力。   
杭州话. 毛王,毛暴力.   
四川话 黄的没的底底,暴的没的边边,   
四川官方方言版 龟儿太黄喽;龟儿太暴力喽   
西安话:黄很,暴力很   
贵州方言:流得不浪子的,打得厉害得很   
长沙话: 确实黄,确实暴力   
湘西话 好好黄好好暴力!   
河南话:可黄,可暴力   
蒙古版:玛勒格毕勒黄,玛勒格毕勒暴。   
彪哥版: 钢钢的黄,钢钢的暴力,钢钢的`~~~~   
老赵忽悠版:那是相当的黄,相当的暴力~   
蒋介石版:娘稀匹的黄,娘稀匹的暴力。   
周星驰大话西游版: 黄、黄你妈个头!暴、暴力你妈个头!   
周杰仑版:快使用黄,黑吼哈,快使用暴力,黑吼哈   
赵氏话,那是相当的黄,相当的暴力   
楚霸王版: 西洋之SM兮,黄且暴力!   
国粹版:真他妈黄,他奶奶的太暴力了。   
中央版:不黄不暴力   
火星文:ㄔ艮黉,ㄔ艮晎水ㄉ。   
日语:你滴,大大滴黄,大大滴暴力了......   
韩语版: 区尼门甘尼门操尼门死米大   
江苏省内的   
江苏东台:呆黄呆暴力   
常州话:费要太黄,费要太暴力哦   
徐州一代语言:血黄,血暴力!   
苏州版:交乖黄,交乖暴力   
镇江话. 王得一塌糊涂,暴力得一塌糊涂.   
宿迁方言:呆日脑黄,呆日脑地暴力.   
沭阳方言:日特ma黄发或扎,日特ma暴力海海滴.   
日本版:かなり猥亵で、とても暴力的な   
荷兰版:Zeer geel en zeer hevig   
葡萄牙版:Muito amarelo e muito violento   
俄语版:Очень желтый цвет и очень яростная   
法语版:Tres jaune et tres violent   
希腊版:∏ολ   
德语版:Sehr gelb und sehr gewaltt?tig   
意大利:Molto giallo e molto violento   
西班牙:Muy amarillo y muy violentos   
德语版:sehr erotisch und sehr gewaltsam   
世界语(Esperanto):tre flava,tre violenta

背你上楼的男人

她是城市的白领,他是城市的扛包工人.高中毕业后,两个人划着完全不同的青春轨迹.可是, 他们依然保持着恋人的关系.仅仅是保持着.白天,她在公司里喝正宗的雀巢咖啡,下班后,她吃他买来的廉价的冰棍;中午,她品味着公司里精致的饭菜,晚上, 他带她去脏兮兮的饭馆吃并不正宗的兰州拉面.她认为,自己的生活太不协调.这样的恋情,从开始的那一天, 便仿佛注定了某一种结局. 他每天去接她,然后送到她所居住的白领公寓的电梯口, 道一声晚安,匆匆离去.那天她突然想撒娇,她说背我上去吧!他看了看电梯,电梯运转良好, 然后他回头,说,好.他没问理由.他背着她,从一楼开始,慢慢向上爬.爬到一半他累了,他说休息一下好不好,她突然来了兴致, 娇嗔着说不行.他就真的没有休息,一直爬到她的寓所所在的13楼. 她问他累不累,他说累,比扛包累.她知道他说的是真的 , 她有了一丝感动.但他们还是分手了.因为有时候,仅有感动,并不能够将爱情维持 .爱情的本身,除了感动,好象还有太多的琐碎.城市里并不缺少一个扛包工人,所以他回到乡下. 他偶尔会给她打电话,告诉她他现在种着大棚,挣了一些钱.她听着,淡淡的. 那时她已经有了新的男友,门当户对的,可以充门面,协调生活的那种. 然后某一天,他有一次打来电话,说他攒够了五千元钱,这些钱可以在乡下娶老婆了.她发现,突然间,自己的眼角,竟然有些湿润.她新交的男友也是每天接她下班,送她至电梯,很绅士地道一声晚安,然后离去某一天她说,背我上去吧.男友说 ,行. 那时电梯停在一楼,男友背起她,飞快地冲进电梯.她伏在男友的背上,与电梯一起爬升,心却在飞快地下沉.男友嘿嘿笑着,好象对自己这个带着幽默的小伎俩很是满意.那一天,她没有接受男友照例的吻别. 她给他打电话,她问他那五千块钱花出去了吗?然后她便发现自己泪流满面.他说花出去了。她扔掉了电话,那一刻, 她觉得自己正在失去整个世界. 几天后她在电梯门口看到他,他的手里拿着一枚戒指,很高档. 他把戒指扬了扬,说, 五千块.她乐了.然后她开始哭泣,哭得一塌糊涂.她说背我上去?他说好.然后他背着她,一步步爬着楼梯.途中他累了,他说这次让不让休息,她说不行不行.他就沉默着,一直爬到了13层.这时她想,如果一个男人,肯背着一个女人爬最漫长的楼梯,甚至可以不问理由,那么,这个女人,还有什么理由拒绝他呢?她给了他一个长久热烈的吻.

你的手机号招桃花吗? ...邪的很

一个好的手机号码是非常重要的,而且更重要的是,手机的数字也有改运的功效,想要让自己的爱情运顺利,或是想要增加财运,下面就为让小编给你介绍一下每个号码所带来的运势吧! 算法: 1请把手机号码的每个数字加起来,比如说小明的手机号码是13977221100,那就把1+3+9+7+7+2+2+1+1+0+0=33 然后再3+3=6 什么样的手机号码会带来怎样的效果呢?
手机灵数1 闲杂人等勿近 这个数字会带给你独立自主的精神,但是也因此而有些孤僻的倾向,这支手机常常会没接到电话,或是会过滤掉不少人的电话,所以大部分的时候都是你再打电话给别人,别人可能会因为一直打不通你的电话而放弃! 桃花指数:这个数字的爱情电力几乎为零,因为很可能会漏掉喜欢的人打来的电话,让你懊悔的要死,甚至打回去对方也不一定接得到,尤其是当对方的手机号码跟你不合时。不过反过来说,如果想要躲避烂桃花的话,这个号码倒是非常好用的,保证可以阻挡那些狂打你电话的苍蝇。 手机灵数2 情人专用热线 这个手机号码会有强大的待机功能,可能会持续等待他人回电或是打电话给你,通常很少漏接正在等待的电话,2号数字会让你接电话的次数比打电话多得多,尤其最重要的,一定不会漏接情人或是心仪对象的来电! 桃花指数:这个号码的爱情电力极强,就算是快没电了,通常也可以撑到跟情人热线完才段掉,可以说是情人的专用手机号码,最适合正在热恋期的情侣们使用,确定对方一定可以接到自己打的电话。而且一旦跟情人通电话,那么其他的闲杂人等,就只能排在情人之后,等热线完才接得到其它电话。 手机灵数3 强力发电机 3号手机灵数可以说是号码中的极品,因为他掌管的就是手机最重要的沟通交流功能,许多当面都很难沟通的对象,遇到这个号码简直就是救星,会立刻变得沟通无障碍!这个号码很少有接不到电话的screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='点击在新窗口浏览图片\nCTRL+Mouse 滚轮可放大/缩小';}" onclick="if(!this.resized) {return true;} else {window.open(this.src);}" src="http://image.onlylady.com/bbsimages/smilies//new/128.gif" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='点击在新窗口浏览图片\nCTRL+Mouse 滚轮可放大/缩小';}" border=0>扰,非常适合聊天使用。 桃花指数:3号手机灵数的爱情电力其实并不低,不过因为其对象比较多,不如2号专一,所以电力比2稍低一些,不过因为许多爱情都是从聊天开始,这支手机将会让对方感觉聊天无比愉快,欲罢不能,很快地发出颇强的电力,不用太多次,保证每个和你聊过天的人都会对你念念不忘。 手机灵数4 超级事务机 手机灵数4的最大特点在于没有用的来电是接不到的,能够接到的电话必定都是无事不登三宝殿,越是重要的事就越不容易漏接,所以依此类推,那些找你吃喝玩乐的来电就很少打得进来了,因而最适合推荐给忙碌的人使用。 桃花指数:灵数4的手机爱情电力极低,通常情人打来不是接待事情,就是做例行的问候,讲不了几句就没有话可讲了,甚至也蛮容易错失情人的来电,因而非常不建议求爱的人使用。当然如果不想听过于肉麻恶心的话,此号码是上上之选,保证每一句话都很正常,对着4号手机真的比较难嗲起来。 手机灵数5 超强咨询站 灵数5的手机号码才真是最强收发的超强咨询站,不管到哪里,不管要收什么,灵数5号绝对不会让你失望,就算只是小广告、会员通知,这个号码都照单全收,绝对不会漏接任何资讯。另外这个号码也最适合全区漫游的服务。 桃花指数:手机灵数5的爱情电力可以说普通强,因为5号几乎可以说是损友专用机,因为正经事5号机还有可能会不小心漏接,但是找人出来玩乐的事,不管到哪里都收得到。如果你喜欢联谊、参加活动,这个讯号可以帮助你时常受到这类讯息,当然也有可能因此而为你带来许许多多的恋爱机会! 手机灵数6 无敌浪漫手机 灵数6号的手机号码是非常浪漫的,也就是说最适合用手机谈恋爱,如果想用电话让感情加温,那么6号是最好的选择。当然不是想拿这个机子来谈恋爱的人,其实就比较不宜选这个号码,因为这支手机是很容易营造暧昧气氛的。 桃花指数:手机灵数6真的是爱情超级发电机,本来没有什么感觉的人一旦用了这个号码,似乎就渐渐的暧昧起来,真是太神奇了,非常推荐想要招桃花与恋爱的人使用,光讲电话,就可能谱出一段美美的恋曲。当然6号机真的很时候拿来撒娇,如果你觉得需要增加一点可爱特质,那么选6号就没错了。 手机灵数7 超性格派机种 灵数7的手机号码肯定是最性格的手机了啦!平常的来电大多爱接不接的,会增加你特立独行的气质,而且通常7号后继八卦话题极少,沟通想法与事务的机会比较多,所以如果觉得自己不够酷、不够有个性,就选用7号吧! 桃花指数:手机灵数7根本就和爱情不合,可以说是超级斩桃花机了,如果你就是快要被烂桃花烦死了的人种,那7号肯定会对你有帮助啦!用7号机讲话,每一句话都清楚理性,想要说句无厘头的情话都讲不出口。如果你的情人埋怨你老师讲大道理,赶快看看是不是不小心选到了爱情上天怒人怨的7号机。 手机灵数8 大发好运机 手机灵数8的人人脉极高,而且通常都是有用的人脉,让你的手机消息灵通,但却又没有不中用的怪短信。8号是一个顺畅的数字,非常时候时常需要交流应酬的人,8号将带给你旺盛的气势,还有意外获利的机会哦! 桃花指数:8号在爱情电力上并不是很足够,只能说是普普通通罢了!不过8号很懂得吃喝玩乐,所以这将会成为你的魅力之一,利用这些才能让你在爱情上加分!手机灵数8很少有浪漫的对话,通常比较多准备去吃喝玩乐的讨论,这是个享受的号码,一起享受的吸引力,更甚于爱情的电力。 手机灵数9 奇人异事机 手机灵数9事个什么电话都会收到的号码,而且通常接到的闲杂短信或电话比有用的还多,有时会意外的断线。这真是一支奇怪的号码,不过这个号码会为你带来感应力,你常常有身准的预知力,甚至知道谁就要打电话来了! 桃花指数:手机灵数9并不是没有爱情电力的,但是它为你带来的是一种宿命缘分的感觉,就是会注定会接到谁的电话,但一直接不到另一个人的电话,似乎冥冥中有缘分安排。不过9号也可以是爱情热线的,但是通常不会太过持久,容易降温。

辣妹“缠胸”招效果赛隆乳

现在到底有多少方法可以改变女性的胸部造型呢?又有哪些方法比较可取呢?学者们就丰胸市场的几大热点做出以下分析,并从安全、有效、健康、美观等几个方面进行了各项积分的评定。
  就生理功能而言,乳房首先是哺乳器官。乳房内部的结构为输乳管、乳腺小叶和腺泡,以及不等量的脂肪、纤维组织等。少女自12岁左右步入青春期,由于受到内分泌激素的刺激,乳房开始发育,16岁左右发育定型,25岁以后一般不再增大。乳房发育成熟后,其大小和形态往往因人而异。
  现在到底有多少方法可以改变女性的胸部造型呢?又有哪些方法比较可取呢?学者们就丰胸市场的几大热点做出以下分析,并从安全、有效、健康、美观等几个方面进行了各项积分的评定:
运动(评分:100分)
  游泳。游泳除了对肺部有益外,对乳房健美也有帮助。尤其是蝶泳和自由泳,这两种泳姿最易使胸部肌肉强韧,乳房丰满。
  俯卧撑。俯卧床上,身体放正直,双手支撑身体时收腹挺胸,双臂与床成90° 角;卧低时胳膊弯曲,身体不能着床。渐次增加次数。
  扩胸操。仰卧长凳上,两手拳心相对,持哑铃内收到胸前,然后两臂向两侧外展,动作应轻柔缓和,哑铃向胸前内收时吸气,来回数十次。
  韵律操。在韵律中舞动上身及手臂,使脊椎大幅度弯曲、伸直,也可使胸肌发达,从而使乳房坚挺饱满。
运动(评分:100分)
  游泳。游泳除了对肺部有益外,对乳房健美也有帮助。尤其是蝶泳和自由泳,这两种泳姿最易使胸部肌肉强韧,乳房丰满。
  俯卧撑。俯卧床上,身体放正直,双手支撑身体时收腹挺胸,双臂与床成90° 角;卧低时胳膊弯曲,身体不能着床。渐次增加次数。
  扩胸操。仰卧长凳上,两手拳心相对,持哑铃内收到胸前,然后两臂向两侧外展,动作应轻柔缓和,哑铃向胸前内收时吸气,来回数十次。
  韵律操。在韵律中舞动上身及手臂,使脊椎大幅度弯曲、伸直,也可使胸肌发达,从而使乳房坚挺饱满。
食物(评分:80分)
  女性大都希望自己拥有丰满坚挺的乳房,试图尝试丰胸秘方,但却未见期望的效果。其实,从月经周期的第一天开始,卵巢激素就已经扮演好驱动乳房、使其自平坦逐渐变向丰满的角色了。所以女性们应该好好利用自己与生俱来的“资源”,掌握在每个月丰胸的最佳时期,通过健胸运动、饮食、按摩等适时地激发乳房,使其慢慢增大。
  从月经来时算起的第11、12、13天为最佳时期,第18~24这七天为次佳时期,在这10天中影响胸部丰满的卵巢激素是24小时等量分泌的,这也正是激发乳房脂肪囤积增厚的最佳时机。在这10天的饮食中,必须摄取适量下列食物:青椒、番茄、胡萝卜、马铃薯和坚果类等,并要多喝牛奶,少喝可乐、咖啡。
按摩(评分:70分)
  近来,国外有学者主张用按摩促使乳房丰满:每天早上起床前和晚上临睡前,分别用双手按摩乳房10分钟。方法是:仰卧床上,由乳房周围向乳头旋转按摩,先按顺时针方向,后按逆时针方向,以乳房皮肤微红时止,最后提拉乳头5~10次。
  这样可以刺激整个乳房,包括腺管、乳腺脂肪、结缔组织、乳头和乳晕等,使乳房日趋丰满而有弹性。另有水按摩法:淋浴时,尽量用莲蓬头将温水或冷水对着胸部冲击,以促进血液循环。这样做不但可以让乳晕颜色以及乳房形状更加漂亮,还可以预防胸部皮肤松弛。需要注意的是:不能用太热的水冲洗胸部。
 手术丰胸(评分:60分)
  液体材料隆乳术。通过注射,使液态材料进入乳房组织。优点是方法简单,易于实施;缺点是尽管手术的安全性日益提高,感染率被控制在1%以下,但隆胸毕竟属于创伤性手术,对人体有潜在性损害。希望女性在选择手术隆胸时一定要三思。
  药物(评分:50分)
  与花钱多、风险大的丰胸手术相比,药物丰胸优势明显。但有些女性试图通过服用雌激素隆乳,常出现恶心、呕吐、头晕等症状,更严重的是,服用雌激素会增加乳腺癌的发病率。如何提高产品的信誉度和实际效果,仍是当前丰胸药物面临的一个重要问题。