Inherited ToolStripMenuItem/WinForms Form Designer problem

G

Guest

I have created a control by inheriting ToolStripMenuItem that has an image
property called LargeImage.

------

public class EventSubMenuItem : ToolStripMenuItem
{
private Image _largeImage = null;

[DefaultValue(null)]
[Localizable(true)]
public Image LargeImage
{
get { return _largeImage; }
set { _largeImage = value; }
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_largeImage != null)
{
_largeImage.Dispose();
}
}
base.Dispose(disposing);
}
}

------

The idea is that there is a collection of these controls as items in a
context menu that is dropped down from a parent ToolStripSplitButton. When
one of these menu items is selected, the parent displays a copy of the menu
item's text and the parent displays the menu item's LargeImage as its Image.

The control is in the same project and namespace as my form, part of a wider
solution.

This all lives in a Toolstrip in an MDI form.
The Image and LargeImage properties are set at design time from the project
resource file.
It all works fine at run time, and when I am in the first in the form
designer. But when I compile, despite getting 0 errors/build succeeded, the
designer blows up with an error message - the message is not consistent. Here
is an example:

One or more errors encountered while loading the designer. The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes.

Parameter is not valid.
Hide

--------

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object
component, Object value)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

Parameter is not valid.
Hide

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object
component, Object value)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)

Parameter is not valid.
Hide

at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.ToolStripItem.get_PreferredImageSize()
at System.Windows.Forms.ToolStripItemInternalLayout.get_PreferredImageSize()
at System.Windows.Forms.ToolStripItemInternalLayout.CommonLayoutOptions()
at System.Windows.Forms.ToolStripItemInternalLayout.GetLayoutData()
at System.Windows.Forms.ToolStripItemInternalLayout.PerformLayout()
at System.Windows.Forms.ToolStripItemInternalLayout.EnsureLayout()
at System.Windows.Forms.ToolStripItemInternalLayout.GetPreferredSize(Size
constrainingSize)
at System.Windows.Forms.ToolStripSplitButton.GetPreferredSize(Size
constrainingSize)
at
System.Windows.Forms.ToolStripSplitStackLayout.CalculatePlacementsVertical()
at System.Windows.Forms.ToolStripSplitStackLayout.LayoutVertical()
at
System.Windows.Forms.ToolStripSplitStackLayout.LayoutCore(IArrangedElement
container, LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container,
LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ToolStrip.OnLayout(LayoutEventArgs e)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.PerformLayout()

Parameter is not valid.
Hide

at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.ToolStripItem.get_PreferredImageSize()
at System.Windows.Forms.ToolStripItemInternalLayout.get_PreferredImageSize()
at System.Windows.Forms.ToolStripItemInternalLayout.CommonLayoutOptions()
at System.Windows.Forms.ToolStripItemInternalLayout.GetLayoutData()
at System.Windows.Forms.ToolStripItemInternalLayout.PerformLayout()
at System.Windows.Forms.ToolStripItemInternalLayout.EnsureLayout()
at System.Windows.Forms.ToolStripItemInternalLayout.GetPreferredSize(Size
constrainingSize)
at System.Windows.Forms.ToolStripSplitButton.GetPreferredSize(Size
constrainingSize)
at
System.Windows.Forms.ToolStripSplitStackLayout.CalculatePlacementsVertical()
at System.Windows.Forms.ToolStripSplitStackLayout.LayoutVertical()
at
System.Windows.Forms.ToolStripSplitStackLayout.LayoutCore(IArrangedElement
container, LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container,
LayoutEventArgs layoutEventArgs)
at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ScrollableControl.OnLayout(LayoutEventArgs levent)
at System.Windows.Forms.ToolStrip.OnLayout(LayoutEventArgs e)
at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
at System.Windows.Forms.Control.PerformLayout()
at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout)
at
System.Windows.Forms.Design.ControlCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, Object codeObject)
at
System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.DeserializeName(IDesignerSerializationManager
manager, String name, CodeStatementCollection statements)

------

I have traced this to the line of code shown below from Designer generated
code in InitializeComponent. I can't see what is wrong with it. Please help
Before I pull all my remaing hair out.

Thanks in advance :)



------
// viewResearchMeetingMenuItem
//
this.viewResearchMeetingMenuItem.Enabled = false;
this.viewResearchMeetingMenuItem.Image =
((System.Drawing.Image)(resources.GetObject("viewResearchMeetingMenuItem.Image")));
this.viewResearchMeetingMenuItem.ImageTransparentColor =
System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(150)))),
((int)(((byte)(255)))));

// THE NEXT LINE OF CODE MAKES THE DESIGNER BLOW UP AFTER COMPILATION
this.viewResearchMeetingMenuItem.LargeImage =
global::Lcp.InvestmentResearch.Properties.Resources.ResearchMeeting32;

this.viewResearchMeetingMenuItem.Name =
"viewResearchMeetingMenuItem";
this.viewResearchMeetingMenuItem.Size = new
System.Drawing.Size(205, 22);
this.viewResearchMeetingMenuItem.Text = "View &Research Meeting…";
this.viewResearchMeetingMenuItem.EnabledChanged += new
System.EventHandler(this.ViewMenu_EnabledChanged);
this.viewResearchMeetingMenuItem.Click += new
System.EventHandler(this.ViewDiaryEvent_Click);

------
 
G

Guest

After deleting and recreating the project resource file twice and playing
around with the code a lot, I finally have a workaround that works but is not
very satisfactory. I import the graphics (png files) to the form's resource
file.

I am wondering if part of the problem is that some of the graphics are used
in more than one place on the form?

Any help - even if it is pointing out stupidity in my code - will be
gratefully received. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top