Hallo ik heb het volgenden probleem, ik heb een class gemaakt die van een imagebestand (waar meerde afbeeldingen worden gesplit) een lijst maakt en daar dan een image met bijbehorende naam eruit haalt, maar hij geeft constant aan dat ie het bronbestand niet kan vinden terwijl hij toch echt in de resources staan.
dit is mij hoofdformulier
en dit is dan mijn imageclass
en dan heb ik nog een menumaker maar die doet het goed
Mijn hoofdformulier staat is mdicontainer op true en staat er al een menustrip genaamd m_mainMenu
Hopelijk kunnen jullie mij helpen
dit is mij hoofdformulier
Code:
Public Class Form1
Private m_menuItems As MenuItemManager
Public Sub New()
InitializeComponent()
m_menuItems = New MenuItemManager(Me)
m_menuItems.SetupStripPanels()
SetupToolbars()
End Sub
#Region "Setup menu en verwijzingen"
Private Sub SetupToolbars()
Dim mmitem As MenuItem = m_menuItems.GetItem("New")
mmitem.Text = "&New"
mmitem.Image = MenuImages16x16.Image(MenuImages16x16.eIndexes.NewDocument)
mmitem.ToolTipText = "New document"
Dim strip As ToolStrip = m_menuItems.GetStrip("file")
strip.Items.Add(m_menuItems.GetItem("New").CreateButton())
strip.Items.Add(m_menuItems.GetItem("Open").CreateButton())
strip.Items.Add(m_menuItems.GetItem("Save").CreateButton())
Dim menuitem As ToolStripMenuItem = m_menuItems.GetMenuStrip("file")
menuitem.Text = "&File"
menuitem.DropDownItems.Add(m_menuItems.GetItem("New").CreateMenuItem())
menuitem.DropDownItems.Add(m_menuItems.GetItem("Open").CreateMenuItem())
menuitem.DropDownItems.Add(m_menuItems.GetItem("Save").CreateMenuItem())
menuitem.DropDownItems.Add(m_menuItems.GetItem("SaveAs").CreateMenuItem())
menuitem.DropDownItems.Add(New ToolStripSeparator())
menuitem.DropDownItems.Add(m_menuItems.GetItem("Exit").CreateMenuItem())
m_mainMenu.Items.Insert(0, menuitem)
End Sub
#End Region
End Class
en dit is dan mijn imageclass
Code:
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Class ImagesUtil
Public Shared Function GetToolbarImageList(ByVal type As Type, ByVal resourceName As String, ByVal imageSize As Size, ByVal transparentColor As Color) As ImageList
Dim bit As New System.Drawing.Bitmap(type, resourceName)
Dim imageList As New ImageList()
imageList.ImageSize = imageSize
imageList.TransparentColor = transparentColor
imageList.Images.AddStrip(bit)
imageList.ColorDepth = ColorDepth.Depth24Bit
Return imageList
End Function
End Class
Public Class MenuImages16x16
Private Shared m_imageList As ImageList = Nothing
Public Enum eIndexes
Undo = 0
Redo
NewDocument
OpenDocument
SaveDocument
End Enum
Public Shared Function ImageList() As ImageList
Dim t As Type = GetType(MenuImages16x16)
If m_imageList Is Nothing Then
m_imageList = ImagesUtil.GetToolbarImageList(t, "Resources.menuimages.bmp", New Size(16, 16), Color.White)
End If
Return m_imageList
End Function
Public Shared Function Image(ByVal index As eIndexes) As Image
Return ImageList().Images(CInt(index))
End Function
End Class
en dan heb ik nog een menumaker maar die doet het goed
Code:
Imports System.Collections.Generic
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
'in deze class worden de toolstrips, panels en verwijzingen aangemaakt
Public Class MenuItem
Public Text As String = String.Empty
Public ToolTipText As String = String.Empty
Public ShortcutKeyDisplayString As String = String.Empty
Public ShortcutKeys As Shortcut = Shortcut.None
Public SingleKey As Keys = Keys.None
Public Image As Image
Public Click As System.EventHandler
Private m_enabled As Boolean = True
Public Property Enabled() As Boolean
Get
Return m_enabled
End Get
Set
For Each item As ToolStripItem In m_items
item.Enabled = value
Next
m_enabled = value
End Set
End Property
Public Tag As Object
Private m_items As New List(Of ToolStripItem)()
Public ReadOnly Property Items() As ToolStripItem()
Get
Return m_items.ToArray()
End Get
End Property
Private Function CreateItem(type As Type) As ToolStripItem
Dim item As ToolStripItem = TryCast(Activator.CreateInstance(type), ToolStripItem)
item.Text = Text
item.Image = Image
AddHandler item.Click, Click
item.Tag = Tag
item.ToolTipText = ToolTipText
item.Enabled = Enabled
m_items.Add(item)
Dim menuitem As ToolStripMenuItem = TryCast(item, ToolStripMenuItem)
If menuitem IsNot Nothing Then
If ShortcutKeyDisplayString.Length > 0 Then
menuitem.ShortcutKeyDisplayString = ShortcutKeyDisplayString
End If
If ShortcutKeys <> Shortcut.None Then
menuitem.ShortcutKeys = CType(ShortcutKeys, Keys)
End If
End If
Return item
End Function
Public Function CreateButton() As ToolStripButton
Dim b As ToolStripButton = TryCast(CreateItem(GetType(ToolStripButton)), ToolStripButton)
b.DisplayStyle = ToolStripItemDisplayStyle.Image
Return b
End Function
Public Function CreateMenuItem() As ToolStripMenuItem
Return TryCast(CreateItem(GetType(ToolStripMenuItem)), ToolStripMenuItem)
End Function
End Class
Public Class MenuItemManager
Private m_owner As Control
Private m_items As New Dictionary(Of Object, MenuItem)()
Private m_strips As New Dictionary(Of Object, ToolStrip)()
Private m_stripsItem As New Dictionary(Of Object, ToolStripItem)()
Public Sub New(owner As Control)
m_owner = owner
End Sub
Public Sub New()
End Sub
Public Function GetItem(key As Object) As MenuItem
If m_items.ContainsKey(key) = False Then
m_items(key) = New MenuItem()
End If
Return m_items(key)
End Function
Public Function GetStrip(key As Object) As ToolStrip
If m_strips.ContainsKey(key) = False Then
m_strips(key) = New ToolStrip()
End If
Return m_strips(key)
End Function
Public Function GetMenuStrip(key As Object) As ToolStripMenuItem
If m_stripsItem.ContainsKey(key) = False Then
m_stripsItem(key) = New ToolStripMenuItem()
End If
Return TryCast(m_stripsItem(key), ToolStripMenuItem)
End Function
Public Function GetStatusStrip(key As Object) As StatusStrip
If m_strips.ContainsKey(key) = False Then
m_strips(key) = New StatusStrip()
End If
Return TryCast(m_strips(key), StatusStrip)
End Function
Public Sub DisableAll()
For Each item As MenuItem In m_items.Values
item.Enabled = False
Next
End Sub
Public Function GetStripPanel(dockedLocation As DockStyle) As ToolStripPanel
If m_owner Is Nothing Then
Return Nothing
End If
For Each ctrl As Control In m_owner.Controls
If TypeOf ctrl Is ToolStripPanel AndAlso DirectCast(ctrl, ToolStripPanel).Dock = dockedLocation Then
Return TryCast(ctrl, ToolStripPanel)
End If
Next
Return Nothing
End Function
Private Sub CreateStripPanel(dockedLocation As DockStyle)
If m_owner IsNot Nothing AndAlso GetStripPanel(dockedLocation) Is Nothing Then
Dim panel As New ToolStripPanel()
panel.Dock = dockedLocation
m_owner.Controls.Add(panel)
End If
End Sub
Public Sub SetupStripPanels()
If m_owner Is Nothing Then
Return
End If
CreateStripPanel(DockStyle.Left)
CreateStripPanel(DockStyle.Right)
CreateStripPanel(DockStyle.Top)
CreateStripPanel(DockStyle.Bottom)
End Sub
Public Function FindFromSingleKey(key As Keys) As MenuItem
For Each item As MenuItem In m_items.Values
If item.SingleKey = key Then
Return item
End If
Next
Return Nothing
End Function
End Class
Mijn hoofdformulier staat is mdicontainer op true en staat er al een menustrip genaamd m_mainMenu
Hopelijk kunnen jullie mij helpen