none
Redimencionar objetos em runtime RRS feed

  • Pergunta

  • Como eu posso fazer para poder redimencionar por exemplo uma Label em runtime em um windows form.

    Eu quero clicar nela e tipo como o corel faz, fica aqueles quadradrinhos nos canto e um no meio que permite que com o mouse eu aumente a suas proporcoes. - igual ao que fazemos quando estamos em modo de layout no visual stuido.

    Em VB6 eu consigo fazer isso mas em .net usando a linguagem VB nao consegui ainda.
    Alguem tem algum exemplo ou alguma ideia???

    Valeu
    terça-feira, 11 de setembro de 2007 13:06

Todas as Respostas

  • Ola rodrigo,

     

    achei este codigo na internet, e não o testei ainda, porem o autor do codigo fala que ele faz algo parecido com o que vc pediu.

     

    Code Snippet
    Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
    MyBase.New()
    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub
    Private components As System.ComponentModel.IContainer
    Private WithEvents Label1 As New System.Windows.Forms.Label
    Private WithEvents Label2 As New System.Windows.Forms.Label
    Private mouseX, mouseY As Integer
    Private arLabels() As Label
    Dim myMousedown As String
    Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    Me.ClientSize = New System.Drawing.Size(400, 400)
    Label1.Name = "Label1"
    Label2.Name = "Label2"
    arLabels = New Label() {Label1, Label2}
    Dim lblY As Integer = 100
    For Each Lbl As Label In arLabels
    Lbl.Location = New System.Drawing.Point(100, lblY)
    Lbl.ForeColor = Color.Red
    Lbl.BackColor = Color.Transparent
    Lbl.TextAlign = ContentAlignment.MiddleCenter
    Lbl.Text = Lbl.Location.X.ToString & "." &
    Lbl.Location.Y.ToString
    AddHandler Lbl.MouseDown, AddressOf Label_MouseDown
    AddHandler Lbl.MouseUp, AddressOf Label_MouseUp
    AddHandler Lbl.MouseMove, AddressOf Label_MouseMove
    lblY += 30
    Me.Controls.Add(Lbl)
    Next
    End Sub
    Private Sub Label_MouseDown(ByVal sender As Object, ByVal _
    e As System.Windows.Forms.MouseEventArgs)
    Dim lbl As Label = DirectCast(sender, Label)
    myMousedown = lbl.Name
    lbl.BringToFront()
    mouseX = Cursor.Position.X - lbl.Location.X
    mouseY = Cursor.Position.Y - lbl.Location.Y
    lbl.Cursor = Cursors.Hand
    End Sub
    Private Sub Label_MouseUp(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.MouseEventArgs)
    Dim lbl As Label = DirectCast(sender, Label)
    myMousedown = ""
    lbl.Cursor = Cursors.Default
    End Sub
    Private Sub Label_MouseMove(ByVal sender As Object, ByVal e _
    As System.Windows.Forms.MouseEventArgs)
    Dim lbl As Label = DirectCast(sender, Label)
    Static LastCursor As Point
    Dim NowCursor As Point = New Point(Cursor.Position.X,
    Cursor.Position.Y)
    If Point.op_Inequality(NowCursor, LastCursor) Then
    If myMousedown = lbl.Name Then
    lbl.Location = New System.Drawing.Point(Cursor.Position.X _
    - mouseX, Cursor.Position.Y - mouseY)
    End If
    LastCursor = Cursor.Position
    lbl.Text = lbl.Location.X.ToString & "." &
    lbl.Location.Y.ToString
    End If
    End Sub
    End Class

     

     

    Espero ter ajudado.

    terça-feira, 11 de setembro de 2007 23:39