Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Zeroql en 24 Agosto 2010, 04:37 am



Título: Problemas con redibujado de lineas en el form
Publicado por: Zeroql en 24 Agosto 2010, 04:37 am
Buenas bueno resulta que tengo un form que al iniciarse se dibujan unas lineas. normal uso el siguiente metodo:

Código
  1. Private Sub frmAddItem_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
  2.        Dim oPen As New Pen(Color.DimGray, 1)
  3.        Dim oGraphics As Graphics = Me.CreateGraphics
  4.        oGraphics.DrawLine(oPen, 0, 0, 0, Me.Height)
  5.        oGraphics.DrawLine(oPen, Me.Width - 1, 0, Me.Width - 1, Me.Height)
  6.        oGraphics.DrawLine(oPen, 0, Me.Height - 1, Me.Width, Me.Height - 1)
  7.        oPen = New Pen(Color.DarkGray, 1)
  8.        oGraphics.DrawLine(oPen, 1, 0, 1, Me.Height)
  9.        oGraphics.DrawLine(oPen, Me.Width - 2, 0, Me.Width - 2, Me.Height)
  10.        oGraphics.DrawLine(oPen, 0, Me.Height - 2, Me.Width, Me.Height - 2)
  11.        oPen.Dispose()
  12.        oGraphics.Dispose()
  13.    End Sub

ahi no tengo problema. pero resulta que deseo hacer el form redimencionable y borrar estas lineas y crear otras nuevas con el nuevo tamaño del form.
¿Como hago para borrar las antiguas lineas?


De ante mano les agradezco la ayuda


Título: Re: Problemas con redibujado de lineas en el form
Publicado por: [D4N93R] en 24 Agosto 2010, 04:47 am
Cada vez que el formulario necesita dibujarse, se llama a ese método que tu tienes, por lo tanto solo tienes que redimensionar el formulario y en ese evento Obligas al form a dibujarse de nuevo, esto lo haces llamando al método Invalidate del Form. Saludos!


Título: Re: Problemas con redibujado de lineas en el form
Publicado por: Zeroql en 24 Agosto 2010, 04:49 am
Heee ya lo intente y no me da!!!


Título: Re: Problemas con redibujado de lineas en el form
Publicado por: [D4N93R] en 24 Agosto 2010, 04:54 am
Postea tu código, si es muy largo puedes ponerlo en pastebin.com


Título: Re: Problemas con redibujado de lineas en el form
Publicado por: Zeroql en 24 Agosto 2010, 05:00 am
Posteo el que tengo actualmente.


Contiene, un Label=lblTitle, un panel=pnTitle,2 imagenes= picExit; picMaxMin, y algunas funciones de manejo de ventanas.
Código
  1. Public Class frmAddItem
  2.  
  3.    Private maximized As Boolean                        'Indica si el formulario esta maximizado o normal
  4.  
  5.    Private Sub frmAddItem_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  6.        CloseForm(Me.Name)
  7.    End Sub
  8.  
  9.    Private Sub frmAddItem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  10.        Me.MdiParent = mdiMain
  11.        loadImgsTitle(Me)
  12.        loadForm(Me.Name, Me.Text)
  13.    End Sub
  14.  
  15.    Private Sub frmAddItem_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
  16.        Dim oPen As New Pen(Color.DimGray, 1)
  17.        Dim oGraphics As Graphics = Me.CreateGraphics
  18.        oGraphics.DrawLine(oPen, 0, 0, 0, Me.Height)
  19.        oGraphics.DrawLine(oPen, Me.Width - 1, 0, Me.Width - 1, Me.Height)
  20.        oGraphics.DrawLine(oPen, 0, Me.Height - 1, Me.Width, Me.Height - 1)
  21.        oPen = New Pen(Color.DarkGray, 1)
  22.        oGraphics.DrawLine(oPen, 1, 0, 1, Me.Height)
  23.        oGraphics.DrawLine(oPen, Me.Width - 2, 0, Me.Width - 2, Me.Height)
  24.        oGraphics.DrawLine(oPen, 0, Me.Height - 2, Me.Width, Me.Height - 2)
  25.        oPen.Dispose()
  26.        oGraphics.Dispose()
  27.    End Sub
  28.  
  29.    Private Sub frmAddItem_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
  30.        If maximized = True Then
  31.            Me.Width = mdiMain.ClientRectangle.Width - frmMenu.Width - 5
  32.            Me.Height = mdiMain.ClientRectangle.Height - frmTaskBar.Height - 5
  33.            If mdiMain.mnuMain.Visible = True Then
  34.                Me.Top = mdiMain.mnuMain.Height + 2
  35.            Else
  36.                Me.Top = 0
  37.            End If
  38.        Else
  39.            Me.Width = 687
  40.            Me.Height = 560
  41.            Me.Left = (mdiMain.ClientRectangle.Width - Me.Width) / 2
  42.            Me.Top = (mdiMain.ClientRectangle.Height - Me.Height) / 2
  43.        End If
  44.        pnTitle.Width = Me.Width
  45.        picExit.Left = pnTitle.Width - picExit.Width - 3
  46.        picMaxMin.Left = picExit.Left - picMaxMin.Width - 3
  47.        Me.Left = frmMenu.Width
  48.    End Sub
  49.  
  50.    Private Sub picExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picExit.Click
  51.        Me.Close()
  52.    End Sub
  53.  
  54.    Private Sub picExit_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picExit.MouseMove
  55.        Dim shellR = New shellresx.clsRes
  56.        picExit.Image = shellR.useImage("btExitS")
  57.    End Sub
  58.  
  59.    Private Sub picMaxMin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picMaxMin.Click
  60.        maximized = Not maximized
  61.        frmAddItem_Resize(Nothing, Nothing)
  62.        me.refresh
  63.        frmAddItem_Paint(Nothing, Nothing)
  64.    End Sub
  65.  
  66.    Private Sub picMaxMin_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picMaxMin.MouseMove
  67.        Dim shellR = New shellresx.clsRes
  68.        picMaxMin.Image = shellR.useImage("btMaxS")
  69.    End Sub
  70.  
  71.    Private Sub pnTitle_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnTitle.MouseDown
  72.        MoveForm(Me)
  73.    End Sub
  74.  
  75.    Private Sub pnTitle_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnTitle.MouseMove
  76.        Dim shellR = New shellresx.clsRes
  77.        picExit.Image = shellR.useImage("btExitN")
  78.        picMaxMin.Image = shellR.useImage("btMaxN")
  79.    End Sub
  80. End Class




Título: Re: Problemas con redibujado de lineas en el form
Publicado por: [D4N93R] en 24 Agosto 2010, 05:23 am
En el método que controla el Resize, frmAddItem_Resize, tienes que llamar a Invalidate. Pruébalo a ver.

Me voy a dormir, xD sigo mañana!


Título: Re: Problemas con redibujado de lineas en el form
Publicado por: 43H4FH44H45H4CH49H56H45H en 24 Agosto 2010, 05:34 am
En el  frmAddItem_Resize colocas:

Código
  1. Me.Refresh()

y con eso basta.