mario.deghetto

Visual Basic & .NET
posts - 319, comments - 204, trackbacks - 0

#46: VB.NET – impedire lo spostamento di un form

Prendo l’occasione di una discussione avuta un po’ di tempo fa, tra me e Riccardo Girardi, il quale aveva la necessità di trovare il modo per bloccare la posizione di un form. La gestione dell’evento di spostamento del form stesso non andava bene, perché causava un brutto sfarfallìo (flickering).

Ho trovato nel blog di Luciano Bastianello il codice in C# con cui viene realizzata questa funzionalità e l’ho convertito in VB.NET, con una correzione da parte di Riccardo Girardi:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
   Const WM_NCLBUTTONDOWN As Integer = 161
   Const WM_SYSCOMMAND As Integer = 274
   Const HTCAPTION As Integer = 2
   Const SC_MOVE As Integer = 61456
   If (m.Msg = WM_SYSCOMMAND) AndAlso _
         (m.WParam.ToInt32() = SC_MOVE) Then
      Return
   End If
   If (m.Msg = WM_NCLBUTTONDOWN) AndAlso _
         (m.WParam.ToInt32() = HTCAPTION) Then
      Return
   End If
   MyBase.WndProc(m)
End Sub

E’ sufficiente inserire questo codice all’interno del codice del form da bloccare e il gioco è fatto.

Print | posted on martedì 26 gennaio 2010 5.03 |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 4 and 7 and type the answer here:

Powered by: