摘要:編寫C#數(shù)據(jù)庫展示類型的窗體程序時,往往會用到窗體的繼承技術(shù)。在介紹窗體繼承操作一般步驟的基礎(chǔ)上,還針對設(shè)計繼承窗體時通常會遇到的問題進(jìn)行了探討。在此基礎(chǔ)上,對于繼承窗體在Visual Studio C#可視化設(shè)計器中展示Access數(shù)據(jù)庫可能會遇到的問題進(jìn)行了討論,并提出了三種解決方法。
關(guān)鍵詞: C#;窗體繼承;窗體設(shè)計; Visual Studio; Access數(shù)據(jù)庫
中圖分類號:TP311.1 文獻(xiàn)標(biāo)識碼:A 文章編號:1009-3044(2014)31-7637-04
Abstract:While programming c# database application, the Windows Form inheritance method usually is often used. After introducing the general manner of Form inheritance in Visual Studio, the paper also covered the main points in successfully making the inheritance. Based on this, discussed the inheritance problems will be met when displaying Access file database table in Visual Studio C# designer mode, and finally proposed three ways to resolve the inherited Form design problem.
Key words: C#; form inheritance; form design; visual studio; access database
微軟公司的C#是一種面向?qū)ο蟮某绦蛟O(shè)計語言,同時借助于其高效的開發(fā)工具Visual Studio 引入可視化的開發(fā)方法,由工具來替代進(jìn)行一些重復(fù)性的、格式性的編程工作,降低了錯誤率,將開發(fā)效率大大提高。同時減輕了程序員的繁瑣的重復(fù)性的關(guān)于編碼格式方面的負(fù)擔(dān)。在利用可視化開發(fā)工具編寫面向?qū)ο蟮腃#程序時,類的繼承(Inheritance)是常常要用到的操作。繼承可以使代碼的重用性和可維護(hù)性得到本質(zhì)的提升。
C#的窗體自身也是一個類,繼承自System.Windows.Forms.Form。C#窗體的繼承就是指通過重用已存在窗體的類代碼來實(shí)現(xiàn)一個新的窗體類。這樣的操作可以通過編寫代碼來實(shí)現(xiàn),也可以通過可視化的操作來完成。
1.1 可視化方式完成繼承
之后就可以在設(shè)計器中順利打開子窗體的設(shè)計窗口了。該方案的優(yōu)點(diǎn)是解決方式簡單,缺點(diǎn)是在設(shè)計器窗口中將無法展示數(shù)據(jù)庫內(nèi)容。但是一般而言,在設(shè)計狀態(tài)也可以通過其他方式或工具來參考查看數(shù)據(jù)庫內(nèi)容,所以該缺點(diǎn)一般可以容忍和接受。
3 結(jié) 論
1) 窗體的繼承是個非常強(qiáng)大的面向?qū)ο蟪绦蛟O(shè)計方法?!?br>