473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Inherited Controls and Context Menus

What's the "proper" way of handling this?

I have a base Control that offers a small set of options via its
ContextMenu.

I've now inherited from this and would like to add additional items to
this Context Menu structure but how best to do so?

Do I override the ContextMenu property in the sub-class, grab the value
of MyBase.ContextMenu and append to it?
Should use a separate function to do this "construction" and assign the
result to the ContextMenu property from Sub New?
(other options, please)

And then ...

What if I need to modify the existing items (defined in the base
Control)? Is there a "clean" way to support this, or do I just have to
search the whole menu structure to find a given item by name?

(Of course, by "MenuItem" I mean "ToolStripMenuItem"...)

TIA,
Phill W.
Oct 9 '08 #1
1 1673
On Thu, 09 Oct 2008 12:55:08 +0100, "Phill W."
<p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote:
>What's the "proper" way of handling this?

I have a base Control that offers a small set of options via its
ContextMenu.

I've now inherited from this and would like to add additional items to
this Context Menu structure but how best to do so?

Do I override the ContextMenu property in the sub-class, grab the value
of MyBase.ContextMenu and append to it?
Should use a separate function to do this "construction" and assign the
result to the ContextMenu property from Sub New?
(other options, please)

And then ...

What if I need to modify the existing items (defined in the base
Control)? Is there a "clean" way to support this, or do I just have to
search the whole menu structure to find a given item by name?

(Of course, by "MenuItem" I mean "ToolStripMenuItem"...)

TIA,
Phill W.
There are various ways to do this. What I might do is to create an
Overridable function in the base class called AddContextMenuItem. It
would have one parameter, an Enum with a value for each of the items
the base class adds, and it returns the appropriate ToolStripMenuItem.
In the base class call this method for each item you want to add. If
it doesn't return Nothing, add the return value to the context menu.

In the derived class override this method. If you want to suppress an
item, return Nothing without calling the base class implementation. If
you want to modify an item, call the base class implementation and
then modify the returned ToolStripMenuItem.

You might also want to have an overridable sub in the base class that
is just an empty method with two parameters, the context menu and a
flag, and call it in the base class before adding any items and again
after all items are added. The derived class could override this to
get control both before any items are added and again after.
Oct 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
8
by: Spam Trap | last post by:
I am getting strange resizing problems when using an inherited form. Controls are moving themselves seemingly randomly, but reproducibly. "frmBase" is my base class (a windows form), and...
4
by: Nikolay Petrov | last post by:
Hi everyone! I am developing app, which should be used by users, which are members of different groups. These users and groups are stored in my SQL database and are custom for my application,...
0
by: dmac | last post by:
I created a contextmenu class, inherited from contextmenu, because i have an app which has lots of similar context menus so i did not want to have to make one up each time. However, I cannot get...
0
by: porter_wss | last post by:
I am a bit confused on serializing objects and inherited objects. What I am trying to accomplish is creating a base object and an inherited object with additional properties. The sender of these...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.