marzo 2006 Blog Posts

Greetings from the windy city

Ciao, vi mando questa foto che ho scattato oggi come cartolina da Chicago......ovviamente non ci sono entrato!

posted @ martedì 14 marzo 2006 07:11 | Feedback (0)

Minimo comune multiplo in Visual Basic

Dovesse servirvi...Eccolo:  ''' ----------------------------------------------------------------------------- ''' <summary> ''' Calcola il minimo comune multiplo ''' </summary> ''' <param name="num">Interi tra cui calcolare il mcm</param> ''' <returns></returns> ''' <remarks> ''' </remarks> ''' <history> '''   [michele]       08/02/2006      Created ''' </history> ''' ----------------------------------------------------------------------------- Public Overloads Shared Function mcm(ByVal ParamArray num() As Int32) As Int32   If num.Length = 0 Then     Return 0   ElseIf num.Length = 1 Then     Return num(1)   End If   mcm = num(0)   For N As Int32 = 1 To num.GetUpperBound(0)     mcm = mcm(mcm, num(N))   Next N End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' Calcola il minimo comune multiplo ''' </summary> ''' <param name="a">Primo intero</param> ''' <param name="b">Secondo intero</param> ''' <returns></returns> ''' <remarks> ''' </remarks> ''' <history> '''   [michele]       08/02/2006      Created ''' </history> ''' ----------------------------------------------------------------------------- Public Overloads Shared Function mcm(ByVal a As Int32, ByVal b As Int32) As Int32   Dim c As Long = a * b   'Dim r As Long   Do     mcm = a Mod b     a = b     b = mcm   Loop While mcm <> 0   Return Convert.ToInt32(c \ a) End Function powered by IMHO 1.3

posted @ lunedì 6 marzo 2006 19:27 | Feedback (0)

Encoding delle Risorse

L'applicazione Windows Forms alla quale sto lavorando ha la possibilità di creare automaticamente un nuovo database sul quale lavorare. Per caricare valori nei dizionari ho messo nelle risorse dei file .sql che carico ed eseguo in un SQLCommand... E qui viene il bello: alcune insert into non funzionavano correttamente: non venivano inseriti i caratteri accentati... Dopo un paio di figuracce su usenet e sul forum di ugi mi sono accorto che leggevo le risorse con l'encoding di default anziché il corretto encoding: System.Text.Encoding.GetEncoding(1252) ...mannaggia a me!!! powered by IMHO 1.3

posted @ venerdì 3 marzo 2006 15:35 | Feedback (0)

Eventi di aggiunta/rimozione di Form MDIChild

Intercettare l'aggiunta/rimozione di form MDIChild ad una form MDIParent é un'operazione che ho scoperto essere piuttosto macchinosa. L'area contenitore di form MDIChild non é altro che un controllo nascosto di tipo System.Windows.Forms.MdiClient. Questo controllo espone come tutti i controls container gli eventi di ControlAdded e ControlRemoved che corrispondo all'aggiunta o alla rimozione di una form Child.Questo é il codice di una Form MDI base con gli eventi ChildFormAdded e Removed: Public Class MDIParentForm  Inherits System.Windows.Forms.Form  Protected WithEvents mdiClient As System.Windows.Forms.MdiClient#Region "Eventi"  Public Event ChildFormAdded As System.Windows.Forms.ControlEventHandler  Public Event ChildFormRemoved As System.Windows.Forms.ControlEventHandler  ''' -----------------------------------------------------------------------------  '''   ''' Solleva l'evento ChildFormAdded  '''   '''   '''   '''   '''   '''     [michele]    23/02/2005    Created  '''   ''' -----------------------------------------------------------------------------  Protected Overridable Overloads Sub OnChildFormAdded(ByVal e As System.Windows.Forms.ControlEventArgs)    RaiseEvent ChildFormAdded(Me, e)  End Sub  ''' -----------------------------------------------------------------------------  '''   ''' Solleva l'evento ChildFormRemoved  '''   '''   '''   '''   '''   '''     [michele]    23/02/2005    Created  '''   ''' -----------------------------------------------------------------------------  Protected Overridable Overloads Sub OnChildFormRemoved(ByVal e As System.Windows.Forms.ControlEventArgs)    RaiseEvent ChildFormRemoved(Me, e)  End Sub#End Region  ''' -----------------------------------------------------------------------------  '''   ''' Crea una form MDIParent  '''   '''   '''   '''   '''     [michele]    03/03/2006    Created  '''   ''' -----------------------------------------------------------------------------  Public Sub New()    Me.IsMdiContainer = True  End Sub  ''' -----------------------------------------------------------------------------  '''   ''' Ritorna il controllo MDIClient della form corrente  '''   '''   '''   '''   '''   '''     [michele]    03/03/2006    Created  '''   ''' -----------------------------------------------------------------------------  Protected Overridable Function GetMDIClientControl() As System.Windows.Forms.MdiClient    For Each ctl As System.Windows.Forms.Control In Me.Controls      If TypeOf ctl Is System.Windows.Forms.MdiClient Then        Return DirectCast(ctl, System.Windows.Forms.MdiClient)      End If    Next ctl  End Function  ''' -----------------------------------------------------------------------------  '''   ''' Recupera il controllo MDIClient dalla control's collection  '''   '''   '''   '''   '''   '''     [michele]    03/03/2006    Created  '''   ''' -----------------------------------------------------------------------------  Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)    Me.mdiClient = Me.GetMDIClientControl    MyBase.OnLoad(e)  End Sub#Region "Riflessione degli eventi di MDIClient"  Private Sub mdiClient_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles mdiClient.ControlAdded    Me.OnChildFormAdded(e)  End Sub  Private Sub mdiClient_ControlRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles mdiClient.ControlRemoved    Me.OnChildFormRemoved(e)  End Sub#End RegionEnd Class powered by IMHO 1.3

posted @ venerdì 3 marzo 2006 13:48 | Feedback (0)