回复 20# 宅男-兜着走
我知道了,比如說...(goodday老大教的)
- if(progressbar1.value = progressbar1.maxvalue){progressbar1.value = progressbar1.minimum;}
如果你是這樣
- if(progressbar1.value = 100){progressbar1.value = 0;}
另外一種,
- private void button1_Click(object sender,eventargs e)
- {
- button1.text = "lol";
- }
上面這個code,當時goodday說sender是這個void元件的properties,我就奇怪爲什麽sender只有.tostring和equalto,其實上面的寫法很奇怪,因為button1_click又用button1.text =,OOP的話應該是這樣(動物會排泄的原理)
- private void button1_Click(object sender,eventargs e)
- {
- (button)sender.text = "lol";
- }
好了,什麽叫做打比較多code?
比如說一個form裏面有100個button,我要按下的button.enabled = false,按下的而已,就要這樣
- //把全部的Click event 放在buttons_click
- private void buttons_click(object sender,eventargs e)
- {
- (button)sender.enabled = false;
- }
- private void button1_click(object sender,eventargs e)
- {
- button1.enabled = false;
- }
- private void button2.........
打死你
還有一種我會的就是(也是goodday老大教的,話說當時他講我完全聽不懂有什麽用途……寫久了才發現到它的用途)
如果現在有menu strip,notify icon,context menu strip,button等等的功能都是做某某很長的code,如果我寫四個的話
- private void xxxxxmenustrip_click(object......)
- {
- //blahblahblah
- }
- private void xxxxxnotifyicon_press(object.....)
- {
- ///blahblahblah
- }
- //以此類推,做四次
- private void xxxxxmenustrip_click(object...)
- {
- YOURFUNCTION();
- }
- //其他三個不重複了
- private void YOURFUNCTION()
- {
- //在這裡寫你的code有問題的時候改這裡就可以了
- }
- private void xxxxmenustrip_click(...)
- {
- YOURFUNCTION();
- YOURFUNCTION_TEXT = (menustrip)sender.text;
- }
- string YOURFUNCTION_TEXT;
- private void YOURFUNCTION()
- {
- string aaa = yourfunction_text;
- }
- private void xxxmenustrip_click(...)
- {
- YOURFUNCTION((menustrip)sender.text);
- }
- private void YOURFUNCTION(string text)
- {
- string aaa = text;
- }
這樣就簡單多了,可說是效率吧……