2008年10月26日

Xen虛擬機器

作者: Rokund (....) 看板: Linux
標題: [心得] Xen虛擬機器
時間: Tue May 15 13:26:43 2007

原本只使用Windows上的Vmware,昨天找了一下Linux上的虛擬技術
Xen應該算是較成熟的吧!但發現Xen在不同distribution有很多不同的用法
感覺很混亂。

我的理想狀況是希望管理VM的那個系統愈小愈好,且佔的資源也愈
小愈好,而Xen是以Paravirtualization的技術為基礎,跟vmware不一樣,因此
效能也較好,符合我的需求。
但是為了要能利用到Paravirtualization
,Guest OS的核心是要有所不同的,而Windows核心是無法修改,
因此要利用Xen灌Windows,CPU要有支援才能,
我查了一下,AMD的大概Athlon 64 3000+以上系
列都可,Intel沒在用不知道。如果灌其他的大部分linux的話,就不限
CPU了。

下面是找到的幾個比較詳細的資料。

=================1. XenExpress===================
第一個找到的是XenExpress,它是由CentOS修改,安裝後可執行Xen的
系統,免費的。而且只有六七百MB -
http://www.xensource.com/products/xen_express/
它還有另外兩種版本,是要錢的。

安裝過程就不要說了,在網路上找到的資料,都是要利用到兩台電腦
假設有A, B兩台電腦

A灌XenExpress - 想成是一種可run xen環境的linux distribution
B灌Administrator Console - 可灌在windows或linux,是一個有GUI
介面的應用程式。

當A灌好之後,利用B上的Administrator Console以網路連線到A,
在B電腦上的這個GUI應用程式可以控制A灌新OS或管理OS等等。

心得:雖然這個distribution是專門用來run xen,也夠小,但還要用
到兩台電腦,不是我要的,不知道可不可以直接在A上操作每個OS...
=======================================================

==============2. 用Fedora+Xen=======================
http://www.powermag.com.tw/NetAdmin/Xen/
我主要是在上面這個網頁找到,寫得很詳細,跟XenExpress不同的是
它說連線到Guest OS的方法是利用VNC等遠端遙控軟體連進去...
這個也讓我感覺很懷疑,怎麼不是像vmware一樣直接跑畫面出來?
======================================================

===============3. Xen on SuSe 10===================
這篇文章是在鳥哥的網站上找到的
http://linux.vbird.org/
文章在在網友投書裡面
它應該就是我要的,在單一機器上顯示出Guest OS的畫面,而不是
利用網路遠端的方式連進去,但這個OS應該裝了一大堆沒用
到的東西,如果只是要當做管理VM的系統好像肥了點。
=================================================

其實我是覺得可以利用XenExpress改成直接顯示Guest OS畫面
而不是用網路連線,只是我沒有那個機器去試,不知道有沒
有人有試過的可以解決我的疑惑,要使Guest OS直接(也就是非透過vnc等
遠端遙控軟體)顯示於裝Xen的電腦畫面上,還可以全螢幕顯示
,又可切換不同OS,save , restore等等功能,Xen是否辦得到?

我覺得虛擬化技術很有趣,除了可以充分利用硬體資源外,
又對資安有很大的提升,有興趣的人可以玩看看。

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.136.147.164


發信人: alang.bbs@bbs.sayya.org (alangnet), 看板: Linux
標 題: Re: [心得] Xen虛擬機器
發信站: SayYA 資訊站 (Wed May 23 13:15:13 2007)
轉信站: ptt!ctu-reader!news.nctu!SayYa

看了 XenExpress 官方說明,如果要在同一部電腦執行 server & console 應該不成問
題才是,將 console 軟體裝在 server 機器上,連線時 IP 用 127.0.0.1

這與 vmware-server 的使用方法很類似



※ 引述《Rokund.bbs@ptt.cc (....)》之銘言:
> =================1. XenExpress===================
> 第一個找到的是XenExpress,它是由CentOS修改,安裝後可執行Xen的
> 系統,免費的。而且只有六七百MB -
> http://www.xensource.com/products/xen_express/
> 它還有另外兩種版本,是要錢的。
> 安裝過程就不要說了,在網路上找到的資料,都是要利用到兩台電腦
> 假設有A, B兩台電腦
> A灌XenExpress - 想成是一種可run xen環境的linux distribution
> B灌Administrator Console - 可灌在windows或linux,是一個有GUI
> 介面的應用程式。
> 當A灌好之後,利用B上的Administrator Console以網路連線到A,
> 在B電腦上的這個GUI應用程式可以控制A灌新OS或管理OS等等。
> 心得:雖然這個distribution是專門用來run xen,也夠小,但還要用
> 到兩台電腦,不是我要的,不知道可不可以直接在A上操作每個OS...
> =======================================================
--
[1;32m※ Origin: [33mSayYA 資訊站 [37m [m
[1;31m◆ From: [36m211.72.159.130 [m

eBay要賣Skype 微軟、Google搶著要(2008/10/25 00:38)

資料來源處: http://www.nownews.com/2008/10/25/11490-2355101.htm

eBay要賣Skype 微軟、Google搶著要(2008/10/25 00:38)

科技中心/綜合報導

MSN和Skype原本是兩個各自為安的聊天軟體,最近卻有可能成為引發微軟和Google的併購戰火。由於2005年拍賣網站eBay在買下Skype之後,一直沒有見到併購之後的獲利效果,日前傳出想出售Skype的打算,微軟和Google為搶奪通訊市場,不排除向Skype招手。



2005年以26億美元買下Skype的eBay網路公司,在過去將近3年裡,原本希望藉由Skype通話的便利性增加網路拍賣的收益,不過如意算盤打錯,不但沒賺頭,反而增加營運成本。但是Skype本身還是擁有每年46%的成長率,繼續在網路市場開疆闢土,光是在2008年第三季就增加3200萬名用戶,比去年同期成長51%。因為沒獲益,現在傳出eBay有易將Skype出售。



消息一傳出,原本就積極打進網路通訊市場的Google,似乎有意願開價買進Skype,不過,為保持網路通訊的龍頭地位,微軟也不甘示弱,在Google之後表示也有意收購Skype。兩家公司搶著要,目的就是看準全球1.7兆美元的通訊商機,而Skype手上的3億7千萬客戶,就成為大家眼中的金雞母。(新聞來源:東森新聞)

2008年10月25日

微軟緊急公布MS08-067安全更新 避免駭客取得電腦控制權

資料來源:http://tw.news.yahoo.com/article/url/d/a/081024/35/1885j.html

微軟緊急公布MS08-067安全更新 避免駭客取得電腦控制權
更新日期:2008/10/24 16:57 特約記者薛怡青/台北報導
【特約記者薛怡青/台北報導】上星期微軟才剛發布10月分的安全更新程式,卻又在這兩天緊急發布了MS08-067緊急安全更新,這個漏洞威脅將全面影響所有的Windows版本,從Windows Server 2000, Windows XP、Windows 2003等系統的影響最大,駭客透過該漏洞侵入使用者電腦,並取得電腦的控制權。

根據微軟安全公報KB958644中提道,除了Windows Server 2008 Core不在此漏洞攻擊的威脅之外,從Windows Server 2000, Windows XP、Windows 2003等系統,甚至包括仍在預覽測試階段的Windows 7 Pre-Beta也都受到此安全漏洞的威脅。使用者若未趕緊下載安全更新程式,將可以引發大全面性的遠程攻擊以及電腦完全被控制的風險,更有人認為這次的嚴重性屬於「只要插上網路線就會中標」的嚴重等級。

目前經查詢該漏洞的結果是,駭客利用「TrojanSpy:Win32/Gimmiv.A」與「TrojanSpy:Win32/Gimmiv.A.dll」惡意程式發動攻擊。一旦受到漏洞攻擊,系統收到一個特製的遠端RPC請求,入侵之後則可以允許遠端執行任何代碼,並且不需經過認證,就可以執行任意代碼。而微軟方面目前已經透過「微軟惡意件保護中心」發佈了相關因應的惡意件特徵代碼。

建議使用者可以到以下網址下載安全更新:http://www.microsoft.com/technet/security/Bulletin/MS08-067.msp

2008年10月12日

seagate 硬碟如何送修??

小弟這個seagate硬碟最近發現有壞軌,經造成造成檔案損壞,猜想應該是快掛了,所以趕緊買了一個新HD使用,並想辦法送修.詢問店家是說要送代理商(亞銳士),並要付600元手續費,後來上網查詢亞銳士網站不只要付600元,還要等最慢45天!且五年保固機種滿三年後將不負責後送之責任...

所以就開始上網找送修的方式,先打電話給SEAGATE客服,他要我先上網登錄取得RMA號碼後才可送修,所以就開始展開冒險的精神....

1. 登入 官方網站 https://www.seagate.com/www/zh-tw/Home/ ,如果沒有帳號,請先註冊。

註:官方網站有支 援中文,請記得切換成中文。

seagate0012. 支援 > 保固和退貨協助 > 確認保固並提交退貨 > 步驟 3:確認保固並進行退貨

運送到國家地區 請選Taiwan ,型號及序號請參考該晝面右邊範例說明,寫填完成後,按 "提交" 送出

seagate002

3. 接下來會顯示該硬碟的保固狀態,如果沒有問題,請按 "繼續"。

seagate003

4. 填寫出貨/請款資料,也就是我們的資料,填寫完成後,請按 "查核訂單/付款"

seagate004

5. 查核訂單,產品的運送地點請選擇以下的地點,畢竟我們是在台灣,再下面是送修明細,上面會說明送修硬碟的規格、數量及費用,如果沒有其他問題,請按 "提交訂單" 完成送修單填寫。

UPS SCS (Taiwan) Co., LTD.
Dennis Yu (886-3-2121234 ext 315)
UPS Supply Chain Solutions (Taiwan) Co., Ltd.
No.1676, Zhongzheng N. Rd.
Luzhu Shiang
Taoyuan
Taiwan R.O.C, 338
Taiwan

seagate005

6.訂單確認

seagate006

7.請將訂單印出來,一份留著,另一份與硬碟打包,將地址標籤印出來貼在包裹寄出既可,在寄出前先打電話至

UPS SCS (Taiwan) Co., LTD.Dennis Yu (886-3-2121234 ext 315) 聯絡一下,確認他們仍有收件服務.

2008年10月11日

料理

■塵式生活風 - 特製苦瓜鑲肉
http://www.wretch.cc/blog/guruma/7087483

■苦瓜封肉湯 @ Amandaㄝ燥咖 PIXNET 痞客邦
http://amanda326.pixnet.net/blog/post/10282124

■甜。 鳳梨苦瓜湯
http://lizsan.spaces.live.com/Blog/cns!1pXHAtT-SR_ahzFuEDekxInA!452.entry

■《 鳳梨苦瓜雞湯 - 食譜 》 - All About Life - 關心觀心 - PChome新聞台Blog
http://mypaper.pchome.com.tw/news/renny612/3/1276421245/20061205005208/


■【小林食譜】鳳梨苦瓜雞湯
http://www.epochtimes.com/b5/4/9/10/n656939.htm

[問題] raw和jpg到底差別在哪??

作者: wliu (威) 看板: DSLR
標題: Re: [問題] raw和jpg到底差別在哪??
時間: Fri Oct 10 14:14:16 2008

※ 引述《ozaki520 (我不要)》之銘言:
: 想問一下raw和jpg到底差別在哪(檔案大小除外)
: 我各拍了一張raw和jpg的照片!!
: 基本上只有容量不同 其餘都一樣
: 而我用修圖軟體也是一樣可以修(修圖程序兩者一樣)
: 那請問raw到底有哪邊不一樣??還是說給專門修圖的人修真的會比較不一樣嗎??
: 那反之拿jpg的檔案給專們的人 那也不就也會很好看??
: 所以對於raw還真有點疑惑

ccd/cmos感光,接收資訊(取得raw)
-> 相機晶片處理(套用相機設定,白平衡、對比等等)
-> 輸出jpg

這是按下快門後到記憶卡上的jpg檔的大概流程

拍raw的話,就是在raw產生之後的動作都不做,跳過相機轉圖的動作
就存檔,然後你必須在電腦上,用專門的軟體,去把本來該在相機做
卻還沒做的動作完成

而差別最主要的就是raw記錄了更多的資訊,不管是白平衡,還是寬容度,
都能比jpg有更大的彈性

我想到一個例子
例如說你要把一個word檔的內容印出來

word檔就相當raw,印出來的紙就相當於jpg

當你覺得這個文件的內容要改的時候

你覺得
在word檔上修改,再印出來

跟把印出來的紙用立可白修,或拿東西貼

那一個調整的能力比較強,跟效果比較好呢??


你會覺得沒感覺,主要是你調整的程度可能不夠大,差異太小你沒辦法分辨出來
你可以先拍一張白平衝非常不準,或是曝光不足跟過曝的照片
再來調,應該就能比較明顯感受到了

(raw檔要用能解raw的軟體調,先存成jpg再來調就一樣了)


--
http://wliu.no-ip.org/wordpress
http://www.flickr.com/photos/silencetoy


--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.178.156
推 hiho :有時感覺一般照片要調很大的根本是技術未夠班~特效除外 10/10 14:16
推 nataray :這個舉例我喜歡! (筆記) XD 10/10 14:21
→ nataray :照片要調很大其實就是拍攝當下拍失敗了,無法挽救 orz 10/10 14:21
→ wliu :若相機自動白平衡不準,技術就難克服了,除非每次都用自定XD 10/10 14:25
推 ad47 :RAW檔解通常也比較銳利 求完美者會選RAW~不一定是要調很大阿 10/10 14:29
推 MapleWang :這比喻不錯 :D 10/10 15:29

2008年9月15日

【新奇】Google可攜式搜尋面板

不知道有沒有支援中文................ 一 一|||      殘念!!!!

相關連結:http://petitinvention.wordpress.com/2008/02/10/future-of-internet-search-mobile-version/

此科技Microsoft跟Google正在積極研發中 

【新奇】Google可攜式搜尋面板


不知道大家小的時候有沒有看過七龍珠呢? 裡面的賽亞人有一個可以偵測跟分析戰鬥力的儀器,
雖然以前覺得很科幻但是這項技術其實已經慢慢在研發了,相信未來不久就會出現在大家眼前
而今天就是要介紹一下這個大家夢寐以求的新產品Google可攜式搜尋面板,
可不要小看這薄薄的一張面版,裡面內建了WIFI、Google 搜尋、Google圖片搜尋、
觸控式螢幕、相機、掃瞄器、無線網絡、Google Map(如果改成Google Earth的話會更好吧)
等...功能在,就像下面這張圖透過它來看整棟樓會馬上出現搜尋的結果,

future_search1_petitinvention-490x490

你不僅可以看整棟樓,也可以詳細到只看其中一層樓的資訊,馬上就出現聯絡電話跟聯絡人姓名了,

不過不知道這樣會不會侵犯到隱私,當然這個面板不只是只能搜這些而已,

它還可以搜尋其他物體像是汽車,走在路上突然看到一台很帥的車

卻不知道叫甚麼名子也不知道裡面的性能等詳細資料,

或是出遊時不知道附近有什麼好吃的食物或看到很漂亮的花跟很奇特的不知名昆蟲

等等只要在這個機器上做選擇它都可以即時幫你查到相關資料。

future_search2_petitinvention-490x490

這台內建掃描器,所以當你有遇到不知道的詞或單字也可以搜尋一下,

future_search3_petitinvention-490x490

這個單字的各種解釋就會馬上出現,你也可以利用各種字典跟維基百科,這樣是不是方便很多了呢

future_search4_petitinvention-490x490

市內導覽可在任何建築物內,機場,車站,醫院等地方達到引路的功能

other_purposes-1-490x490

線上即時翻譯拉丁文馬上變英文,只是不知道翻的好不好。

other_purposes-2-490x490

如果你想在密密麻麻的報紙裡面找到一些你比較感興趣的文字也可以使用關鍵字搜尋喔

other_purposes-3-490x490

就連天空上的星星也可以研究喔,感覺比天文台還要好了@@

future_search3-1_petitinvention-490x490

甚至也可以預先看到開花後的樣子喔

future_search3-2_petitinvention-490x490

再來就是養生者的福音了,它可以幫你分析食物裡的營養成分、熱量等

future_search4-1_petitinvention-490x490

future_search4-2_petitinvention-490x490 

最後還滿期望這個產品能趕快出現在市面上,這能帶給我們更多更好的搜尋跟便利阿。

2008年9月3日

記事本

http://picasaweb.google.com/robbin0919/20081031_#

http://picasaweb.google.com/robbin0919/Jasmine_#


http://kate.babyface.com.tw/NetAdmin/08200609Xen/

http://old.vosonic.com.tw/index.php?PA=support&str=firmware&id=26

http://www.wireshark.org/

12.75 * 8 =102
9.45 * 5 =47.25
5.8 * 10 =58
----------------------
9.01087

ruby@csi.com.tw

你週六要一早就到台中嗎?
jeffsu@aptg.com.tw 說:你坐8:00台北-->台中 8:52


有敬茶
依序敬茶後

收茶杯
長輩會押紅包

改稱呼後
開始掛戒指儀式
然後吃湯圓
再來就是準備工作
拍拍工作人員等等


■Google Chart API controls for Asp.NET
http://www.codeplex.com/GoogleChartNet

■東風 http://www.aziotv.tv/sysmanager/scheduleList.asp
■旅遊生活頻道 http://www.travelandliving.com.tw/asia/homepage.htm

■Inside AdSense-Traditional Chinese (中文)
http://zht-adsense.blogspot.com/?utm_source=aso&utm_campaign=ww-zh_TW-et-tipsbox&utm_medium=link

MoneyDJ理財網~技術分析學院
http://www.funddj.com/z/analyst/analyst1.htm

■A flexible charting library for .NET
http://www.codeproject.com/KB/graphics/zedgraph.aspx


■Main Page - ZedGraphWiki
http://zedgraph.org/wiki/index.php?title=Main_Page

■asp.net blog 的 source
http://www.dotnetnuke.com/opensoure

to yuchang660321

因為您這個婚禮拍攝須知問題蠻大的,所以單獨回給你,希望比較有系統,也希望有幫上忙,這一次感謝有那位在網路上很有名的專業婚宴攝影師一起研究,很多事情真的一學就會,所以也一起分享給各位,但記得吉米不是專業,只是連續15小時自HIGH學到一些東西,這只是第一次用閃燈的經驗分享,請務必研讀相關補光文獻,才能在攝影補光學上扎根。

1.事前準備
A.一定要用高容量充電電池,掛上第五電池盒(至少兩組十顆,建議eneloop或Panasonic)
B.準備五顆鹼性電池,雖然回電慢,但至少可以當備品應急(不要金頂和勁量,都有漏液經驗)
C.前一晚確定閃燈和電池都重新充電,不管有沒有滿格。(相機最好有兩顆以上的電池,D200例外)
D.確定你有多張高容量2G或4G記憶卡或兩張記憶卡加一台OTG(邊拍邊存才不怕記憶卡毀損而扼腕)
E.一定要有廣焦段變焦鏡(建議24-120mmVR、18-200mmVR、A09)
F.如果是全天拍攝,可準備24mm或35mm以上之定焦廣角大光圈
(一顆就好,會用不到,沒時間換鏡頭,有休息時間才可以跟新人玩景深遊戲)

2.閃燈使用須知
A.對於SB-800不熟的人,請務必開啟TTL+BL模式,這樣閃燈會自動分析主體與背景
(如果背景比例多餘主體,請另行斟酌。)
B.對於SB-800很熟的人,才使用單TTL(只對主體補光)或M或GN模式等手動模式。
C.戶內低屋頂:現場光源夠亮,打直跳燈加原廠柔光罩,如果光源不夠亮,使用45度或60度跳燈不加柔光罩。
D.戶內高屋頂:現場光源夠亮,打直跳燈拉出散光片與反光版。現場光源不夠亮或混亂,請閃燈直打加柔光罩。
E.戶外無反射頂:想要主體清楚補光,直打加柔光罩,想要均勻補光,請打直閃燈拉出閃光片與反光版。
F.一般不用柔光罩下TTL+BL直打,閃燈會自動分析焦端與光圈,如裝上原廠柔光罩會將閃燈強制設定在14mm。
G.SB-800的可使用範圍為14mm-105mm,太廣會出現暗區,太遠會GN值不夠,請務必確定主體焦段遠近。
H.每閃光完,會有一個高頻率的聲音,當聽到時間拉長時,如有多組電池就必須換電池,這是回電不足的徵兆。
I.不要太相信Ready燈,每一張照片有時間要看閃燈的LCD,如出現-EV訊息,代表回電不足,一定要換電池。
J.可以攜帶充電器,如果是一整天的婚禮,中午會有休息時間可以利用時間充電。
K.如不希望原廠遮光罩強制開啟14mm,可用副場軟式遮光罩來創造更多不同的補光模式。

3.婚宴搶拍原則:
A.婚禮非藝術照,沒有重來機會,寧爛勿缺,寧願無構圖或閃光不足,但是一定搶到畫面。(可全程用光圈先決)
B.確定進行流程,趕在新人前回頭拍攝,不要不好意思,留記錄才是前提,現場混亂要有爬上桌或趴地心理準備。
C.兩位攝影師閃光干擾一定會有,一定要事先溝通好誰構好圖先等第一閃才能再按快門閃第二次。
D.使用RAW檔拍攝,可以救回許多慌張設定錯誤照片。
(如果需要高速搶拍可用高ISO,但是記得要調回最低的ISO值)。
C.回電不足的照片會一片黑,但不要急著刪刪,如果是拍RAW檔,可以事後利用NC或NX來調整EV救回照片。
D.構圖不好的照片不要刪,在後製的過程的中可以利用裁減來重新構圖,所以現場要用最大解析度拍攝。
E.流水席會有現場混亂的缺陷,使用大光圈(F2.8)變焦鏡,利用散景來減低混亂又不失現場氣氛。
F.要有600張以上的心理準備,可以開啟連拍搶鏡頭,本次吉米全程15小時拍了1774張,可用照片約只有7成5。


PS.SB-800拉出的反光版,有另一個菱形透明版,那是讓光源更散的散光片,如果要用反光版建議這個也要拉出,不然反射的光效果會較不佳。

2008年8月30日

Formatting the Windows Forms DataGrid Control in Visual Basic

資料來源:http://msdn.microsoft.com/en-us/library/aa289506(VS.71,printer).aspx

©2008 Microsoft Corporation. All rights reserved.


Visual Studio Technical Articles
Formatting the Windows Forms DataGrid Control in Visual Basic

Seth Grossman
Visual Studio Team
Microsoft Corporation

December 2002

Summary: Quite a few basic tasks related to formatting the Windows Forms DataGrid control require you to create and implement your own custom column styles. However, once you are familiar with these objects, you will have a lot of power at your disposal. (11 printed pages)

Requirements

The following software is referenced within this whitepaper:

  • Visual Basic .NET 2002

Contents

Synopsis
Background
Column Styles
Basic Techniques
Advanced Scenarios
Conclusion

Synopsis

In this paper, you will:

  • Create a class that defines a custom column style for the Windows Forms DataGrid control.
  • Implement that class as a column within the DataGrid control.
  • Learn about other possible customizations to columns that will enhance the behavior of the DataGrid control.

Background

A number of tasks you may want to accomplish with the Windows Forms DataGrid control are, surprisingly, more difficult than you might expect. Primarily, this is because the Windows Forms DataGrid control is column-based, rather than cell-based. As a result, to accomplish most tasks, you have to work with the columns, not the cells themselves.

One example of a group of tasks that requires working with columns is changing the display properties of the grid (foreground color, background color, data format, and so on). These display properties are all maintained through column formatting.

Column Styles

To format columns, you need to create a column style. A column style is an object that defines what the column looks and behaves like, including such things as color, font, and the presence of controls, such as check boxes. The .NET Framework includes two types of column-style classes by default: the DataGridTextBoxColumn [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtextboxcolumnclasstopic.asp ] and DataGridBoolColumn [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridboolcolumnclasstopic.asp ] classes. The DataGridTextBoxColumn class exposes very basic "edit box" functionality; users can enter text into it. The DataGridBoolColumn class exposes a column of check boxes within the column to represent Boolean [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystembooleanclasstopic.asp ] values.

Since neither of these column styles enables you to color the cells of the grid, you will have to create your own custom column style.

Basic Techniques

To work with column styles, you need to create a column-style object and then implement the behavior you would like it to display at run time. Specifically, you need to inherit from an existing column style (either the DataGridTextBoxColumn or DataGridBoolColumn) and then override some of its functionality.

After creating the class, you have to tell the grid to use it. Later in the paper, you will find details about how to use the custom column-style class within the grid.

Step I: Creating a Custom ColumnStyle Class

One example of a custom column style would be one that displays a column of text that, when certain criteria have been met (such as a specific value in a cell), the cell's color is set.

The following example illustrates how to implement a column style that colors the cells of a grid when the value displayed in the cell is greater than 1. The code for this class inherits from the .NET Framework's DataGridTextBoxColumn [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtextboxcolumnclasstopic.asp ] class and overrides the Paint method, so that you can do custom painting of the cell. Note that this class expects the data in the column to be of type Integer.

Public Class ColoredTextBoxColumn
Inherits DataGridTextBoxColumn

Protected Overloads Overrides Sub Paint(ByVal graph As Graphics, _
ByVal rectbounds As Rectangle, ByVal curmngrSrc As _
CurrencyManager, ByVal RowNumber As Integer, ByVal _
ForeColorBrush As Brush, ByVal BackColorBrush As Brush, _
ByVal AlignmentRight As Boolean)

Dim ObjVal As Object
ObjVal = Me.GetColumnValueAtRow(curmngrSrc, RowNumber)

If Not (IsNothing(ObjVal) Or IsDBNull (ObjVal)) Then
Dim cellValue As Integer
cellValue = CType(ObjVal, Integer)
If (cellValue > 1) Then
' Here is where we are going to do
' the actual painting.
' Color the contents of the cell Red
' and the background of the cell Yellow.
BackColorBrush = Brushes.Yellow
ForeColorBrush = Brushes.Red
Else
BackColorBrush = Brushes.White
ForeColorBrush = Brushes.Black
End If
End If

' Call Paint from the base class to
' accomplish the actual drawing.
MyBase.Paint(graph, rectbounds, curmngrSrc, RowNumber, _
BackColorBrush, ForeColorBrush, AlignmentRight)
End Sub
End Class



In the code above, the cell's value is cast to an integer and the cells of the grid have their ForeColor and BackColor set based on some condition; in this case, the condition is "value is greater than 1". The cell's ForeColor and BackColor are painted using brushes from the System.Drawing namespace.



Step II: Programming with Your Custom Column-Style Class



Now that you have a created a custom column-style class, you can implement it within a DataGrid control.



The Windows Forms DataGrid control maintains a collection of table styles. A table style represents the details about how a specific table is drawn by the DataGrid control (the table is specified by the MappingName [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtablestyleclassmappingnametopic.asp ] property). Each table style contains a collection of column styles. For more information about the role of table styles and how they work, see Formatting the Windows Forms DataGrid Control [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskFormattingtheDataGridAtDesignTime.asp ] .



To make use of your custom column-style class, you first instantiate the new column-style and table-style classes. Then, you add the column style to the table style. Finally, you add the table style to the grid.



Note Adding these instances of the table and column styles to your datagrid control overrides all the existing column definitions.


Once you create a custom column definition and add it to the table, you need to define all the column styles in the grid. In order to do that, create instances of the base column style for each column you want to display and add them to the table style you created as well.






Public Sub AddFormattedColoredColumn()
Dim tsProducts As New DataGridTableStyle
tsProducts.MappingName = "Products"

Dim cstbProdName As New DataGridTextBoxColumn
cstbProdName.MappingName = "ProductName"
cstbProdName.HeaderText = "Product Name"

Dim cscolUnitPrice As New ColoredTextBoxColumn
cscolUnitPrice.MappingName = "UnitPrice"
cscolUnitPrice.HeaderText = "UnitPrice"

tsProducts.GridColumnStyles.Add(cstbProdName)
tsProducts.GridColumnStyles.Add(cscolUnitPrice)
DataGrid1.TableStyles.Add(tsProducts)
End Sub



In the code above, a new table style (tsProducts) and two new column styles (cstbProdName and cscolUnitPrice) are instantiated. The mapping names for all three are set to their respective table and columns. The column styles are added to the table style's collection of column styles; then the table style is added to the DataGrid control's collection of table styles.



Be sure to call the procedure above before the grid is loaded, so that the correct data is displayed by the grid.



Advanced Scenarios



Above is a basic description and implementation of custom column styles, which is intended to give you a general idea of how to manipulate columns and cells within the DataGrid control. At this point, there are a number of options available, if you wish to do more.



Setting Other Cell Properties



You can customize a number of different qualities that the cells of the DataGrid control exhibit. You can set column alignment and column width, and you can format your data for display.



Setting Column Alignment



You can set the alignment of the cell data within columns. The column object itself does not have an Alignment property; rather, a column's alignment is set by the column style.



The following example displays two columns, "Product Name" and "UnitPrice," and sets the alignment of the cells within each. This example assumes a DataGrid control (DataGrid1) displaying the "Products" table from the Northwind database with a ColoredTextBoxColumn column (code example above).






Public Sub AddAlignedColoredColumns()
Dim tsProducts As New DataGridTableStyle
tsProducts.MappingName = "Products"

Dim cstbProdName As New DataGridTextBoxColumn
cstbProdName.MappingName = "ProductName"
cstbProdName.HeaderText = "Product Name"
cstbProdName.Alignment = HorizontalAlignment.Left

Dim cscolUnitPrice As New ColoredTextBoxColumn
cscolUnitPrice.MappingName = "UnitPrice"
cscolUnitPrice.HeaderText = "UnitPrice"
cscolUnitPrice.Alignment = HorizontalAlignment.Center

tsProducts.GridColumnStyles.Add(cstbProdName)
tsProducts.GridColumnStyles.Add(cscolUnitPrice)
DataGrid1.TableStyles.Add(tsProducts)
End Sub



In the code above, once the column styles are created and their mapping names are set to the columns, the Alignment property is set.



Note In Visual Studio .NET 2002, the text of the column headers does not correctly display if the Alignment property is set to Center.


Setting Column Width



As with alignment, width of a column is specified in a column style; the column object itself does not have a Width property. The column object itself does not have a Width property; rather, a column's width is set by the column style.



The following example displays two columns, "Product Name" and "UnitPrice", and sets the size of each. This example assumes a DataGrid control (DataGrid1) displaying the "Products" table from the Northwind database with a BackColor/ForeColor column (code example above).






Public Sub AddSizedColoredColumns()
Dim tsProducts As New DataGridTableStyle
tsProducts.MappingName = "Products"

Dim cstbProdName As New DataGridTextBoxColumn
cstbProdName.MappingName = "ProductName"
cstbProdName.HeaderText= "Product Name"
cstbProdName.Width = 250

Dim cscolUnitPrice As New ColoredTextBoxColumn
cscolUnitPrice.MappingName = "UnitPrice"
cscolUnitPrice.HeaderText = "Unit Price"
cscolUnitPrice.Width = 150

tsProducts.GridColumnStyles.Add(cstbProdName)
tsProducts.GridColumnStyles.Add(cscolUnitPrice)
DataGrid1.TableStyles.Add(tsProducts)
End Sub



In the code above, once the column styles are created and their mapping names are set to the columns, the Width property is set.



Formatting Data For Display



You can format the contents of the cell into commonly recognized formats, such as currency or dates.



Formatting the string displayed within the cell of a grid can also be accomplished with the column style. As with specifying the column's width, it is as simple as setting a property. The Format [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridtextboxcolumnclassformattopic.asp ] property of the DataGridTextBoxColumn class allows you to set a number of basic formatting types.



Keep in mind that the operating system's culture setting will also determine aspects of how the string is displayed. Markers such as currency type, decimal indicator, and units of measurement are some of the variables determined by the culture being displayed.



There are a few standard formats used by most developers. Here is a table naming the format expression, the original value from the data source (Input), the format expression's practical effect on your data (Output), and a brief description of the formatting type. Note that all of the examples in this table have English-United States (en-US) set as their culture.



Format Expressions: "English/United States" Culture




































































































Format ExpressionCultureInputOutputDescription
den-USFebruary 12, 19762/12/1976Short date: The numerical month, day, and year.
Den-USFebruary 12, 1976Thursday, February 12, 1976Long date: The day of the week, month (spelled-out), day, and year.
Ten-US11:38:00 PM11:38:00 PMLong time: The hour, minute, second, and (in appropriate cultures) AM/PM designator.
ten-US11:38:00 PM11:38 PMShort time: The hour and minute and (in appropriate cultures) AM/PM designator.
Fen-USThursday, February 12, 1976 11:38:16 PMThursday, February 12, 1976 11:38:16 PMFull date (long time): The day of the week, month (spelled-out), day, year, hour, minute, second, and (in appropriate cultures) AM/PM designator.
fen-USThursday, February 12, 1976 11:38:16 PMThursday February 12, 1976 11:38Full date (short time): The day of the week, month (spelled-out), day, year, hour, minute, and (in appropriate cultures) AM/PM designator.
C (or c)en-US32.98$32.98Currency: A string representing a monetary value. The currency, decimal separator, and other numeric information are determined by the NumberFormatInfo [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemGlobalizationNumberFormatInfoClassTopic.asp ] class and the current culture set for that thread. See Setting the Culture and UI Culture for Windows Forms Globalization [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcustomizingsettingsforspecificcultures.asp ] for more information.



The entries in the table below are a subset of the available format expressions, each with a different culture set.



Format Expressions: Various Cultures




















































Format ExpressionCultureInputOutputDescription
Tes-ES11:38:00 PM23:38:00Long time: The hour, minute, second, and (in appropriate cultures) AM/PM designator.
ffr-FRThursday, February 12, 1976 11:38 PMjeudi 12 febrier 1976 23:38Full date (short time): The day of the week, month (spelled-out), day, year, hour, minute, and (in appropriate cultures) AM/PM designator. Note that ordering of values may change depending on the culture selected.
C (or c)jp-JP12132.98¥12,132.98Currency: A string representing a monetary value. The currency, decimal separator, and other numeric information are determined by the NumberFormatInfo [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemGlobalizationNumberFormatInfoClassTopic.asp ] class and the current culture set for that thread. See Setting the Culture and UI Culture for Windows Forms Globalization [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcustomizingsettingsforspecificcultures.asp ] for more information.



The format you select for the data in your grid will be driven by the data being displayed. Be sure to consider the local culture of the operating system your application will run on when implementing format expressions.



The following example displays a column ("UnitPrice") formatted as a currency. This example assumes a DataGrid control (DataGrid1) displaying the "Products" table from the Northwind database with a BackColor/ForeColor column (code example above).






Public Sub AddFormattedColumn()
Dim tsProducts As New DataGridTableStyle
tsProducts.MappingName = "Products"

' Create a new column style from the example above.
Dim csUnitPrice As New ColoredTextBoxColumn
csUnitPrice.MappingName = "UnitPrice"
csUnitPrice.HeaderText= "Unit Price"
' Set the format of the column
' NOTE: The data must be of type Integer to for it to be
' formatted correctly as a currency.
csUnitPrice.Format = "c"

tsProducts.GridColumnStyles.Add(csUnitPrice)
DataGrid1.TableStyles.Add(tsProducts)
End Sub



In the code above, once the column style is created and its mapping name is set to a column, the Format property is set to currency, so that the strings representing the price will be displayed in the appropriate format.



More information about formatting strings is available in the Visual Basic documentation. For a discussion of the different types of formatting strings, see Formatting Types [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconformattingtypes.asp ] . For a list of standard date/time and numeric format strings, see Date and Time Format Strings [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondatetimeformatstrings.asp ] and Standard Numeric Format Strings [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconstandardnumericformatstrings.asp ] .



Implementing Graphics Within Cells



In addition to formatting the contents of the cells, you can tell the grid to paint itself in a variety of fashions. The System.Drawing namespace provides you with some interesting options for customizing columns with graphics.



Creating Textured Backgrounds Using Brushes



If your project calls for something less traditional than the ColoredTextBox class we created earlier, you can use one of the brushes provided in the System.Drawing.Drawing2D namespace. As an example, try replacing the ForeColorBrush and BackColorBrush specified in the code sample in the section "Step I: Creating a custom ColumnStyle class":






BackColorBrush = New SolidBrush(Color.Yellow)
ForeColorBrush = New SolidBrush(Color.Red)



with the following code:






BackColorBrush = New System.Drawing.Drawing2D.HatchBrush _
(Drawing2D.HatchStyle.SolidDiamond, Color.Plum, Color.Thistle)
ForeColorBrush = New SolidBrush(Color.DarkBlue)



This new code uses an instance of the HatchBrush [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawingdrawing2dhatchbrushclasstopic.asp ] class to paint the background in a series of filled diamonds (the filled-diamond pattern is a member of the HatchStyle [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawingdrawing2dhatchstyleclasstopic.asp ] enumeration). You can experiment with the different brush options available in the Drawing2D namespace to find a combination that is appealing to you.



Note Be sure to call the Dispose method [ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawingbrushclassdisposetopic.asp ] when your code is finished using a brush.


Conclusion



As you can see, there are number of common tasks related to the Windows Forms DataGrid control that require creating and implementing your own custom column styles. Once you have begun working with these objects, a great deal of power is available to you. You can paint cells with a variety of brushes, set column alignment or width, or use the .NET Framework to format the contents of the grid's cells.





2008年8月25日

Blogspot表格的問題

作者: Shuhaur (D.K.) 看板: Google
標題: Re: [問題] Blogspot表格的問題
時間: Sun Aug 24 21:32:50 2008

※ 引述《rotch512 (孝順行善不能等)》之銘言:
: 因為我不曉得怎麼用 Blogspot 「直接」造出一個表格
: 所以就直接用 HTML 的語法寫
: 結果表格是出來了
: 但是表格上方有一大塊的空白
: 不曉得是否有板友遇過這樣的問題
: 請問該如何解決呢?




table


請用...


--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.121.23.220
※ 編輯: Shuhaur 來自: 122.121.23.220 (08/24 21:33)
[1;37m推 [33mChampionHare [m [33m:推 +1 [m 08/24 21:41