Hello,
I'm developing a custom control that is to be used in a custom forms designer that I created. The control should have exactly two cells behaving like cells in a TableLayoutPanel, so I thought I'd build my control as an extension to TableLayoutPanel. Now I need to customize its designer, since I do not need all the design-time options that TableLayoutPanelDesigner offers.
Problem is: TableLayoutPanelDesigner is an internal class, and can therefore not be inherited!
Now I was wondering what my options are...
I was thinking about developing a custom designer from scratch (extending from ParentControlDesigner). How to achieve the concept of cells is a complete mystery to me though. There is quite some documentation out there about custom designers, but since the LayoutPanels are new in 2.0 nothing is written about how their designers may be implemented.
If only the framework was open source...
Any clues anyone? I'm stuck!
Thanks,
Tim |
| tawm Friday, February 10, 2006 12:36 AM |
A way to implement the concept of cells is to use Behaviors and Glyphs. Check out http://msdn2.microsoft.com/en-us/library/system.windows.forms.design.behavior.behavior.aspx.
You would basically have one glyph for each cell, meaning you would have to keep track of the boundaries of the cell, and use the behavior associated with your glyph to track things like enter, leave, drag-drop. You can also use the glyphs to draw cell borders. You could also override DrawBorder on the designer to draw the cell borders.
Martin |
| Martin Thorsen - MSFT Monday, February 13, 2006 10:12 PM |
Just looked at the code. We manually add the Select menu item, so you won't be able to remove or disable it.
Martin |
| Martin Thorsen - MSFT Tuesday, February 21, 2006 7:36 PM |
I'd like to know how to do this too. I've asked some similiar question before and no answer received so far...
Alan |
| LearnToRock Friday, February 10, 2006 3:44 AM |
Well, in a way, the framework is open source. Try usingReflector ( http://www.aisto.com/roeder/dotnet/) to take a look at the implementation of TableLayoutPanelDesigner; might give you some ideas. |
| CommonGenius.com Saturday, February 11, 2006 3:33 AM |
I walked through the designer chain in reflector. It's too heavy to re-implement all the classes (at least 6 internal .Net classes) for just a small change to the context menu. I hope there is a better way to handle this.
What I'm trying to achieve is to remove the menu item "View Code" (doesn't apply when using my custom designer), ""Delete TableLayoutPanel", which seems inherited from the underlying form. The rational for disbale "Delete <ControlType>"is not allowing user to delete the TableLayoutPanel from my custom designer. Will this at all possible?
Thank, Alan |
| LearnToRock Monday, February 13, 2006 9:32 PM |
Unfortunately there doesn't seem to be any way to do this on the TableLayoutPanelDesigner. The TableLayoutPanelDesigner overrides OnContextMenu and then uses some internal classes to build its own context menu.
If your designer has a View Code menucommand exposed via the MenuService, you can disabled this command, which would disable the entry on the context menu. Same for Delete.
Martin |
| Martin Thorsen - MSFT Monday, February 13, 2006 10:07 PM |
A way to implement the concept of cells is to use Behaviors and Glyphs. Check out http://msdn2.microsoft.com/en-us/library/system.windows.forms.design.behavior.behavior.aspx.
You would basically have one glyph for each cell, meaning you would have to keep track of the boundaries of the cell, and use the behavior associated with your glyph to track things like enter, leave, drag-drop. You can also use the glyphs to draw cell borders. You could also override DrawBorder on the designer to draw the cell borders.
Martin |
| Martin Thorsen - MSFT Monday, February 13, 2006 10:12 PM |
Martin,
I could disable the function of the menucommand, say 'view code' or 'delete <control name>', by following your suggestion. Where do these command originally come from? By adding a menucommandservice to designerhost, does the menucommandservice genrate all these command, or they come from somewhere else? It seems that the menuitem on the contextmenu never grayed out though being disabled. Any advice on how to fix it?
IServiceContainer sc = host as IServiceContainer; IMenuCommandService mcs = sc.GetService(typeof(IMenuCommandService)) as IMenuCommandService; if (mcs != null) { MenuCommand mc = mcs.FindCommand(StandardCommands.Delete); if (mc != null) { mc.Enabled = false; mc.Visible = false; mc.Supported = false;
mcs.RemoveCommand(mc); } }
Thank you a million! Alan
| Martin Thorsen - MSFT wrote: | |
Unfortunately there doesn't seem to be any way to do this on the TableLayoutPanelDesigner. The TableLayoutPanelDesigner overrides OnContextMenu and then uses some internal classes to build its own context menu.
If your designer has a View Code menucommand exposed via the MenuService, you can disabled this command, which would disable the entry on the context menu. Same for Delete.
Martin |
|
|
| LearnToRock Tuesday, February 14, 2006 3:52 AM |
Without a sample project it's hard for me to say how to fix it. Try not to remove the command, but just disable it. |
| Martin Thorsen - MSFT Tuesday, February 14, 2006 6:11 PM |
Martin, how can I send you a project? Seems that I cannot attach to the post in the forum. MayI send the project to your email?
Alan
| Martin Thorsen - MSFT wrote: | | Without a sample project it's hard for me to say how to fix it. Try not to remove the command, but just disable it. |
|
|
| LearnToRock Tuesday, February 14, 2006 7:05 PM |
Did you try not removing the command? Try that first. If that doesn't help, add your email to the post and I will contact you offline. |
| Martin Thorsen - MSFT Tuesday, February 14, 2006 8:52 PM |
Yep! I did it by just disabling the menucommand :) However, it always return null when trying to find the following commands:
//mcs is the IMenuCommandService mcs.FindCommand(StandardCommands.ViewCode) mcs.FindCommand(StandardCommands.DocumentOutline) mcs.FindCommand(StandardCommands.Properties)
I'd like to disable these three commands too... Another question is where is the best place to disable these commands? Right now I disabled them right after the creation of the designer (designerhost and services were instantiated). Is it the right place?
Thanks a bunch! Alan
| Martin Thorsen - MSFT wrote: | | Did you try not removing the command? Try that first. If that doesn't help, add your email to the post and I will contact you offline. |
|
|
| LearnToRock Wednesday, February 15, 2006 2:38 AM |
If the menu command doesn't exist, then the entry on the tablelayoutpaneldesigner context menu will be enabled.
As a workaround you can probably just add the commands and immediately disable them. You need to do so before any tablelayoutpanel is added to the form in the designer. The place you mention above should work. |
| Martin Thorsen - MSFT Wednesday, February 15, 2006 9:43 PM |
It works. But I still cannot get rid of the"Select" menucommand, whichis not defined in the standcommands. Is it possible to disable it too? I also noticed this small nuance after disabling a bunch of default commands: the separator lines are piled up at the top of context menu. Is there any way to get rid of them? It seems to me impossible because the tablelayoutpanel overrides the oncontextmenu and adds those separator lines. But I do hope there is some way to remove them.
You're great tutor, Martin.
Alan |
| LearnToRock Thursday, February 16, 2006 5:03 PM |
Thanks for the kind words. 
I am not sure why the separator lines are piling up at the top. If the commands are there, but disabled, they should still show up on the menu. I am not in the office today or tomorrow (office moves), so I can't take a look at the source to see what might be going on, or where Select is defined. I will take a look on Monday.
Martin |
| Martin Thorsen - MSFT Thursday, February 16, 2006 7:10 PM |
Thanks for your consistent contribution to this forum. One clarification is I not only disabled those menucommands but also set them invisible 'cause I don't want them to show up at all :) Naturally the separator lines are left in original place and piled up.
Could you also please kindly review the post about dynamically added rows by setting growable astyle to addrows? Seems to me it's not behaving as expected...
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=254438&SiteID=1
Alan |
| LearnToRock Thursday, February 16, 2006 9:14 PM |
Okay. Sounds like the issue regarding the separator lines is solved. I will check on the Select command on Monday. |
| Martin Thorsen - MSFT Thursday, February 16, 2006 10:28 PM |
Just looked at the code. We manually add the Select menu item, so you won't be able to remove or disable it.
Martin |
| Martin Thorsen - MSFT Tuesday, February 21, 2006 7:36 PM |
Thank you so much. if only MS could open the configurability to the downstream developers like me... I'm still released to know it's not my own problem :)
Alan
| Martin Thorsen - MSFT wrote: | |
Just looked at the code. We manually add the Select menu item, so you won't be able to remove or disable it.
Martin |
|
|
| LearnToRock Tuesday, February 21, 2006 7:55 PM |
Two years down the line, has anything been done to help in this area?
I also have a custom form designer, and a class that inherits from TableLayoutPanel. I don't want the user to use ANY of the items in the context menu. Ideally I would like to not show the context menu at all - is this possible?
If I must show the context menu then, following the advice above, I can disable or hide most of the StandardCommands. However, I can't find a way to disable or hide the commands specific to TableLayoutPanel, i.e. Row, Column, Edit Rows and Columns. Is there a way to do this?
Thanks. |
| Carol Dent Wednesday, April 08, 2009 1:44 PM |