Alex's Weblog

Weblog di Ermanno Goletto (Codename Alex - A Learning EXperience)
posts - 438, comments - 4214, trackbacks - 294

My Links

News

Il blog è stato
trasferito al
 seguente link:


DevAdmin Blog

Add my blog to Live

Foto

Curriculum Vitae


Il contenuto di questo blog e di ciascun post viene fornito “così come é”, senza garanzie, e non conferisce alcun diritto. Questo blog riporta il mio personale pensiero che non riflette necessariamente il pensiero del mio datore di lavoro.

Logo Creative Commons Deed


Logo MCTS

Logo MCSA

Logo MCP

Logo Microsoft Certified Business Management Solutions Professional

Microsoft Certified Business Management Solutions Specialist


Logo UGIdotNET UGIdotNET Contributor


Logo UGISS UGISS Contributor


Logo SysAdmin.it SysAdmin.it Staff


Article Categories

Archives

Post Categories

Blogs

Database

Development

Friends

IT

Knowledge Base

Links

MBS

MCP

MVP Sites

User Groups

Virtualization

Tutto quello che avreste voluto sapere sull'Owner-Drawing

http://msdn.microsoft.com/msdnmag/issues/04/02/CuttingEdge/default.aspx

In questo articolo Dino Esposito tratta in maniera approfondita i seguenti argomenti:
- Customizing Menu Rendering
- Overriding the Menu of a Form
- The MeasureItem Event
- The DrawItem Event
- Painting the Menu Item
- Context Menu and TextBoxes
- Using Graphical Menus Seamlessly

e risponde implicitamente ad un mio dubbio circa la possibilità di personalizzare il context menu di default del TextBox:

The Textbox is the only control in Windows Forms that has a built-in context menu. The control exposes a ContextMenu property, but it doesn't return an instance of the context menu that appears when you right-click. Why? The code for the textbox's context menu is hardcoded in the Win32 API. In particular, the context menu is generated on the fly each time the user right-clicks. The menu is then released and destroyed once the selection is made. You can replace this menu with your own by setting the ContextMenu property, but there's no chance to manipulate the original menu. Since the menu has a very short (and unmanaged) life, how can you easily subclass it and mark it as owner-draw?
  The simplest trick that I've found is the following: create a TextboxContextMenu class that represents a custom context menu with all of the items of a standard textbox context menu (Undo, Cut, Copy, and the like). Implementing these methods is relatively simple and samples can be found in the MSDN documentation. Once you hold an instance of a managed class that works like the typical context menu of a TextBox, you first make it owner-draw and then you bind it to any TextBox you want:

Dim txtMenu As New TextBoxContextMenu 
gMenu.AddIcon(txtMenu.MenuItemCut, "..\images\cut.bmp")
gMenu.AddIcon(txtMenu.MenuItemCopy, "..\images\copy.bmp")
gMenu.AddIcon(txtMenu.MenuItemPaste, "..\images\paste.bmp")
gMenu.AddIcon(txtMenu.MenuItemDelete, "..\images\delete.bmp")
TextBox1.ContextMenu = txtMenu
gMenu.Init(TextBox1.ContextMenu)

The TextBoxContextMenu class lives in the same assembly that contains the GraphicMenu class. You should be aware that owner-drawn menus don't work correctly when attached to a NotifyIcon component. For more information on this problem see Knowledge Base article 827043.

Print | posted on venerdì 23 gennaio 2004 20:06 | Filed Under [ Links .NET Framework ]

Feedback

Gravatar

# re: Tutto quello che avreste voluto sapere sull'Owner-Drawing

The number of locations the restaurant located is about 3,557 out of them 345 restaurants are owned by the company and the rest 3,212 companies are franchised.
23/04/2018 17:05 | www.talktosonic.com
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET