elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Mensajes
Páginas: 1 ... 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 [807] 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 ... 1254
8061  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 11 Noviembre 2013, 01:15 am
Una nueva versión de mi Listview, que tiene muchas cosas interesantes como poder dibujar una barra de progreso en una celda...

Ahora le añadí lo básico para hacer undo/redo para añadir o eliminar items.

Una pequeña demostración:



Un ejemplo de uso:

Código
  1. Public Class Form1
  2.  
  3.    Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  4.  
  5.        ' Enable the Undo/Redo Manager
  6.        ListView_Elektro1.Enable_UndoRedo_Manager = True
  7.  
  8.        ' Create an Item
  9.        Dim LVItem As New ListViewItem With {.Text = "Hello World"}
  10.  
  11.        ' Add the item
  12.        ListView_Elektro1.AddItem(LVItem)
  13.  
  14.        ' Remove the item
  15.        'ListView_Elektro1.RemoveItem(LVItem)
  16.  
  17.    End Sub
  18.  
  19.    ' Undo an operation
  20.    Private Sub Button_Undo_Click(sender As Object, e As EventArgs) Handles Button_Undo.Click
  21.        ListView_Elektro1.Undo()
  22.    End Sub
  23.  
  24.    ' Redo an operation
  25.    Private Sub Button_Redo_Click(sender As Object, e As EventArgs) Handles Button_Redo.Click
  26.        ListView_Elektro1.Redo()
  27.    End Sub
  28.  
  29.    ' Handles when an Undo or Redo operation is performed
  30.    Private Sub UndoRedo_Performed(sender As Object, e As ListView_Elektro.UndoneRedoneEventArgs) _
  31.    Handles ListView_Elektro1.UndoRedo_IsPerformed
  32.  
  33.        MsgBox(e.Operation.ToString)
  34.        MsgBox(e.Method.ToString)
  35.        MsgBox(e.Item.Text)
  36.  
  37.    End Sub
  38.  
  39.    ' Handles when a Undo or Redo stack size changed
  40.    Private Sub UndoRedo_StackSizeChanged(sender As Object, e As ListView_Elektro.StackSizeChangedEventArgs) _
  41.    Handles ListView_Elektro1.UndoRedo_StackSizeChanged
  42.  
  43.        MsgBox(e.UndoStackIsEmpty)
  44.        MsgBox(e.RedoStackIsEmpty)
  45.  
  46.    End Sub
  47.  
  48. End Class


El código completo del UserControl listo para ser compilado:

Código
  1. '  /*                  *\
  2. ' |#* ListView Elektro *#|
  3. '  \*                  */
  4. '
  5. ' // By Elektro H@cker
  6. '
  7. '   Properties:
  8. '   -----------
  9. ' · Disable_Flickering
  10. ' · Double_Buffer
  11. ' · GridLineColor
  12. ' · ItemHighlightColor
  13. ' · ItemNotFocusedHighlighColor
  14. ' · DrawCustomGridLines
  15. ' · UseDefaultGridLines
  16. ' · Enable_ProgressBar
  17. ' · Progressbar_Column
  18. ' · ProgressBar_BackColor
  19. ' · ProgressBar_BorderColor
  20. ' · ProgressBar_FillColor1
  21. ' · ProgressBar_FillColor2
  22. ' · Percent
  23. ' · Percent_Decimal
  24. ' · Percent_Font
  25. ' · Percent_Text
  26. ' · Percent_Forecolor
  27. ' · Percent_Text_Allignment
  28. ' · Enable_UndoRedo_Manager
  29.  
  30. '   Events:
  31. '   -------
  32. ' · ItemAdded
  33. ' · ItemRemoved
  34. ' · UndoRedo_IsPerformed
  35. ' · UndoRedo_StackSizeChanged
  36. '
  37. '   Methods:
  38. '   --------
  39. ' · AddItem
  40. ' · AddItems
  41. ' · RemoveItem
  42. ' · RemoveItems
  43. ' · Undo
  44. ' · Redo
  45.  
  46. Public Class ListView_Elektro : Inherits ListView
  47.  
  48.    Public Event ItemAdded As EventHandler(Of ItemAddedEventArgs)
  49.    Public Class ItemAddedEventArgs : Inherits EventArgs
  50.        Property Item As ListViewItem
  51.    End Class
  52.  
  53.    Public Event ItemRemoved As EventHandler(Of ItemRemovedEventArgs)
  54.    Public Class ItemRemovedEventArgs : Inherits EventArgs
  55.        Property Item As ListViewItem
  56.    End Class
  57.  
  58.    Private _Disable_Flickering As Boolean = True
  59.    Private _gridLines As Boolean = False
  60.    Private _useDefaultGridLines As Boolean = False
  61.    Private _gridLineColor As Color = Color.Black
  62.    Private _itemHighlightColor As Color = Color.FromKnownColor(KnownColor.Highlight)
  63.    Private _itemNotFocusedHighlighColor As Color = Color.FromKnownColor(KnownColor.MenuBar)
  64.  
  65.    Private _enable_progressbar As Boolean = False
  66.    Private _progressbar_column As Integer = Nothing
  67.  
  68.    Private _percent As Double = 0
  69.    Private _percent_decimal As Short = 2
  70.    Private _percent_text As String = "%"
  71.    Private _percent_text_allignment As StringAlignment = StringAlignment.Center
  72.    Private _percent_stringformat As StringFormat = New StringFormat With {.Alignment = _percent_text_allignment}
  73.    Private _percent_font As Font = Me.Font
  74.    Private _percent_forecolor As SolidBrush = New SolidBrush(Color.Black)
  75.  
  76.    Private _progressBar_backcolor As SolidBrush = New SolidBrush(Color.Red)
  77.    Private _progressBar_bordercolor As Pen = New Pen(Color.LightGray)
  78.    Private _progressBar_fillcolor1 As Color = Color.YellowGreen
  79.    Private _progressBar_fillcolor2 As Color = Color.White
  80.  
  81.    Public Sub New()
  82.  
  83.        Me.Name = "ListView_Elektro"
  84.        Me.DoubleBuffered = True
  85.        Me.UseDefaultGridLines = True
  86.  
  87.        ' Set Listview OwnerDraw to True, so we can draw the progressbar inside.
  88.        If Me.Enable_ProgressBar Then Me.OwnerDraw = True
  89.  
  90.        Me.GridLines = True
  91.        Me.FullRowSelect = True
  92.        Me.MultiSelect = True
  93.        Me.View = View.Details
  94.  
  95.    End Sub
  96.  
  97. #Region " Properties "
  98.  
  99.    ''' <summary>
  100.    ''' Enable/Disable any flickering effect on the ListView.
  101.    ''' </summary>
  102.    Protected Overrides ReadOnly Property CreateParams() As CreateParams
  103.        Get
  104.            If _Disable_Flickering Then
  105.                Dim cp As CreateParams = MyBase.CreateParams
  106.                cp.ExStyle = cp.ExStyle Or &H2000000
  107.                Return cp
  108.            Else
  109.                Return MyBase.CreateParams
  110.            End If
  111.        End Get
  112.    End Property
  113.  
  114.    ''' <summary>
  115.    ''' Set the Double Buffer.
  116.    ''' </summary>
  117.    Public Property Double_Buffer() As Boolean
  118.        Get
  119.            Return Me.DoubleBuffered
  120.        End Get
  121.        Set(ByVal Value As Boolean)
  122.            Me.DoubleBuffered = Value
  123.        End Set
  124.    End Property
  125.  
  126.    ''' <summary>
  127.    ''' Enable/Disable the flickering effects on this ListView.
  128.    '''
  129.    ''' This property turns off any Flicker effect on the ListView
  130.    ''' ...but also reduces the performance (speed) of the ListView about 30% slower.
  131.    ''' This don't affect to the performance of the application itself, only to the performance of this control.
  132.    ''' </summary>
  133.    Public Property Disable_Flickering() As Boolean
  134.        Get
  135.            Return _Disable_Flickering
  136.        End Get
  137.        Set(ByVal Value As Boolean)
  138.            Me._Disable_Flickering = Value
  139.        End Set
  140.    End Property
  141.  
  142.    ''' <summary>
  143.    ''' Changes the gridline color.
  144.    ''' </summary>
  145.    Public Property GridLineColor() As Color
  146.        Get
  147.            Return _gridLineColor
  148.        End Get
  149.        Set(ByVal value As Color)
  150.            If value <> _gridLineColor Then
  151.                _gridLineColor = value
  152.                If _gridLines Then
  153.                    Me.Invalidate()
  154.                End If
  155.            End If
  156.        End Set
  157.    End Property
  158.  
  159.    ''' <summary>
  160.    ''' Changes the color when item is highlighted.
  161.    ''' </summary>
  162.    Public Property ItemHighlightColor() As Color
  163.        Get
  164.            Return _itemHighlightColor
  165.        End Get
  166.        Set(ByVal value As Color)
  167.            If value <> _itemHighlightColor Then
  168.                _itemHighlightColor = value
  169.                Me.Invalidate()
  170.            End If
  171.        End Set
  172.    End Property
  173.  
  174.    ''' <summary>
  175.    ''' Changes the color when the item is not focused.
  176.    ''' </summary>
  177.    Public Property ItemNotFocusedHighlighColor() As Color
  178.        Get
  179.            Return _itemNotFocusedHighlighColor
  180.        End Get
  181.        Set(ByVal value As Color)
  182.            If value <> _itemNotFocusedHighlighColor Then
  183.                _itemNotFocusedHighlighColor = value
  184.                Me.Invalidate()
  185.            End If
  186.        End Set
  187.    End Property
  188.  
  189.    Private ReadOnly Property DrawCustomGridLines() As Boolean
  190.        Get
  191.            Return (_gridLines And Not _useDefaultGridLines)
  192.        End Get
  193.    End Property
  194.  
  195.    Public Shadows Property GridLines() As Boolean
  196.        Get
  197.            Return _gridLines
  198.        End Get
  199.        Set(ByVal value As Boolean)
  200.            _gridLines = value
  201.        End Set
  202.    End Property
  203.  
  204.    ''' <summary>
  205.    ''' use the default gridlines.
  206.    ''' </summary>
  207.    Public Property UseDefaultGridLines() As Boolean
  208.        Get
  209.            Return _useDefaultGridLines
  210.        End Get
  211.        Set(ByVal value As Boolean)
  212.            If _useDefaultGridLines <> value Then
  213.                _useDefaultGridLines = value
  214.            End If
  215.            MyBase.GridLines = value
  216.            MyBase.OwnerDraw = Not value
  217.        End Set
  218.    End Property
  219. #End Region
  220.  
  221. #Region " Procedures "
  222.  
  223.    ''' <summary>
  224.    ''' Adds an Item to the ListView,
  225.    ''' to monitor when an Item is added to the ListView.
  226.    ''' </summary>
  227.    Public Function AddItem(ByVal Item As ListViewItem) As ListViewItem
  228.        Me.Items.Add(Item)
  229.        RaiseEvent ItemAdded(Me, New ItemAddedEventArgs With {.Item = Item})
  230.        Return Item
  231.    End Function
  232.    Public Function AddItem(ByVal Text As String) As ListViewItem
  233.        Dim NewItem As New ListViewItem(Text)
  234.        Me.Items.Add(NewItem)
  235.        RaiseEvent ItemAdded(Me, New ItemAddedEventArgs With {.Item = NewItem})
  236.        Return NewItem
  237.    End Function
  238.  
  239.    ''' <summary>
  240.    ''' Removes an Item from the ListView
  241.    ''' to monitor when an Item is removed from the ListView.
  242.    ''' </summary>
  243.    Public Sub RemoveItem(ByVal Item As ListViewItem)
  244.        Me.Items.Remove(Item)
  245.        RaiseEvent ItemRemoved(Me, New ItemRemovedEventArgs With {.Item = Item})
  246.    End Sub
  247.  
  248.    ''' <summary>
  249.    ''' Removes an Item from the ListView at given Index
  250.    ''' to monitor when an Item is removed from the ListView.
  251.    ''' </summary>
  252.    Public Sub RemoveItem_At(ByVal Index As Integer)
  253.        RemoveItem(Me.Items.Item(Index))
  254.    End Sub
  255.  
  256.    ''' <summary>
  257.    ''' Removes an Item from the ListView at given Index
  258.    ''' to monitor when an Item is removed from the ListView.
  259.    ''' </summary>
  260.    Public Sub RemoveItems_At(ByVal Indexes As Integer())
  261.        Array.Sort(Indexes)
  262.        Array.Reverse(Indexes)
  263.        For Each Index As Integer In Indexes
  264.            RemoveItem(Me.Items.Item(Index))
  265.        Next
  266.    End Sub
  267.  
  268.    ''' <summary>
  269.    ''' Adds a range of Items to the ListView,
  270.    ''' to monitor when an Item is added to the ListView.
  271.    ''' </summary>
  272.    Public Sub AddItems(ByVal Items As ListViewItem())
  273.        For Each item As ListViewItem In Items
  274.            AddItem(item)
  275.        Next
  276.    End Sub
  277.    Public Sub AddItems(ByVal Items As ListViewItemCollection)
  278.        For Each item As ListViewItem In Items
  279.            AddItem(item)
  280.        Next
  281.    End Sub
  282.  
  283.    ''' <summary>
  284.    ''' Removes a range of Items from the ListView
  285.    ''' to monitor when an Item is removed from the ListView.
  286.    ''' </summary>
  287.    Public Sub RemoveItems(ByVal Items As ListViewItem())
  288.        For Each item As ListViewItem In Items
  289.            RemoveItem(item)
  290.        Next
  291.    End Sub
  292.    Public Sub RemoveItems(ByVal Items As ListViewItemCollection)
  293.        For Each item As ListViewItem In Items
  294.            RemoveItem(item)
  295.        Next
  296.    End Sub
  297.    Public Sub RemoveItems(ByVal Items As SelectedListViewItemCollection)
  298.        For Each item As ListViewItem In Items
  299.            RemoveItem(item)
  300.        Next
  301.    End Sub
  302.  
  303.    Protected Overrides Sub OnDrawColumnHeader(ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs)
  304.        e.DrawDefault = True
  305.        MyBase.OnDrawColumnHeader(e)
  306.    End Sub
  307.  
  308.    Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
  309.        For Each selectedIndex As Integer In MyBase.SelectedIndices
  310.            MyBase.RedrawItems(selectedIndex, selectedIndex, False)
  311.        Next
  312.        MyBase.OnLostFocus(e)
  313.    End Sub
  314.  
  315.    Protected Overrides Sub OnDrawSubItem(ByVal e As System.Windows.Forms.DrawListViewSubItemEventArgs)
  316.  
  317.        Dim drawAsDefault As Boolean = False
  318.        Dim highlightBounds As Rectangle = Nothing
  319.        Dim highlightBrush As SolidBrush = Nothing
  320.  
  321.        'FIRST DETERMINE THE COLOR
  322.        If e.Item.Selected Then
  323.            If MyBase.Focused Then
  324.                highlightBrush = New SolidBrush(_itemHighlightColor)
  325.            ElseIf HideSelection Then
  326.                drawAsDefault = True
  327.            Else
  328.                highlightBrush = New SolidBrush(_itemNotFocusedHighlighColor)
  329.            End If
  330.        Else
  331.            drawAsDefault = True
  332.        End If
  333.  
  334.        If drawAsDefault Then
  335.            e.DrawBackground()
  336.        Else
  337.            'NEXT DETERMINE THE BOUNDS IN WHICH TO DRAW THE BACKGROUND
  338.            If FullRowSelect Then
  339.                highlightBounds = e.Bounds
  340.            Else
  341.                highlightBounds = e.Item.GetBounds(ItemBoundsPortion.Label)
  342.            End If
  343.  
  344.            'ONLY DRAW HIGHLIGHT IN 1 OF 2 CASES
  345.            'CASE 1 - FULL ROW SELECT (AND DRAWING ANY ITEM)
  346.            'CASE 2 - NOT FULL ROW SELECT (AND DRAWING 1ST ITEM)
  347.            If FullRowSelect Then
  348.                e.Graphics.FillRectangle(highlightBrush, highlightBounds)
  349.            ElseIf e.ColumnIndex = 0 Then
  350.                e.Graphics.FillRectangle(highlightBrush, highlightBounds)
  351.            Else
  352.                e.DrawBackground()
  353.            End If
  354.        End If
  355.  
  356.        e.DrawText()
  357.  
  358.        If _gridLines Then
  359.            e.Graphics.DrawRectangle(New Pen(_gridLineColor), e.Bounds)
  360.        End If
  361.  
  362.  
  363.        If FullRowSelect Then
  364.            e.DrawFocusRectangle(e.Item.GetBounds(ItemBoundsPortion.Entire))
  365.        Else
  366.            e.DrawFocusRectangle(e.Item.GetBounds(ItemBoundsPortion.Label))
  367.        End If
  368.  
  369.        MyBase.OnDrawSubItem(e)
  370.  
  371.    End Sub
  372.  
  373. #End Region
  374.  
  375. #Region " ProgressBar Properties "
  376.  
  377.    ''' <summary>
  378.    ''' Enables the drawing of a ProgressBar
  379.    ''' This property should be "True" to use any of the ProgressBar properties.
  380.    ''' </summary>
  381.    Public Property Enable_ProgressBar As Boolean
  382.        Get
  383.            Return _enable_progressbar
  384.        End Get
  385.        Set(ByVal value As Boolean)
  386.            Me.OwnerDraw = value
  387.            _enable_progressbar = value
  388.        End Set
  389.    End Property
  390.  
  391.    ''' <summary>
  392.    ''' The column index to draw the ProgressBar
  393.    ''' </summary>
  394.    Public Property Progressbar_Column As Integer
  395.        Get
  396.            Return _progressbar_column
  397.        End Get
  398.        Set(ByVal value As Integer)
  399.            _progressbar_column = value
  400.        End Set
  401.    End Property
  402.  
  403.    ''' <summary>
  404.    ''' The ProgressBar progress percentage
  405.    ''' </summary>
  406.    Public Property Percent As Double
  407.        Get
  408.            Return _percent
  409.        End Get
  410.        Set(ByVal value As Double)
  411.            _percent = value
  412.        End Set
  413.    End Property
  414.  
  415.    ''' <summary>
  416.    ''' The decimal factor which should be displayed for the ProgressBar progress percentage
  417.    ''' </summary>
  418.    Public Property Percent_Decimal As Short
  419.        Get
  420.            Return _percent_decimal
  421.        End Get
  422.        Set(ByVal value As Short)
  423.            _percent_decimal = value
  424.        End Set
  425.    End Property
  426.  
  427.    ''' <summary>
  428.    ''' The Font to be used as the ProgressBar Percent text
  429.    ''' </summary>
  430.    Public Property Percent_Font As Font
  431.        Get
  432.            Return _percent_font
  433.        End Get
  434.        Set(ByVal value As Font)
  435.            _percent_font = value
  436.        End Set
  437.    End Property
  438.  
  439.    ''' <summary>
  440.    ''' The additional text to add to the ProgressBar Percent value
  441.    ''' </summary>
  442.    Public Property Percent_Text As String
  443.        Get
  444.            Return _percent_text
  445.        End Get
  446.        Set(ByVal value As String)
  447.            _percent_text = value
  448.        End Set
  449.    End Property
  450.  
  451.    ''' <summary>
  452.    ''' The ForeColor of the ProgressBar Percent Text
  453.    ''' </summary>
  454.    Public Property Percent_Forecolor As Color
  455.        Get
  456.            Return _percent_forecolor.Color
  457.        End Get
  458.        Set(ByVal value As Color)
  459.            _percent_forecolor = New SolidBrush(value)
  460.        End Set
  461.    End Property
  462.  
  463.    ''' <summary>
  464.    ''' The text allignment to use for the ProgressBar
  465.    ''' </summary>
  466.    Public Property Percent_Text_Allignment As StringAlignment
  467.        Get
  468.            Return _percent_stringformat.Alignment
  469.        End Get
  470.        Set(ByVal value As StringAlignment)
  471.            _percent_stringformat.Alignment = value
  472.        End Set
  473.    End Property
  474.  
  475.    ''' <summary>
  476.    ''' The ProgressBar BackColor
  477.    ''' </summary>
  478.    Public Property ProgressBar_BackColor As Color
  479.        Get
  480.            Return _progressBar_backcolor.Color
  481.        End Get
  482.        Set(ByVal value As Color)
  483.            _progressBar_backcolor = New SolidBrush(value)
  484.        End Set
  485.    End Property
  486.  
  487.    ''' <summary>
  488.    ''' The ProgressBar BorderColor
  489.    ''' </summary>
  490.    Public Property ProgressBar_BorderColor As Color
  491.        Get
  492.            Return _progressBar_bordercolor.Color
  493.        End Get
  494.        Set(ByVal value As Color)
  495.            _progressBar_bordercolor = New Pen(value)
  496.        End Set
  497.    End Property
  498.  
  499.    ''' <summary>
  500.    ''' The First ProgressBar Gradient color
  501.    ''' </summary>
  502.    Public Property ProgressBar_FillColor1 As Color
  503.        Get
  504.            Return _progressBar_fillcolor1
  505.        End Get
  506.        Set(ByVal value As Color)
  507.            _progressBar_fillcolor1 = value
  508.        End Set
  509.    End Property
  510.  
  511.    ''' <summary>
  512.    ''' The Last ProgressBar Gradient color
  513.    ''' </summary>
  514.    Public Property ProgressBar_FillColor2 As Color
  515.        Get
  516.            Return _progressBar_fillcolor2
  517.        End Get
  518.        Set(ByVal value As Color)
  519.            _progressBar_fillcolor2 = value
  520.        End Set
  521.    End Property
  522.  
  523. #End Region
  524.  
  525. #Region " ProgressBar EventHandlers "
  526.  
  527.    ' ListView [DrawColumnHeader]
  528.    Public Sub Me_DrawColumnHeader(ByVal sender As Object, ByVal e As DrawListViewColumnHeaderEventArgs) _
  529.    Handles Me.DrawColumnHeader
  530.  
  531.        e.DrawDefault = True ' Draw default ColumnHeader.
  532.  
  533.    End Sub
  534.  
  535.    ' ListView [DrawItem]
  536.    Public Sub Me_DrawItem(ByVal sender As Object, ByVal e As DrawListViewItemEventArgs) _
  537.    Handles Me.DrawItem
  538.  
  539.        e.DrawDefault = False ' Draw default main item.
  540.  
  541.    End Sub
  542.  
  543.    ' ListView [DrawSubItem]
  544.    Public Sub Me_DrawSubItem(ByVal sender As Object, ByVal e As DrawListViewSubItemEventArgs) _
  545.    Handles Me.DrawSubItem
  546.  
  547.        If Not Enable_ProgressBar OrElse Progressbar_Column = Nothing Then
  548.            Exit Sub
  549.        End If
  550.  
  551.        ' Item is highlighted.
  552.        ' If (e.ItemState And ListViewItemStates.Selected) <> 0 Then
  553.        '     e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds)
  554.        ' End If
  555.  
  556.        ' Draw the progressbar.
  557.        If e.ColumnIndex = Progressbar_Column Then
  558.  
  559.            ' Background color of the progressbar.
  560.            e.Graphics.FillRectangle(_progressBar_backcolor, e.Bounds)
  561.  
  562.            ' Gradient to fill the progressbar.
  563.            Dim brGradient As Brush = _
  564.                New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), _
  565.                                                                 ProgressBar_FillColor1, ProgressBar_FillColor2, 270, True)
  566.            ' Draw the actual progressbar.
  567.            e.Graphics.FillRectangle(brGradient, _
  568.                                     e.Bounds.X + 1, e.Bounds.Y + 2, _
  569.                                     CInt(((Percent) / 100) * (e.Bounds.Width - 2)), e.Bounds.Height - 3)
  570.  
  571.            ' Draw the percentage number and percent sign.
  572.            e.Graphics.DrawString(Percent.ToString("n" & Percent_Decimal) & Percent_Text, _
  573.                                  Percent_Font, _percent_forecolor, _
  574.                                  CSng(e.Bounds.X + (e.Bounds.Width / 2)), e.Bounds.Y + 3, _
  575.                                  _percent_stringformat)
  576.  
  577.            ' Draw a light gray rectangle/border around the progressbar.
  578.            e.Graphics.DrawRectangle(_progressBar_bordercolor, _
  579.                                     e.Bounds.X, e.Bounds.Y + 1, _
  580.                                     e.Bounds.Width - 1, e.Bounds.Height - 2)
  581.        Else
  582.  
  583.            ' e.DrawDefault = True
  584.  
  585.        End If
  586.  
  587.    End Sub
  588.  
  589. #End Region
  590.  
  591. #Region " Undo/Redo Manager "
  592.  
  593.    ''' <summary>
  594.    ''' Enable or disble the Undo/Redo monitoring.
  595.    ''' </summary>
  596.    Public Property Enable_UndoRedo_Manager As Boolean = False
  597.  
  598.    ' Stacks to store Undo/Redo actions.
  599.    Public Undostack As New Stack(Of ListView_Action)
  600.    Public Redostack As New Stack(Of ListView_Action)
  601.  
  602.    ' Flags to check if it is doing a Undo/Redo operation.
  603.    Private IsDoingUndo As Boolean = False
  604.    Private IsDoingRedo As Boolean = False
  605.  
  606.    ' Delegate to Add an Item for Undo/Redo operations.
  607.    Private Delegate Sub AddDelegate(item As ListViewItem)
  608.  
  609.    ' Delegate to Remove an Item for Undo/Redo operations.
  610.    Private Delegate Sub RemoveDelegate(item As ListViewItem)
  611.  
  612.    ' The Undo/Redo action.
  613.    Private action As ListView_Action = Nothing
  614.  
  615.    ' The operation.
  616.    Public Enum Operation As Short
  617.        Undo = 0
  618.        Redo = 1
  619.    End Enum
  620.  
  621.    ' The method for the Undo/Redo operation.
  622.    Public Enum Method As Short
  623.        Add = 0
  624.        Remove = 1
  625.    End Enum
  626.  
  627.    ''' <summary>
  628.    ''' Creates a Undo/Redo Action.
  629.    ''' </summary>
  630.    Class ListView_Action
  631.  
  632.        ''' <summary>
  633.        ''' Names the Undo/Redo Action.
  634.        ''' </summary>
  635.        Property Name As String
  636.  
  637.        ''' <summary>
  638.        ''' Points to a method to excecute.
  639.        ''' </summary>
  640.        Property Operation As [Delegate]
  641.  
  642.        ''' <summary>
  643.        ''' Method of the Undo/Redo operation.
  644.        ''' </summary>
  645.        Property Method As Method
  646.  
  647.        ''' <summary>
  648.        ''' Data Array for the method to excecute.
  649.        ''' </summary>
  650.        Property Data As ListViewItem
  651.  
  652.    End Class
  653.  
  654.    ''' <summary>
  655.    ''' This event is raised after an Undo/Redo action is performed.
  656.    ''' </summary>
  657.    Public Event UndoRedo_IsPerformed As EventHandler(Of UndoneRedoneEventArgs)
  658.    Public Class UndoneRedoneEventArgs : Inherits EventArgs
  659.        Property Operation As Operation
  660.        Property Method As Method
  661.        Property Item As ListViewItem
  662.        Property UndoStack As Stack(Of ListView_Action)
  663.        Property RedoStack As Stack(Of ListView_Action)
  664.    End Class
  665.  
  666.    ''' <summary>
  667.    ''' This event is raised when Undo/Redo Stack size changed.
  668.    ''' </summary>
  669.    Public Event UndoRedo_StackSizeChanged As EventHandler(Of StackSizeChangedEventArgs)
  670.    Public Class StackSizeChangedEventArgs : Inherits EventArgs
  671.        Property UndoStack As Stack(Of ListView_Action)
  672.        Property RedoStack As Stack(Of ListView_Action)
  673.        Property UndoStackIsEmpty As Boolean
  674.        Property RedoStackIsEmpty As Boolean
  675.    End Class
  676.  
  677.    ''' <summary>
  678.    ''' Undo the last action.
  679.    ''' </summary>
  680.    Public Sub Undo()
  681.  
  682.        If Me.Undostack.Count = 0 Then Exit Sub ' Nothing to Undo.
  683.  
  684.        Me.IsDoingUndo = True
  685.        Me.action = Me.Undostack.Pop ' Get the Action from the Stack and remove it.
  686.        Me.action.Operation.DynamicInvoke(Me.action.Data) ' Invoke the undo Action.
  687.        Me.IsDoingUndo = False
  688.  
  689.        Raise_UndoRedo_IsPerformed(Operation.Undo, Me.action.Method, Me.action.Data)
  690.  
  691.    End Sub
  692.  
  693.    ''' <summary>
  694.    ''' Redo the last action.
  695.    ''' </summary>
  696.    Public Sub Redo()
  697.  
  698.        If Me.Redostack.Count = 0 Then Exit Sub ' Nothing to Redo.
  699.  
  700.        Me.IsDoingRedo = True
  701.        Me.action = Me.Redostack.Pop() ' Get the Action from the Stack and remove it.
  702.        Me.action.Operation.DynamicInvoke(Me.action.Data) ' Invoke the redo Action.
  703.        Me.IsDoingRedo = False
  704.  
  705.        Raise_UndoRedo_IsPerformed(Operation.Redo, Me.action.Method, Me.action.Data)
  706.  
  707.    End Sub
  708.  
  709.    ' Reverses an Undo/Redo action
  710.    Private Function GetReverseAction(ByVal e As UndoneRedoneEventArgs) As ListView_Action
  711.  
  712.        Me.action = New ListView_Action
  713.  
  714.        Me.action.Name = e.Item.Text
  715.        Me.action.Data = e.Item
  716.  
  717.        Me.action.Operation = If(e.Method = Method.Add, _
  718.                        New RemoveDelegate(AddressOf Me.RemoveItem), _
  719.                        New AddDelegate(AddressOf Me.AddItem))
  720.  
  721.        Me.action.Method = If(e.Method = Method.Add, _
  722.                     Method.Remove, _
  723.                     Method.Add)
  724.  
  725.        Return Me.action
  726.  
  727.    End Function
  728.  
  729.    ' Raises the "UndoRedo_IsPerformed" Event
  730.    Private Sub Raise_UndoRedo_IsPerformed(ByVal Operation As Operation, _
  731.                                           ByVal Method As Method, _
  732.                                           ByVal Item As ListViewItem)
  733.  
  734.        RaiseEvent UndoRedo_IsPerformed(Me, New UndoneRedoneEventArgs _
  735.                   With {.Item = Item, _
  736.                         .Method = Method, _
  737.                         .Operation = Operation, _
  738.                         .UndoStack = Me.Undostack, _
  739.                         .RedoStack = Me.Redostack})
  740.  
  741.        Raise_UndoRedo_StackSizeChanged()
  742.  
  743.    End Sub
  744.  
  745.    ' Raises the "UndoRedo_StackSizeChanged" Event
  746.    Private Sub Raise_UndoRedo_StackSizeChanged()
  747.  
  748.        RaiseEvent UndoRedo_StackSizeChanged(Me, New StackSizeChangedEventArgs _
  749.                   With {.UndoStack = Me.Undostack, _
  750.                         .RedoStack = Me.Redostack, _
  751.                         .UndoStackIsEmpty = Me.Undostack.Count = 0, _
  752.                         .RedoStackIsEmpty = Me.Redostack.Count = 0})
  753.  
  754.    End Sub
  755.  
  756.    ' This handles when an Undo or Redo operation is performed.
  757.    Private Sub UndoneRedone(ByVal sender As Object, ByVal e As UndoneRedoneEventArgs) _
  758.    Handles Me.UndoRedo_IsPerformed
  759.  
  760.        Select Case e.Operation
  761.  
  762.            Case Operation.Undo
  763.                ' Create a Redo Action for the undone action.
  764.                Me.Redostack.Push(GetReverseAction(e))
  765.  
  766.            Case Operation.Redo
  767.                ' Create a Undo Action for the redone action.
  768.                Me.Undostack.Push(GetReverseAction(e))
  769.  
  770.        End Select
  771.  
  772.    End Sub
  773.  
  774.    ' Monitors when an Item is added to create an Undo Operation.
  775.    Private Sub OnItemAdded(sender As Object, e As ItemAddedEventArgs) _
  776.    Handles Me.ItemAdded
  777.  
  778.        If Me.Enable_UndoRedo_Manager _
  779.            AndAlso (Not Me.IsDoingUndo And Not Me.IsDoingRedo) Then
  780.  
  781.            Me.Redostack.Clear()
  782.  
  783.            ' // Crate an Undo Action
  784.            Me.action = New ListView_Action
  785.            Me.action.Name = e.Item.Text
  786.            Me.action.Operation = New RemoveDelegate(AddressOf Me.RemoveItem)
  787.            Me.action.Data = e.Item
  788.            Me.action.Method = Method.Remove
  789.  
  790.            Me.Undostack.Push(action)
  791.  
  792.            Raise_UndoRedo_StackSizeChanged()
  793.  
  794.        End If
  795.  
  796.    End Sub
  797.  
  798.    ' Monitors when an Item is removed to create an Undo Operation.
  799.    Private Sub OnItemRemoved(sender As Object, e As ItemRemovedEventArgs) _
  800.    Handles Me.ItemRemoved
  801.  
  802.        If Me.Enable_UndoRedo_Manager _
  803.            AndAlso (Not Me.IsDoingUndo And Not Me.IsDoingRedo) Then
  804.  
  805.            Me.Redostack.Clear()
  806.  
  807.            ' // Crate an Undo Action
  808.            Me.action = New ListView_Action
  809.            Me.action.Name = e.Item.Text
  810.            Me.action.Operation = New AddDelegate(AddressOf Me.AddItem)
  811.            Me.action.Data = e.Item
  812.            Me.action.Method = Method.Add
  813.  
  814.            Me.Undostack.Push(action)
  815.  
  816.            Raise_UndoRedo_StackSizeChanged()
  817.  
  818.        End If
  819.  
  820.    End Sub
  821.  
  822. #End Region
  823.  
  824. End Class
8062  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 10 Noviembre 2013, 21:04 pm
· Juntar múltiples listas:

Código
  1. #Region " Join Lists "
  2.  
  3.    ' [ Join Lists ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' Dim list_A As New List(Of String) From {"a", "b"}
  10.    ' Dim list_B As New List(Of String) From {"c", "d"}
  11.    ' Dim newlist As List(Of String) = Join_Lists(Of String)({list_A, list_B}) ' Result: {"a", "b", "c", "d"}
  12.  
  13.    Private Function Join_Lists(Of T)(ByVal Lists() As List(Of T)) As List(Of T)
  14.        Return Lists.SelectMany(Function(l) l).ToList
  15.    End Function
  16.  
  17. #End Region





· Revertir un Stack:

Código
  1. #Region " Reverse Stack "
  2.  
  3.    ' [ Reverse Stack ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' Dim MyStack As New Stack(Of String)
  8.    '
  9.    ' MyStack.Push("S") : MyStack.Push("T") : MyStack.Push("A") : MyStack.Push("C") : MyStack.Push("K")
  10.    '
  11.    ' MyStack = Reverse_Stack(Of String)(MyStack)
  12.    '
  13.    ' For Each value In MyStack
  14.    '     MsgBox(value)
  15.    ' Next
  16.  
  17.    Private Function Reverse_Stack(Of T)(stack As Stack(Of T)) As Stack(Of T)
  18.        Return New Stack(Of T)(stack)
  19.    End Function
  20.  
  21. #End Region





· Eliminar las lineas vacias de un archivo de texto:

Código
  1. #Region " Delete Empty Lines In TextFile "
  2.  
  3.    ' [ Delete Empty Lines In TextFile ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' Delete_Empty_Lines_In_TextFile("C:\File.txt")
  10.    ' Delete_Empty_Lines_In_TextFile("C:\File.txt", System.Text.Encoding.GetEncoding(1252))
  11.  
  12.    Private Sub Delete_Empty_Lines_In_TextFile(ByVal file As String, _
  13.                                               Optional ByVal encoding As System.Text.Encoding = Nothing)
  14.  
  15.        IO.File.WriteAllLines(file, IO.File.ReadAllLines(file) _
  16.                                    .Where(Function(line) Not String.IsNullOrEmpty(line)) _
  17.                                    , If(encoding Is Nothing, System.Text.Encoding.Default, encoding))
  18.  
  19.    End Sub
  20.  
  21. #End Region




Y por último esta Class para dockear un Form,
le añadí lo necesario para poder bloquear la posición del form (no el tamaño, me parece irrelevante).

Código
  1. ' [ Form Dock ]
  2. '
  3. ' // By Elektro H@cker
  4.  
  5. #Region " Usage Examples "
  6.  
  7. ' Private _formdock As New FormDock(Me) With {.LockPosition = True}
  8. '
  9. ' Private Shadows Sub Shown() Handles MyBase.Shown
  10. '
  11. '   _formdock.Dock(FormDock.DockPosition.WorkingArea_BottomRight)
  12. '
  13. ' End Sub
  14.  
  15. #End Region
  16.  
  17. #Region " Form Dock "
  18.  
  19. Public Class FormDock
  20.    Inherits NativeWindow
  21.    Implements IDisposable
  22.  
  23. #Region " Variables, Properties and Enumerations "
  24.  
  25.    ''' <summary>
  26.    ''' While the property still Enabled it will locks the formulary position.
  27.    ''' </summary>
  28.    Public Property LockPosition As Boolean = False
  29.  
  30.    ''' <summary>
  31.    ''' Stores the formulary to Dock.
  32.    ''' </summary>
  33.    Private WithEvents form As Form = Nothing
  34.  
  35.    ''' <summary>
  36.    ''' Stores the size of the formulary to Dock.
  37.    ''' </summary>
  38.    Private UI_Size As Size = Nothing
  39.  
  40.    ''' <summary>
  41.    ''' Stores the Dock positions.
  42.    ''' </summary>
  43.    Private Dock_Positions As Dictionary(Of DockPosition, Point)
  44.  
  45.    ''' <summary>
  46.    ''' Dock Positions.
  47.    ''' </summary>
  48.    Public Enum DockPosition As Short
  49.        Center_Screen = 0
  50.        Bounds_BottomLeft = 1
  51.        Bounds_BottomRight = 2
  52.        Bounds_TopLeft = 3
  53.        Bounds_TopRight = 4
  54.        WorkingArea_BottomLeft = 5
  55.        WorkingArea_BottomRight = 6
  56.        WorkingArea_TopLeft = 7
  57.        WorkingArea_TopRight = 8
  58.    End Enum
  59.  
  60. #End Region
  61.  
  62. #Region " New Constructor "
  63.  
  64.    Public Sub New(ByVal form As Form)
  65.  
  66.        Me.form = form
  67.        SetHandle()
  68.  
  69.    End Sub
  70.  
  71. #End Region
  72.  
  73. #Region " Public Procedures "
  74.  
  75.    ''' <summary>
  76.    ''' Docks the form.
  77.    ''' </summary>
  78.    Public Sub Dock(ByVal Position As DockPosition)
  79.  
  80.        If Dock_Positions Is Nothing Then
  81.            Renew_Positions(form)
  82.        End If
  83.  
  84.        form.Location = Dock_Positions(Position)
  85.  
  86.    End Sub
  87.  
  88. #End Region
  89.  
  90. #Region " Miscellaneous Procedures "
  91.  
  92.    ''' <summary>
  93.    ''' Renews the Dock positions according to the the current form Size.
  94.    ''' </summary>
  95.    Private Sub Renew_Positions(ByVal form As Form)
  96.  
  97.        UI_Size = form.Size
  98.  
  99.        Dock_Positions = New Dictionary(Of DockPosition, Point) _
  100.        From {
  101.                 {DockPosition.Center_Screen,
  102.                               New Point((Screen.PrimaryScreen.Bounds.Width - UI_Size.Width) \ 2,
  103.                                         (Screen.PrimaryScreen.Bounds.Height - UI_Size.Height) \ 2)},
  104.                 {DockPosition.Bounds_BottomLeft,
  105.                               New Point(Screen.PrimaryScreen.Bounds.X,
  106.                                         Screen.PrimaryScreen.Bounds.Height - UI_Size.Height)},
  107.                 {DockPosition.Bounds_BottomRight,
  108.                           New Point(Screen.PrimaryScreen.Bounds.Width - UI_Size.Width,
  109.                                     Screen.PrimaryScreen.Bounds.Height - UI_Size.Height)},
  110.                 {DockPosition.Bounds_TopLeft,
  111.                               New Point(Screen.PrimaryScreen.Bounds.X,
  112.                                         Screen.PrimaryScreen.Bounds.Y)},
  113.                 {DockPosition.Bounds_TopRight,
  114.                               New Point(Screen.PrimaryScreen.Bounds.Width - UI_Size.Width,
  115.                                         Screen.PrimaryScreen.Bounds.Y)},
  116.                 {DockPosition.WorkingArea_BottomLeft,
  117.                               New Point(Screen.PrimaryScreen.WorkingArea.X,
  118.                                         Screen.PrimaryScreen.WorkingArea.Height - UI_Size.Height)},
  119.                 {DockPosition.WorkingArea_BottomRight,
  120.                               New Point(Screen.PrimaryScreen.WorkingArea.Width - UI_Size.Width,
  121.                                         Screen.PrimaryScreen.WorkingArea.Height - UI_Size.Height)},
  122.                 {DockPosition.WorkingArea_TopLeft,
  123.                               New Point(Screen.PrimaryScreen.WorkingArea.X,
  124.                                         Screen.PrimaryScreen.WorkingArea.Y)},
  125.                 {DockPosition.WorkingArea_TopRight,
  126.                               New Point(Screen.PrimaryScreen.WorkingArea.Width - UI_Size.Width,
  127.                                         Screen.PrimaryScreen.WorkingArea.Y)}
  128.            }
  129.  
  130.    End Sub
  131.  
  132. #End Region
  133.  
  134. #Region " Form EventHandlers "
  135.  
  136.    ''' <summary>
  137.    ''' Renews the Dock positions according to the the current form Size,
  138.    ''' when Form is Shown.
  139.    ''' </summary>
  140.    Private Sub OnShown() _
  141.    Handles form.Shown
  142.  
  143.        If Not UI_Size.Equals(Me.form.Size) Then
  144.            Renew_Positions(Me.form)
  145.        End If
  146.  
  147.    End Sub
  148.  
  149.    ''' <summary>
  150.    ''' Renews the Dock positions according to the the current form Size,
  151.    ''' When Form is resized.
  152.    ''' </summary>
  153.    Private Sub OnResizeEnd() _
  154.    Handles form.ResizeEnd
  155.  
  156.        If Not UI_Size.Equals(Me.form.Size) Then
  157.            Renew_Positions(Me.form)
  158.        End If
  159.  
  160.    End Sub
  161.  
  162.    ''' <summary>
  163.    ''' SetHandle
  164.    ''' Assign the handle of the target form to this NativeWindow,
  165.    ''' necessary to override WndProc.
  166.    ''' </summary>
  167.    Private Sub SetHandle() Handles _
  168.        form.HandleCreated,
  169.        form.Load,
  170.        form.Shown
  171.  
  172.        Try
  173.            If Not Me.Handle.Equals(Me.form.Handle) Then
  174.                Me.AssignHandle(Me.form.Handle)
  175.            End If
  176.        Catch ex As InvalidOperationException
  177.        End Try
  178.  
  179.    End Sub
  180.  
  181.    ''' <summary>
  182.    ''' Releases the Handle.
  183.    ''' </summary>
  184.    Private Sub OnHandleDestroyed() _
  185.    Handles form.HandleDestroyed
  186.  
  187.        Me.ReleaseHandle()
  188.  
  189.    End Sub
  190.  
  191. #End Region
  192.  
  193. #Region " Windows Messages "
  194.  
  195.    ''' <summary>
  196.    ''' WndProc Message Interception.
  197.    ''' </summary>
  198.    Protected Overrides Sub WndProc(ByRef m As Message)
  199.  
  200.        If Me.LockPosition Then
  201.  
  202.            Select Case m.Msg
  203.  
  204.                Case &HA1
  205.                    ' Cancels any attempt to drag the window by it's caption.
  206.                    If m.WParam.ToInt32 = &H2 Then Return
  207.  
  208.                Case &H112
  209.                    ' Cancels any clicks on the Move system menu item.
  210.                    If (m.WParam.ToInt32 And &HFFF0) = &HF010& Then Return
  211.  
  212.            End Select
  213.  
  214.        End If
  215.  
  216.        ' Return control to base message handler.
  217.        MyBase.WndProc(m)
  218.  
  219.    End Sub
  220.  
  221. #End Region
  222.  
  223. #Region " IDisposable "
  224.  
  225.    ''' <summary>
  226.    ''' Disposes the objects generated by this instance.
  227.    ''' </summary>
  228.    Public Sub Dispose() Implements IDisposable.Dispose
  229.        Dispose(True)
  230.        GC.SuppressFinalize(Me)
  231.    End Sub
  232.  
  233.    Protected Overridable Sub Dispose(IsDisposing As Boolean)
  234.  
  235.        Static IsBusy As Boolean ' To detect redundant calls.
  236.  
  237.        If Not IsBusy AndAlso IsDisposing Then
  238.  
  239.            Me.LockPosition = False
  240.            Me.ReleaseHandle()
  241.  
  242.        End If
  243.  
  244.        IsBusy = True
  245.  
  246.    End Sub
  247.  
  248. #End Region
  249.  
  250. End Class
  251.  
  252. #End Region
8063  Programación / .NET (C#, VB.NET, ASP) / Re: Cómo obtener datos de un form principal a uno secundario en .NET en: 10 Noviembre 2013, 19:21 pm
Declara una property como te ha indicado el compañero @Hadess_inf

Solo es necesario que modifiques el código del formulario que contiene el primer TextBox:

Código
  1. Public Class Form1
  2.  
  3.    Public Property TB_text As String
  4.        Get
  5.            Return Me.TB.Text
  6.        End Get
  7.        Set(ByVal str As String)
  8.            Form2.TB.Text = str
  9.        End Set
  10.    End Property
  11.  
  12.    Private Sub TB_TextChanged(sender As Object, e As EventArgs) _
  13.    Handles TB.TextChanged
  14.        Me.TB_text = sender.text
  15.    End Sub
  16.  
  17.    Private Shadows Sub Load() Handles MyBase.Load
  18.        Me.TB.Text = "Hello World!"
  19.        Form2.Show()
  20.    End Sub
  21.  
  22. End Class

La intención es separar un poco los datos, de la UI, siempre hay que tener los buenos hábitos en mente... (aunque esto no sea WPF), pero si lo prefieres diréctamente puedes ahorrarte la propiedad y utilizar el evento OnTextChanged para interactuar con el Textbox secundario:

Código
  1. Public Class Form1
  2.  
  3.    Private Shadows Sub Load() Handles MyBase.Load
  4.        Form2.Show()
  5.        TB.Text = "Hello World!"
  6.    End Sub
  7.  
  8.    Private Sub TB_TextChanged(sender As Object, e As EventArgs) _
  9.    Handles TB.TextChanged
  10.        Form2.TB.Text = sender.text
  11.    End Sub
  12.  
  13. End Class

Saludos
8064  Programación / .NET (C#, VB.NET, ASP) / Re: Enviar y Recibir SMS desde la PC con vb.NET en: 10 Noviembre 2013, 19:00 pm
Aquí tienes lo necesario:
.NET Phone Communication Library Part IV - Receive SMS

Plus:
.NET Phone Communication Library Part I - Retrieve Phone Settings

PD: El resto de artículos parece que han sido eliminados por antiguedad.

Saludos
8065  Programación / .NET (C#, VB.NET, ASP) / Re: [C#] [VB.NET] Enums con valores duplicados en: 10 Noviembre 2013, 18:45 pm
@Keyen Night gracias

Cierro el tema.
8066  Programación / .NET (C#, VB.NET, ASP) / Re: Pregunta tonta ? como cambiar icono en visual net 2010 ejecutables y formularios en: 1 Noviembre 2013, 15:20 pm
¿Los iconos los tienes en formato ICO o son en formato PNG?,  si te fijas el diálogo está filtrado para mostrar sólamente iconos en formato ICO, no PNG...

(no quiero pensar que reálmente no te reconoce los iconos ICO... es casi imposible, segúramente la causa sea lo que te acabo de decir)

De todas formas te digo como hacerlo de forma manual...

Para el icono del exe, en el archivo .vbproj de tu solución añade esto:
Código:
  <PropertyGroup>
    <ApplicationIcon>C:\ruta del icono.ICO</ApplicationIcon>
  </PropertyGroup>

Y para cambiar el icono del formulario...
Código
  1.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.  
  3.        Dim bmp As Bitmap = Bitmap.FromFile("C:\ruta del icono.ICO")
  4.  
  5.        Me.Icon = System.Drawing.Icon.FromHandle(bmp.GetHicon())
  6.  
  7.    End Sub

Saludos
8067  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 1 Noviembre 2013, 14:56 pm
Dado un número, devuelve el valor más próximo de un Enum.

Código
  1.    #Region " Get Nearest Enum Value "
  2.  
  3.       ' [ Get Nearest Enum Value ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       '
  9.       ' Enum Bitrate As Short : kbps_128 = 128 : kbps_192 = 192 : kbps_256 = 256 : kbps_320 = 320 : End Enum
  10.       ' MsgBox(Get_Nearest_Enum_Value(Of Bitrate)(133).ToString) ' Result: kbps_128
  11.       ' MsgBox(Get_Nearest_Enum_Value(Of KnownColor)(1000)) ' Result: 174
  12.  
  13.    Private Function Get_Nearest_Enum_Value(Of T)(ByVal value As Long) As T
  14.  
  15.        Return [Enum].Parse(GetType(T), [Enum].GetValues(GetType(T)).
  16.                                               Cast(Of Object).
  17.                                               OrderBy(Function(br) Math.Abs(value - br)).
  18.                                               First)
  19.  
  20.    End Function
  21.  
  22.    #End Region



Dado un número, devuelve el valor próximo más bajo de un Enum.

Código
  1.    #Region " Get Nearest Lower Enum Value "
  2.  
  3.       ' [ Get Nearest Lower Enum Value ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       '
  9.       ' Enum Bitrate As Short : kbps_128 = 128 : kbps_192 = 192 : kbps_256 = 256 : kbps_320 = 320 : End Enum
  10.       ' MsgBox(Get_Nearest_Lower_Enum_Value(Of Bitrate)(190).ToString) ' Result: kbps_128
  11.       ' MsgBox(Get_Nearest_Lower_Enum_Value(Of Bitrate)(196).ToString) ' Result: kbps_192
  12.  
  13.    Private Function Get_Nearest_Lower_Enum_Value(Of T)(ByVal value As Integer) As T
  14.  
  15.        Select Case value
  16.  
  17.            Case Is < [Enum].GetValues(GetType(T)).Cast(Of Object).First
  18.                Return Nothing
  19.  
  20.            Case Else
  21.                Return [Enum].Parse(GetType(T), [Enum].GetValues(GetType(T)).
  22.                                                       Cast(Of Object)().
  23.                                                       Where(Function(enum_value) enum_value <= value).
  24.                                                       Last)
  25.        End Select
  26.  
  27.    End Function
  28.  
  29.    #End Region




Dado un número, devuelve el valor próximo más alto de un Enum.

Código
  1.    #Region " Get Nearest Higher Enum Value "
  2.  
  3.       ' [ Get Nearest Higher Enum Value ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       '
  9.       ' Enum Bitrate As Short : kbps_128 = 128 : kbps_192 = 192 : kbps_256 = 256 : kbps_320 = 320 : End Enum
  10.       ' MsgBox(Get_Nearest_Higher_Enum_Value(Of Bitrate)(196).ToString) ' Result: kbps_256
  11.       ' MsgBox(Get_Nearest_Higher_Enum_Value(Of KnownColor)(1000)) ' Result: 0
  12.  
  13.    Private Function Get_Nearest_Higher_Enum_Value(Of T)(ByVal value As Integer) As T
  14.  
  15.        Select Case value
  16.  
  17.            Case Is > [Enum].GetValues(GetType(T)).Cast(Of Object).Last
  18.                Return Nothing
  19.  
  20.            Case Else
  21.  
  22.                Return [Enum].Parse(GetType(T), [Enum].GetValues(GetType(T)).
  23.                                                       Cast(Of Object).
  24.                                                       Where(Function(enum_value) enum_value >= value).
  25.                                                       FirstOrDefault)
  26.        End Select
  27.  
  28.    End Function
  29.  
  30.    #End Region

EDITO:

Aquí todos juntos:

Código
  1.    #Region " Get Nearest Enum Value "
  2.  
  3.        ' [ Get Nearest Enum Value ]
  4.        '
  5.        ' // By Elektro H@cker
  6.        '
  7.        ' Examples :
  8.        '
  9.        ' MsgBox(Get_Nearest_Enum_Value(Of Bitrate)(133, Enum_Direction.Nearest).ToString) ' Result: kbps_128
  10.        ' MsgBox(Get_Nearest_Enum_Value(Of KnownColor)(1000, Enum_Direction.Nearest)) ' Result: 174
  11.        '
  12.        ' MsgBox(Get_Nearest_Enum_Value(Of Bitrate)(190, Enum_Direction.Down).ToString) ' Result: kbps_128
  13.        ' MsgBox(Get_Nearest_Enum_Value(Of KnownColor)(-1, Enum_Direction.Down).ToString) ' Result: 0
  14.        '
  15.        ' MsgBox(Get_Nearest_Enum_Value(Of Bitrate)(196, Enum_Direction.Up).ToString) ' Result: kbps_256
  16.        ' MsgBox(Get_Nearest_Enum_Value(Of KnownColor)(1000, Enum_Direction.Up)) ' Result: 0
  17.  
  18.    Private Enum Enum_Direction As Short
  19.        Down = 1
  20.        Up = 2
  21.        Nearest = 0
  22.    End Enum
  23.  
  24.    Private Function Get_Nearest_Enum_Value(Of T)(ByVal value As Long, _
  25.                                                  Optional ByVal direction As Enum_Direction = Enum_Direction.Nearest) As T
  26.  
  27.        Select Case direction
  28.  
  29.            Case Enum_Direction.Nearest ' Return nearest Enum value
  30.                Return [Enum].Parse(GetType(T), [Enum].GetValues(GetType(T)).
  31.                                                       Cast(Of Object).
  32.                                                       OrderBy(Function(br) Math.Abs(value - br)).
  33.                                                       First)
  34.  
  35.            Case Enum_Direction.Down ' Return nearest lower Enum value
  36.                If value < [Enum].GetValues(GetType(T)).Cast(Of Object).First Then
  37.                    Return Nothing
  38.                Else
  39.                    Return [Enum].Parse(GetType(T), [Enum].GetValues(GetType(T)).
  40.                                                           Cast(Of Object)().
  41.                                                           Where(Function(enum_value) enum_value <= value).
  42.                                                           Last)
  43.                End If
  44.  
  45.            Case Enum_Direction.Up ' Return nearest higher Enum value
  46.                If value > [Enum].GetValues(GetType(T)).Cast(Of Object).Last Then
  47.                    Return Nothing
  48.                Else
  49.                    Return [Enum].Parse(GetType(T), [Enum].GetValues(GetType(T)).
  50.                                                           Cast(Of Object).
  51.                                                           Where(Function(enum_value) enum_value >= value).
  52.                                                           FirstOrDefault)
  53.                End If
  54.  
  55.        End Select
  56.  
  57.    End Function
  58.  
  59.    #End Region
8068  Programación / .NET (C#, VB.NET, ASP) / Re: Como eliminar resultados numericos en un variable o Array ? en: 29 Octubre 2013, 14:52 pm
Vamos Luis te lo he dado todo hecho, no es dificil adaptarlo, te falta poco.

En tu último código no has declarado el valor máximo
Citar
Código
  1. Dim maximum As Short = 99

Solo te falta eso y copiar esto otro:
Citar
Código
  1.        For Each Number As Integer In Result1
  2.  
  3.           TextBoxes(TextBoxCount).Text = _
  4.               If(Not Number > maximum, _
  5.                  CStr(Number), _
  6.                  CStr(maximum))
  7.  
  8.           Threading.Interlocked.Increment(TextBoxCount)
  9.  
  10.       Next Number

La verdad es que el búcle no requiere ningún cambio, pero puedes escribirlo de esta otra forma:

Código:
For Each Number As Int32 In Result1

    TextBoxCount += 1

    if not Number > maximum then
       TextBoxes(TextBoxCount).Text = cstr(number)
    else
       TextBoxes(TextBoxCount).Text = cstr(maximum)
     end if

 Next Number

Saludos
8069  Programación / Scripting / Re: Error en Bat en: 29 Octubre 2013, 12:07 pm
Los búcles procesan todos los valores que le has dado en su totalidad, por este orden:

Código:
a:1 b:20 c:100 d:1 e:40
a:1 b:20 c:100 d:1 e:50
a:1 b:20 c:100 d:2 e:40
a:1 b:20 c:100 d:2 e:50
a:1 b:20 c:200 d:1 e:40
a:1 b:20 c:200 d:1 e:50
a:1 b:20 c:200 d:2 e:40
a:1 b:20 c:200 d:2 e:50
a:1 b:30 c:100 d:1 e:40
a:1 b:30 c:100 d:1 e:50
a:1 b:30 c:100 d:2 e:40
a:1 b:30 c:100 d:2 e:50
a:1 b:30 c:200 d:1 e:40
a:1 b:30 c:200 d:1 e:50
a:1 b:30 c:200 d:2 e:40
a:1 b:30 c:200 d:2 e:50
a:2 b:20 c:100 d:1 e:40
a:2 b:20 c:100 d:1 e:50
a:2 b:20 c:100 d:2 e:40
a:2 b:20 c:100 d:2 e:50
a:2 b:20 c:200 d:1 e:40
a:2 b:20 c:200 d:1 e:50
a:2 b:20 c:200 d:2 e:40
a:2 b:20 c:200 d:2 e:50
a:2 b:30 c:100 d:1 e:40
a:2 b:30 c:100 d:1 e:50
a:2 b:30 c:100 d:2 e:40
a:2 b:30 c:100 d:2 e:50
a:2 b:30 c:200 d:1 e:40
a:2 b:30 c:200 d:1 e:50
a:2 b:30 c:200 d:2 e:40
a:2 b:30 c:200 d:2 e:50

¿Que intentas hacer?, ¿Cual debería ser el resultado esperado?.

Saludos!
8070  Sistemas Operativos / Windows / Re: Problema con asosiacion de archivos en Win 7 en: 29 Octubre 2013, 12:01 pm
Hola, ¿debemos adivinar de que reproductor hablas?.

En el valor por defecto de la clave:
Código:
HKEY_CLASSES_ROOT\.dll
...Encontrarás la asociación.

Ejemplo:

Código:
HKEY_CLASSES_ROOT\.dll "default value=mediaplayer.dll"

Código:
HKEY_CLASSES_ROOT\mediaplayer.dll

Si no se encuentra ahí, entonces está en la clave SystemFileAssociations:

Código:
HKCR\SystemFileAssociations\.dll
HKLM\SystemFileAssociations\.dll

Saludos.
Páginas: 1 ... 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 [807] 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines