程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> DELPHI的奇異菜單的編寫

DELPHI的奇異菜單的編寫

編輯:.NET實例教程

Custom Menus, Text, Lines / Delphi 4, 5
自定義菜單,文本,線/ Delphi 4, 5
Fancy Menus, etc.
奇異菜單,等等
Custom Menus, Rotated Text, and Special Lines
自定義菜單,旋轉文本,和特殊的線條

Before Delphi 4, it was difficult to customize a menu (add a bitmap, change a font, etc.), because owner drawing (i.e. custom drawing) - although implemented by Windows - was not exposed by the TMainMenu class. Since Delphi 4, however, this situation has been rectifIEd, and we can have our way with menus.
在Delphi 4之前,要想自定義一個菜單是困難的(例如加上一個BMP圖像,改變字體等),因為owner drawing事件(也就是custom drawing事件)-雖然是由Windows來執行,但是卻並不在TMainMenu class中出現.自從Delphi 4開始後,
這種情況有了改變,我們於是有了可以自定義菜單的功能了.

This article will highlight some techniques you can use to customize the appearance of menus in your Delphi applications. We''ll discuss text placement, menu sizing, font assignment, and using bitmaps and shapes to enhance a menu''s appearance. Just for fun, this article also features techniques for creating rotated text and custom lines. All of the techniques discussed in this article are demonstrated in projects available for download。
這篇文章將主要著重論述可以用來自定義你的Delphi應用程序中的菜單的外形的一些技術巧.我們將論述文本的放置,菜單的大小,字體的設置,以及用BMP文件和SHAPE控件來加強菜單的顯示效果。僅僅出於娛樂的目的,這篇文章也將對旋轉的文本和自定義線條的技巧進行特寫。這篇文章所論述到的所有技巧都已在工程文件中通過了調試並且可以到網上下載這些工程文件。
Custom Fonts and Sizes
設置字體和大小
To create a custom menu, set the OwnerDraw property of the menu component -TMainMenu or TPopupMenu - to True, and provide event handlers for its OnDrawItem and OnMeasureItem events. For example, an OnMeasureItem event handler is declared like this:
為了創建一個自定義的菜單,將TmainMenu或TpopupMenu組件的OwnerDraw屬性設為TRUE,並且創建它的OnDrawItem和OnMeasureItem的事件過程。例如,一個OnMeasureItem事件過程可以聲明如下:

procedure TForm1.Option1MeasureItem(Sender: TObject;
  ACanvas: TCanvas; var Width, Height: Integer);


Set the Width and Height variables to adjust the size of the menu item. The OnDrawItem event handler is where all the hard work is done; it''s where you draw your menu and make any special settings. To draw the menu option with Times New Roman font, for example, you should do something like this:
設置上面事件過程中的菜單項的Width 和Height變量到合適的大小.所有主要的事情都要由OnDrawItem事件來觸發;它是你要重畫菜單和作任何特殊設置的地方。舉例,為了用Times New Roman字體來重畫菜單項,你可以如下面這樣做:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved