Help with Magic Library 1.7.3

gearbolt

Member
Joined
Mar 16, 2003
Messages
14
I am trying to add the icons to the menus but whenever the program tries to load the image I get the following exception.

An unhandled exception of type System.ArgumentException occurred in system.drawing.dll

Additional information: null is not a valid value for stream.

Here is the code I have so far. You can download the Magic Dll at
http://www.crownwood.net/index.html

The line in question has been highlighted in red. I also have included the VB file and the image. This is driving me crazy and I know its something simple.

Thanks for the help

Code:
Imports Crownwood.Magic.Menus 
Imports Crownwood.Magic.Common 
Imports Crownwood.Magic.Controls 

Public Class MDIContainer 
Inherits System.Windows.Forms.Form 

Private _count As Integer = 1 
Private _images As ImageList = Nothing 
Private _status As StatusBar = Nothing 
Private _statusBarPanel As StatusBarPanel = Nothing 
Private _topMenu As Crownwood.Magic.Menus.MenuControl = Nothing 


#Region " Windows Form Designer generated code " 

Public Sub New() 
MyBase.New() 

LoadResources() 
This call is required by the Windows Form Designer. 
InitializeComponent() 

Add any initialization after the InitializeComponent() call 
SetupMenus() 
SetupStatusBar() 
End Sub 

Form overrides dispose to clean up the component list. 
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 
If disposing Then 
If Not (components Is Nothing) Then 
components.Dispose() 
End If 
End If 
MyBase.Dispose(disposing) 
End Sub 

Required by the Windows Form Designer 
Private components As System.ComponentModel.IContainer 

NOTE: The following procedure is required by the Windows Form Designer 
It can be modified using the Windows Form Designer. 
Do not modify it using the code editor. 
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() 
 
MDIContainer 
 
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) 
Me.ClientSize = New System.Drawing.Size(292, 266) 
Me.IsMdiContainer = True 
Me.Name = "MDIContainer" 
Me.Text = "Test Menu" 

End Sub 

#End Region 

Shared Sub Main() 


Application.Run(New MDIContainer()) 

End Sub 

Protected Sub LoadResources() 

 Create a strip of images by loading an embedded bitmap resource 

[COLOR=red]
_images = ResourceHelper.LoadBitmapStrip(Me.GetType(), _ 
"MenuImages.bmp", _ 
New Size(16, 16), _ 
New Point(0, 0)) 
[/COLOR] 

End Sub 



Protected Sub SetupMenus() 
 Create the MenuControl 
_topMenu = New Crownwood.Magic.Menus.MenuControl() 

 We want the control to handle the MDI pendant 
_topMenu.MdiContainer = Me 


 Create the top level Menus 
Dim MenuFile1 As MenuCommand = New MenuCommand("&File") 
Dim MenuFile2 As MenuCommand = New MenuCommand("&Exit") 
Dim Menufile3 As MenuCommand = New MenuCommand("&Windows") 
Dim Menufile4 As MenuCommand = New MenuCommand("&Help") 
Dim Menufile8 As MenuCommand = New MenuCommand("&Wow") 

_topMenu.MenuCommands.AddRange(New MenuCommand() {MenuFile1, MenuFile2, Menufile3, Menufile4, Menufile8}) 


 Create the submenus 
CreateAppearanceMenu(MenuFile1) 
CreateWindowsMenu(MenuFile2) 
CreateAnimationMenu(Menufile3) 
CreateCityMenus(Menufile4, Menufile8) 

 Add to the display 
_topMenu.Dock = DockStyle.Top 


Controls.Add(_topMenu) 
 Create an initial MDI child window 
OnNewWindowSelected(Nothing, EventArgs.Empty) 
End Sub 


Protected Sub CreateCityMenus(ByVal mc1 As MenuCommand, ByVal mc2 As MenuCommand) 

Define the hierarchy of the submenus 
Dim s0 As MenuCommand = New MenuCommand("&New York") 
Dim s1 As MenuCommand = New MenuCommand("N&ew Jersy") 
Dim s2 As MenuCommand = New MenuCommand("Ne&w Knicks") 
Dim s3 As MenuCommand = New MenuCommand("New &Mets") 


 Setup the left column font details 

Dim fs As FontStyle = FontStyle.Bold 

mc1.MenuCommands.ExtraText = "Teams" 
mc1.MenuCommands.ExtraTextColor = Color.White 
mc1.MenuCommands.ExtraBackColor = Color.DarkBlue 
mc1.MenuCommands.ExtraFont = New Font("Times New Roman", 12.0F, fs) 

Draws the submenus on the screen for this function 
mc1.MenuCommands.AddRange(New MenuCommand() {s0, s1, s2, s3}) 
End Sub 


Protected Sub CreateAppearanceMenu(ByVal mc As MenuCommand) 

Dim style1 As MenuCommand = New MenuCommand("&IDE") 



Draws the submenu on the screen 
mc.MenuCommands.AddRange(New MenuCommand() {style1}) 
End Sub 

Protected Sub CreateWindowsMenu(ByVal mc As MenuCommand) 

End Sub 

Protected Sub CreateAnimationMenu(ByVal mc As MenuCommand) 

End Sub 


Protected Sub SetupStatusBar() 
 Create and setup the StatusBar object 
_status = New StatusBar() 
_status.Dock = DockStyle.Bottom 
_status.ShowPanels = True 

 Create and setup a single panel for the StatusBar 
_statusBarPanel = New StatusBarPanel() 
_statusBarPanel.AutoSize = StatusBarPanelAutoSize.Spring 
_status.Panels.Add(_statusBarPanel) 

Controls.Add(_status) 
End Sub 

Public Sub SetStatusBarText(ByVal text As String) 
_statusBarPanel.Text = text 
End Sub 

Protected Sub OnNewWindowSelected(ByVal sender As Object, ByVal e As EventArgs) 
Dim child As MDIChild = New MDIChild(Me) 

child.MdiParent = Me 
child.Size = New Size(130, 130) 
child.Text = "Child" & _count 
child.Show() 

_count += 1 

OnMenuItemSelected("NewWindow") 
End Sub 

Protected Sub OnMenuItemSelected(ByVal name As String) 
Dim child As MDIChild = Me.ActiveMdiChild 

If Not (child Is Nothing) Then 
child.AppendText(name) 
End If 
End Sub 




End Class 
Public Class MDIChild 
Inherits Form 

Protected _mdiContainer As MDIContainer 
Protected _box As RichTextBox 

Sub New(ByVal mdiContainer As MDIContainer) 
 Remember parent Form 
_mdiContainer = mdiContainer 

 Create a RichTextBox to fill entire client area 
_box = New RichTextBox() 
_box.Text = "Right click inside this window to show a Popup menu." 
_box.Dock = DockStyle.Fill 
_box.BorderStyle = BorderStyle.None 
AddHandler _box.MouseUp, AddressOf OnRichTextMouseUp 
Controls.Add(_box) 
End Sub 

Public Sub AppendText(ByVal text As String) 
_box.Text = _box.Text & vbCrLf & text 
End Sub 

Protected Sub OnRichTextMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) 
If e.Button = MouseButtons.Right Then 
 Dim box As RichTextBox = sender 


End Sub 

Protected Sub OnSelected(ByVal mc As MenuCommand) 
_mdiContainer.SetStatusBarText("Selection over " & mc.Description) 
End Sub 

Protected Sub OnDeselected(ByVal mc As MenuCommand) 
_mdiContainer.SetStatusBarText("") 
End Sub 
End class
 
Last edited by a moderator:
Hello,

I had the same problem loading the images. You have to:

1. Import the image file into your project;
2. In the image file propertys change the item BuildAction from "Content" to "Embedded Resource";
3. In your code when you call the LoadImages Routine you must use "YourSolutionName.YourImageName.bmp"

It works for me.
 
Back
Top