Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: ActiveSheet en 22 Agosto 2007, 08:27 am



Título: {RUTINA} Arrastrar Controles VB 2008
Publicado por: ActiveSheet en 22 Agosto 2007, 08:27 am
Esta rutina es para arrastrar y redimenzionar contrles en tiempo de ejecucion
para el VB 2008

para redimenzionar con el boton derecho

Código
  1. Friend Class MoverControles
  2.    Inherits System.Windows.Forms.Form
  3.  
  4.    Private DX, DY As Integer
  5.    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
  6.    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
  7.    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, _
  8.    ByVal X As Integer, ByVal Y As Integer, ByVal cX As Integer, ByVal cY As Integer, ByVal wFlags As Integer) As Integer
  9.  
  10.    Const GWL_STYLE As Integer = (-16)
  11.    Const WS_THICKFRAME As Integer = &H40000
  12.    Const SWP_DRAWFRAME As Integer = &H20
  13.    Const SWP_NOMOVE As Integer = &H2
  14.    Const SWP_NOSIZE As Integer = &H1
  15.    Const SWP_NOZORDER As Integer = &H4
  16.    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
  17.        AsignarEventos(Me)
  18.  
  19.    End Sub
  20.    Private Sub Control_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  21.        DX = e.X
  22.        DY = e.Y
  23.        If e.Button = MouseButtons.Right Then
  24.            CambiarEstilo(CType(sender, Control))
  25.        Else
  26.            CType(sender, Control).BringToFront()
  27.        End If
  28.    End Sub
  29.    Private Sub Control_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  30.        If e.Button = MouseButtons.Left Then
  31.            CType(sender, Control).Left = e.X + CType(sender, Control).Left - DX
  32.            CType(sender, Control).Top = e.Y + CType(sender, Control).Top - DY
  33.        End If
  34.    End Sub
  35.    Private Sub AsignarEventos(ByVal elControl As Control)
  36.        Dim ctrl As Control
  37.        For Each ctrl In elControl.Controls
  38.            If ctrl.Name <> "cmdAlgo" And ctrl.Name <> "txtControl1" And ctrl.Name <> "txtControl1" Then ' aqui vaz agregando los controles que quieres estaticos y no redimensionables
  39.                AddHandler ctrl.MouseDown, AddressOf Me.Control_MouseDown
  40.                AddHandler ctrl.MouseMove, AddressOf Me.Control_MouseMove
  41.                AsignarEventos(ctrl)
  42.            End If
  43.        Next
  44.    End Sub
  45.    Private Sub CambiarEstilo(ByVal aControl As Control)
  46.        Dim Style As Integer
  47.        Try
  48.            Style = GetWindowLong(aControl.Handle.ToInt32, GWL_STYLE)
  49.            If (Style And WS_THICKFRAME) = WS_THICKFRAME Then
  50.                Style = Style Xor WS_THICKFRAME
  51.            Else
  52.                Style = Style Or WS_THICKFRAME
  53.            End If
  54.            SetWindowLong(aControl.Handle.ToInt32, GWL_STYLE, Style)
  55.            SetWindowPos(aControl.Handle.ToInt32, Me.Handle.ToInt32, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)
  56.        Catch
  57.        End Try
  58.    End Sub
  59. End Class


Título: Re: {RUTINA} Arrastrar Controles VB 2008
Publicado por: MANULOMM en 25 Agosto 2007, 06:20 am
esto va en .net... no en vb6.0.....  :-X :-X :-X

Atentamente,


Juan Manuel Lombana
Medellín - Colombia


Título: Re: {RUTINA} Arrastrar Controles VB 2008
Publicado por: ActiveSheet en 25 Agosto 2007, 06:38 am
y el foro de VB 2008?


Título: Re: {RUTINA} Arrastrar Controles VB 2008
Publicado por: rob1104 en 25 Agosto 2007, 09:12 am
Desde Visual Basic 7.0, 2003, 2005 y ahora el 2008 usan la tecnologia .NET...

http://es.wikipedia.org/wiki/Visual_Basic.NET   ;D

Saludos