ToolStripControlHost visual basic 2010

sabato 17 novembre 2012 - 07.57
Tag Elenco Tags  VB.NET  |  .NET 4.0  |  Windows XP  |  Visual Studio 2010  |  Access (.mdb)  |  Office 2007  |  Firefox

reitano Profilo | Newbie

Salve.
uso vs 2010 per hobby e chiedo aiuto per il ToolStripControlHost generato da:
Public Sub SelCol_Menu(ByRef Menu As ToolStripMenuItem, ByVal onClick As EventHandler, ByVal NomeTabella As String)
Dim dtw As DataView = SelCol_NewDataView(NomeTabella)
Dim DataRow As DataRow = Nothing
Dim TSMI As ToolStripMenuItem
Dim Text As String = String.Empty
Dim Image As Image = Nothing
Dim Name As String = String.Empty
Dim tsmi1 As ToolStripMenuItem
Menu.DropDownItems.Clear()
For Each Riga As DataRowView In dtw
Try
DataRow = Riga.Row
Text = Tabella_SelCol.GetCampo(Tabella_SelCol._Campi.SC_Nome, DataRow).ToString
Image = CType(Tabella_SelCol.GetCampo(Tabella_SelCol._Campi.SC_Icona, DataRow), Icon).ToBitmap
Name = Text
TSMI = New ToolStripMenuItem(Text, Image, onClick, Name)
TSMI.Tag = NomeTabella
Menu.DropDownItems.Add(TSMI)
Dim GListBox As GListBox = SelCol_ListBoxSelezionati(Name, NomeTabella)
Dim Tsph As ToolStripControlHost = CType(New ToolStripControlHost(GListBox), ToolStripItem)
TSMI.DropDownItems.Add(Tsph) 'New ToolStripControlHost(LstCampi))
GListBox.Width = Tsph.Width
Tsph.Padding = Padding.Empty
tsmi1 = New ToolStripMenuItem("Modifica", My.Resources.ResDataBase.SelColModifica.ToBitmap, onClick, "Modifica")
TSMI.DropDownItems.Add(tsmi1)
tsmi1 = New ToolStripMenuItem("Elimina", My.Resources.ResDataBase.SelColDelete.ToBitmap, onClick, "Elimina")
TSMI.DropDownItems.Add(tsmi1)
Catch oE As System.Exception
' Handle exception here
MsgBox(oE.ToString & vbCrLf & "Procedura: SelCol_FillMenu" & vbCrLf & "Modulo: clsBrumaDb")
End Try
Next
Menu.DropDownItems.Add(New ToolStripSeparator)
Text = "Nuova Selezione"
Image = My.Resources.ResDataBase.SelColNew.ToBitmap
Name = Text
TSMI = New ToolStripMenuItem(Text, Image, onClick, Name)
Menu.DropDownItems.Add(TSMI)
Text = "Reset"
Image = My.Resources.ResDataBase.SelCol.ToBitmap
Name = Text
TSMI = New ToolStripMenuItem(Text, Image, onClick, Name)
Menu.DropDownItems.Add(TSMI)
End Sub
Option Explicit On
Option Strict On
Public Class GListBoxItem
Private _myText As String
Private _myImageIndex As Integer
' properties
Public Property Text() As String
Get
Return _myText
End Get
Set(ByVal value As String)
_myText = value
End Set
End Property
Public Property ImageIndex() As Integer
Get
Return _myImageIndex
End Get
Set(ByVal value As Integer)
_myImageIndex = value
End Set
End Property
'constructor
Public Sub New(ByVal text As String, ByVal index As Integer)
_myText = text
_myImageIndex = index
End Sub
Public Sub New(ByVal text As String)
Me.New(text, -1)
End Sub
Public Sub New()
Me.New("")
End Sub
Public Overrides Function ToString() As String
Return _myText
End Function
End Class
'End of GListBoxItem class
' GListBox class
Public Class GListBox
Inherits ListBox
Private _myImageList As ImageList
Public Property ImageList() As ImageList
Get
Return _myImageList
End Get
Set(ByVal value As ImageList)
_myImageList = value
End Set
End Property
Public Sub New()
' Set owner draw mode
Me.DrawMode = DrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
If e.Index < 0 Or IsNothing(_myImageList) Then Return
e.DrawBackground()
e.DrawFocusRectangle()
Dim item As GListBoxItem
Dim bounds As Rectangle = e.Bounds
Dim imageSize As Size = _myImageList.ImageSize
Try
item = CType(Items(e.Index), GListBoxItem)
If item.ImageIndex <> -1 Then
ImageList.Draw(e.Graphics, bounds.Left, bounds.Top, item.ImageIndex)
e.Graphics.DrawString(item.Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left + imageSize.Width, bounds.Top)
Else
e.Graphics.DrawString(item.Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
End If
Catch
If e.Index <> -1 Then
e.Graphics.DrawString(Items(e.Index).ToString(), e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
Else
e.Graphics.DrawString(Text, e.Font, New SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
End If
End Try
'MyBase.OnDrawItem(e)
End Sub
End Class
il tutto produce l'immagine allegata.

583x568 53Kb

qualche aiuto?

583x568 53Kb
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5