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


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


  Mostrar Mensajes
Páginas: 1 ... 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 [534] 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 ... 1254
5331  Programación / .NET (C#, VB.NET, ASP) / Re: Leer una clase en un formulario Windows de Visual C# en: 10 Junio 2015, 20:25 pm
he intentado traducirloa C# y me dice:

El motor/librería NRefactory que utilizan practicamente todos los traductores, es bastante estricto con los saltos de linea en ciertas partes, los cuales si que están permitidos en la IDE.

Debes escribir el bracket despues del keyword From.

Es decir, de esto:
Citar
Código
  1.        Private ReadOnly countryDict As New Dictionary(Of Integer, String) From
  2.            {
  3.                {0, "Japan"},
  4.                {1, "United States"},
  5.                {2, "Unknown"},
  6.                {3, "Unknown"},
  7.                {4, "Unknown"},
  8.                {5, "Unknown"},
  9.                {6, "Unknown"},
  10.                {7, "Unknown"},
  11.                {8, "Spain"},
  12.                {9, "Unknown"},
  13.                {10, "Unknown"},
  14.                {11, "Unknown"},
  15.                {12, "Unknown"},
  16.                {13, "Unknown"}
  17.            }

A esto otro:
Código
  1.        Private ReadOnly countryDict As New Dictionary(Of Integer, String) From {
  2.                {0, "Japan"},
  3.                {1, "United States"},
  4.                {2, "Unknown"},
  5.                {3, "Unknown"},
  6.                {4, "Unknown"},
  7.                {5, "Unknown"},
  8.                {6, "Unknown"},
  9.                {7, "Unknown"},
  10.                {8, "Spain"},
  11.                {9, "Unknown"},
  12.                {10, "Unknown"},
  13.                {11, "Unknown"},
  14.                {12, "Unknown"},
  15.                {13, "Unknown"}
  16.            }



Muy pero que muy, muy, muy y muy buen trabajo.

Gracias. Alguien debería donarme unos eurillos a mi paypal :silbar:.

Saludos!
5332  Programación / .NET (C#, VB.NET, ASP) / Re: Leer una clase en un formulario Windows de Visual C# en: 10 Junio 2015, 19:45 pm
Te voy a hacer un regalito :P ...es cosa tuya traducirlo a C#, o compilar el código en una dll para no tener que traducir.

La SNES siempre me ha fascinado, bueno, tengo cierta melancolía y bastantes roms por ahí perdidas xD, en fin, me ha interesado el tema, he cogido la Class que publicaste al principio del tema, y la he extendido para mejorarla en varios aspectos, añadiendo mayor y mejor documentación, así cómo nuevas funcionalidades.



Cosas a tener en cuenta:

1. Me ha sido imposible descifrar los 13 códigos de paises que se pueden usar en una ROM de SNES, no encuentro información sobre esto en ningún lugar, solo encontré información parcial en la que se dice que '0' equivale a Japón, '1' a U.S., y bajo mis propias conclusiones '8' debe ser España.
Si alguien conoce esta información al completo, que me lo haga saber, gracias.

2. No he testeado mi Class con cientos de ROMs para comprobar que todo funciona cómo debería funcionar a las mil maravillas en todas las circunstancias posibles, pero supongo que si, ya que me he basado en las especificaciones de la cabecera de SNES, las cuales ya estaban implementados en la Class original de donde saqué la idea.
Si alguien encuentra algún error, que me lo comunique, gracias.



A continuación publico el código fuente, y abajo del todo unos ejemplos de lectura y escritura:

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro.
  3. '            Based on this 3rd party project:
  4. '            https://github.com/Zeokat/SNES-ROM-Header-Dumper-CSharp/blob/master/snes_dumper.cs
  5. ' Modified : 10-June-2015
  6. ' ***********************************************************************
  7. ' <copyright file="SnesRom.vb" company="Elektro Studios">
  8. '     Copyright (c) Elektro Studios. All rights reserved.
  9. ' </copyright>
  10. ' ***********************************************************************
  11.  
  12. #Region " Usage Examples "
  13.  
  14. ' CONTENIDO OMITIDO...
  15.  
  16. #End Region
  17.  
  18. #Region " Option Statements "
  19.  
  20. Option Strict On
  21. Option Explicit On
  22. Option Infer Off
  23.  
  24. #End Region
  25.  
  26. #Region " Imports "
  27.  
  28. Imports System.IO
  29. Imports System.Text
  30.  
  31. #End Region
  32.  
  33. Public NotInheritable Class SnesRom
  34.  
  35. #Region " Properties "
  36.  
  37.    ''' <summary>
  38.    ''' Gets the raw byte-data of the ROM file.
  39.    ''' </summary>
  40.    ''' <value>The raw byte-data of the ROM file.</value>
  41.    Public ReadOnly Property RawData As Byte()
  42.        Get
  43.            Return Me.rawDataB
  44.        End Get
  45.    End Property
  46.    ''' <summary>
  47.    ''' (backing field) The raw byte-data of the ROM file.
  48.    ''' </summary>
  49.    Private ReadOnly rawDataB As Byte()
  50.  
  51.    ''' <summary>
  52.    ''' Gets The ROM header type.
  53.    ''' </summary>
  54.    ''' <remarks>http://romhack.wikia.com/wiki/SMC_header</remarks>
  55.    ''' <value>The ROM header type.</value>
  56.    Public ReadOnly Property HeaderType As HeaderTypeEnum
  57.        Get
  58.            Return Me.headerTypeB
  59.        End Get
  60.    End Property
  61.    ''' <summary>
  62.    ''' (backing field) The ROM header type.
  63.    ''' </summary>
  64.    Private headerTypeB As HeaderTypeEnum
  65.  
  66.    ''' <summary>
  67.    ''' Gets the SNES header address location.
  68.    ''' </summary>
  69.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  70.    ''' <value>The SNES header address location.</value>
  71.    Private ReadOnly Property HeaderLocation As Integer
  72.        Get
  73.            Return Me.headerLocationB
  74.        End Get
  75.    End Property
  76.    ''' <summary>
  77.    ''' (backing field) The SNES header address location.
  78.    ''' </summary>
  79.    Private headerLocationB As Integer = 33216
  80.  
  81.    ''' <summary>
  82.    ''' Gets or sets the name of the ROM, typically in ASCII.
  83.    ''' The name buffer consists in 21 characters.
  84.    ''' </summary>
  85.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  86.    ''' <value>The name of the ROM.</value>
  87.    Public Property Name As String
  88.        Get
  89.            Return Me.nameB
  90.        End Get
  91.        Set(ByVal value As String)
  92.            Me.SetName(value)
  93.            Me.nameB = value
  94.        End Set
  95.    End Property
  96.    ''' <summary>
  97.    ''' (backing field) The name of the ROM.
  98.    ''' </summary>
  99.    Private nameB As String
  100.  
  101.    ''' <summary>
  102.    ''' Gets the ROM layout.
  103.    ''' The SNES ROM layout describes how the ROM banks appear in a ROM image and in the SNES address space.
  104.    ''' </summary>
  105.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  106.    ''' <value>The ROM layout.</value>
  107.    Public ReadOnly Property Layout As Byte
  108.        Get
  109.            Return Me.layoutB
  110.        End Get
  111.    End Property
  112.    ''' <summary>
  113.    ''' (backing field) The ROM layout.
  114.    ''' </summary>
  115.    Private layoutB As Byte
  116.  
  117.    ''' <summary>
  118.    ''' Gets the bank type.
  119.    ''' An image contains only LoROM banks or only HiROM banks, not both.
  120.    ''' </summary>
  121.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  122.    ''' <value>The bank type.</value>
  123.    Public ReadOnly Property BankType As BankTypeEnum
  124.        Get
  125.            Return Me.bankTypeB
  126.        End Get
  127.    End Property
  128.    ''' <summary>
  129.    ''' (backing field) The bank type.
  130.    ''' </summary>
  131.    Private bankTypeB As BankTypeEnum
  132.  
  133.    ''' <summary>
  134.    ''' Gets the cartrifge type, it can be a ROM only, or a ROM with save-RAM.
  135.    ''' </summary>
  136.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  137.    ''' <value>The cartridge type.</value>
  138.    Public ReadOnly Property CartridgeType As CartridgeTypeEnum
  139.        Get
  140.            Return Me.cartridgeTypeB
  141.        End Get
  142.    End Property
  143.    ''' <summary>
  144.    ''' (backing field) The cartrifge type.
  145.    ''' </summary>
  146.    Private cartridgeTypeB As CartridgeTypeEnum
  147.  
  148.    ''' <summary>
  149.    ''' Gets the ROM size byte.
  150.    ''' </summary>
  151.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  152.    ''' <value>The ROM size byte.</value>
  153.    Public ReadOnly Property RomSize As Byte
  154.        Get
  155.            Return Me.romSizeB
  156.        End Get
  157.    End Property
  158.    ''' <summary>
  159.    ''' (backing field) The ROM size byte.
  160.    ''' </summary>
  161.    Private romSizeB As Byte
  162.  
  163.    ''' <summary>
  164.    ''' Gets the RAM size byte.
  165.    ''' </summary>
  166.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  167.    ''' <value>The RAM size byte.</value>
  168.    Public ReadOnly Property RamSize As Byte
  169.        Get
  170.            Return Me.ramSizeB
  171.        End Get
  172.    End Property
  173.    ''' <summary>
  174.    ''' (backing field) The ROM size byte.
  175.    ''' </summary>
  176.    Private ramSizeB As Byte
  177.  
  178.    ''' <summary>
  179.    ''' Gets or sets the country data.
  180.    ''' </summary>
  181.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  182.    ''' <value>The country data.</value>
  183.    Public Property Country As CountryData
  184.        Get
  185.            Return New CountryData(Me.CountryCode)
  186.        End Get
  187.        Set(ByVal value As CountryData)
  188.            Me.SetByte(Me.startAddressCountryCode, value.Code)
  189.            Me.CountryCode = value.Code
  190.        End Set
  191.    End Property
  192.  
  193.    ''' <summary>
  194.    ''' The country code.
  195.    ''' </summary>
  196.    Private Property CountryCode As Byte
  197.  
  198.    ''' <summary>
  199.    ''' Gets or sets the license code.
  200.    ''' </summary>
  201.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  202.    ''' <value>The license code.</value>
  203.    Public Property LicenseCode As Byte
  204.        Get
  205.            Return Me.licenseCodeB
  206.        End Get
  207.        Set(ByVal value As Byte)
  208.            Me.SetByte(Me.startAddressLicenseCode, value)
  209.            Me.licenseCodeB = value
  210.        End Set
  211.    End Property
  212.    ''' <summary>
  213.    ''' (backing field) The license code.
  214.    ''' </summary>
  215.    Private licenseCodeB As Byte
  216.  
  217.    ''' <summary>
  218.    ''' Gets or sets the version number.
  219.    ''' </summary>
  220.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  221.    ''' <value>The version number.</value>
  222.    Public Property VersionNumber As Byte
  223.        Get
  224.            Return Me.versionNumberB
  225.        End Get
  226.        Set(ByVal value As Byte)
  227.            Me.SetByte(Me.startAddressVersionNumber, value)
  228.            Me.versionNumberB = value
  229.        End Set
  230.    End Property
  231.    ''' <summary>
  232.    ''' (backing field) The version number.
  233.    ''' </summary>
  234.    Private versionNumberB As Byte
  235.  
  236.    ''' <summary>
  237.    ''' Gets the checksum compliment.
  238.    ''' </summary>
  239.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  240.    ''' <value>The checksum compliment.</value>
  241.    Public ReadOnly Property ChecksumCompliment As UShort
  242.        Get
  243.            Return Me.checksumComplimentB
  244.        End Get
  245.    End Property
  246.    ''' <summary>
  247.    ''' (backing field) The checksum compliment.
  248.    ''' </summary>
  249.    Private checksumComplimentB As UShort
  250.  
  251.    ''' <summary>
  252.    ''' Gets the checksum.
  253.    ''' </summary>
  254.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  255.    ''' <value>The checksum.</value>
  256.    Public ReadOnly Property Checksum As UShort
  257.        Get
  258.            Return Me.checksumB
  259.        End Get
  260.    End Property
  261.    ''' <summary>
  262.    ''' (backing field) The checksum.
  263.    ''' </summary>
  264.    Private checksumB As UShort
  265.  
  266. #End Region
  267.  
  268. #Region " Header Addresses "
  269.  
  270.    ' ********************************************************************************************************************
  271.    ' NOTE:
  272.    ' The reason for the variables that are commented-out is just because are unused, but could be helpful in the future.
  273.    ' ********************************************************************************************************************
  274.  
  275.    ' ''' <summary>
  276.    ' ''' The start address of a Lo-ROM header.
  277.    ' ''' </summary>
  278.    'Private ReadOnly loRomHeaderAddress As UShort = 32704
  279.  
  280.    ' ''' <summary>
  281.    ' ''' The start address of a Hi-ROM header.
  282.    ' ''' </summary>
  283.    'Private ReadOnly hiRomHeaderAddress As UShort = 65472
  284.  
  285.    ''' <summary>
  286.    ''' The start address of the ROM name.
  287.    ''' </summary>
  288.    Private ReadOnly startAddressName As Integer = 0
  289.  
  290.    ''' <summary>
  291.    ''' The end address of the ROM name.
  292.    ''' </summary>
  293.    Private ReadOnly endAddressName As Integer = 20
  294.  
  295.    ''' <summary>
  296.    ''' The start address of the ROM layout.
  297.    ''' </summary>
  298.    Private ReadOnly startAddressLayout As Integer = 21
  299.  
  300.    ' ''' <summary>
  301.    ' ''' The end address of the ROM layout.
  302.    ' ''' </summary>
  303.    'Private ReadOnly endAddressLayout As Integer = 21
  304.  
  305.    ''' <summary>
  306.    ''' The start address of the ROM cartridge type.
  307.    ''' </summary>
  308.    Private ReadOnly startAddressCartridgeType As Integer = 22
  309.  
  310.    ' ''' <summary>
  311.    ' ''' The end address of the ROM cartridge type.
  312.    ' ''' </summary>
  313.    'Private ReadOnly endAddressCartridgeType As Integer = 22
  314.  
  315.    ''' <summary>
  316.    ''' The start address of the ROM size (rom).
  317.    ''' </summary>
  318.    Private ReadOnly startAddressRomSize As Integer = 23
  319.  
  320.    ' ''' <summary>
  321.    ' ''' The end address of the ROM size (rom).
  322.    ' ''' </summary>
  323.    'Private ReadOnly endAddressRomSize As Integer = 23
  324.  
  325.    ''' <summary>
  326.    ''' The start address of the ROM size (ram).
  327.    ''' </summary>
  328.    Private ReadOnly startAddressRamSize As Integer = 24
  329.  
  330.    ' ''' <summary>
  331.    ' ''' The end address of the ROM size (ram).
  332.    ' ''' </summary>
  333.    'Private ReadOnly endAddressRamSize As Integer = 24
  334.  
  335.    ''' <summary>
  336.    ''' The start address of the ROM country code.
  337.    ''' </summary>
  338.    Private ReadOnly startAddressCountryCode As Integer = 25
  339.  
  340.    ' ''' <summary>
  341.    ' ''' The end address of the ROM country code.
  342.    ' ''' </summary>
  343.    'Private ReadOnly endAddressCountryCode As Integer = 25
  344.  
  345.    ''' <summary>
  346.    ''' The start address of the ROM license code.
  347.    ''' </summary>
  348.    Private ReadOnly startAddressLicenseCode As Integer = 26
  349.  
  350.    ' ''' <summary>
  351.    ' ''' The end address of the ROM license code.
  352.    ' ''' </summary>
  353.    'Private ReadOnly endAddressLicenseCode As Integer = 26
  354.  
  355.    ''' <summary>
  356.    ''' The start address of the ROM Version Number.
  357.    ''' </summary>
  358.    Private ReadOnly startAddressVersionNumber As Integer = 27
  359.  
  360.    ' ''' <summary>
  361.    ' ''' The end address of the ROM Version Number.
  362.    ' ''' </summary>
  363.    'Private ReadOnly endAddresVersionNumber As Integer = 27
  364.  
  365.    ''' <summary>
  366.    ''' The start address of the ROM checksum compliment.
  367.    ''' </summary>
  368.    Private ReadOnly startAddressChecksumCompliment As Integer = 28
  369.  
  370.    ''' <summary>
  371.    ''' The end address of the ROM checksum compliment.
  372.    ''' </summary>
  373.    Private ReadOnly endAddressChecksumCompliment As Integer = 29
  374.  
  375.    ''' <summary>
  376.    ''' The start address of the ROM checksum.
  377.    ''' </summary>
  378.    Private ReadOnly startAddressChecksum As Integer = 30
  379.  
  380.    ''' <summary>
  381.    ''' The end address of the ROM checksum.
  382.    ''' </summary>
  383.    Private ReadOnly endAddressChecksum As Integer = 31
  384.  
  385. #End Region
  386.  
  387. #Region " Enumerations "
  388.  
  389.    ''' <summary>
  390.    ''' Specifies a SNES ROM header type.
  391.    ''' A headered ROM has SMC header and SNES header.
  392.    ''' A headerless ROM has no SMC header, but still contains a SNES header.
  393.    ''' Note that both a LoRom and HiRom images can be headered, or headerless.
  394.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  395.    ''' </summary>
  396.    Public Enum HeaderTypeEnum As Integer
  397.  
  398.        ''' <summary>
  399.        ''' A headered SNES ROM.
  400.        ''' The ROM contains an SMC header, and also contains an SNES header.
  401.        ''' </summary>
  402.        Headered = 0
  403.  
  404.        ''' <summary>
  405.        ''' A headerless SNES ROM.
  406.        ''' The ROM does not contains an SMC header, but contains an SNES header.
  407.        ''' </summary>
  408.        Headerless = 1
  409.  
  410.    End Enum
  411.  
  412.    ''' <summary>
  413.    ''' Specifies a SNES ROM bank type.
  414.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  415.    ''' </summary>
  416.    Public Enum BankTypeEnum As UShort
  417.  
  418.        ''' <summary>
  419.        ''' A LoROM maps each ROM bank into the upper half (being addresses $8000 to $ffff) of each SNES bank,
  420.        ''' starting with SNES bank $00, and starting again with SNES bank $80.
  421.        ''' </summary>
  422.        LoRom = 32704US
  423.  
  424.        ''' <summary>
  425.        ''' A HiROM maps each ROM bank into the whole (being addresses $0000 to $ffff) of each SNES bank,
  426.        ''' starting with SNES bank $40, and starting again with SNES bank $80.
  427.        ''' </summary>
  428.        HiRom = 65472US
  429.  
  430.    End Enum
  431.  
  432.    ''' <summary>
  433.    ''' Specifies a SNES ROM cartridge type.
  434.    ''' <remarks>http://romhack.wikia.com/wiki/SNES_ROM_layout</remarks>
  435.    ''' </summary>
  436.    Public Enum CartridgeTypeEnum As Byte
  437.  
  438.        ''' <summary>
  439.        ''' A ROM without save-RAM.
  440.        ''' </summary>
  441.        NoSram0 = 0
  442.  
  443.        ''' <summary>
  444.        ''' A ROM without save-RAM.
  445.        ''' <remarks>I didn't fully verified this value...</remarks>
  446.        ''' </summary>
  447.        NoSram1 = 1
  448.  
  449.        ''' <summary>
  450.        ''' A ROM with save-RAM.
  451.        ''' </summary>
  452.        Sram = 2
  453.  
  454.    End Enum
  455.  
  456. #End Region
  457.  
  458. #Region " Exceptions "
  459.  
  460.    ''' <summary>
  461.    ''' Exception that is thrown when a SNES ROM has an invalid format.
  462.    ''' </summary>
  463.    <Serializable>
  464.    Public NotInheritable Class InvalidRomFormatException : Inherits Exception
  465.  
  466.        ''' <summary>
  467.        ''' Initializes a new instance of the <see cref="InvalidROMFormatException"/> class.
  468.        ''' </summary>
  469.        Public Sub New()
  470.            MyBase.New("The SNES ROM image has an invalid format.")
  471.        End Sub
  472.  
  473.        ''' <summary>
  474.        ''' Initializes a new instance of the <see cref="InvalidROMFormatException"/> class.
  475.        ''' </summary>
  476.        ''' <param name="message">The message that describes the error.</param>
  477.        Public Sub New(ByVal message As String)
  478.            MyBase.New(message)
  479.        End Sub
  480.  
  481.        ''' <summary>
  482.        ''' Initializes a new instance of the <see cref="InvalidROMFormatException"/> class.
  483.        ''' </summary>
  484.        ''' <param name="message">The message that describes the error.</param>
  485.        ''' <param name="inner">The inner exception.</param>
  486.        Public Sub New(ByVal message As String, ByVal inner As Exception)
  487.            MyBase.New(message, inner)
  488.        End Sub
  489.  
  490.    End Class
  491.  
  492. #End Region
  493.  
  494. #Region " Types "
  495.  
  496.    ''' <summary>
  497.    ''' Defines a SNES ROM country.
  498.    ''' </summary>
  499.    <Serializable>
  500.    Public NotInheritable Class CountryData
  501.  
  502. #Region " Properties "
  503.  
  504.        ''' <summary>
  505.        ''' Gets the region, which can de PAL or NTSC.
  506.        ''' </summary>
  507.        ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  508.        ''' <value>The country code.</value>
  509.        Public ReadOnly Property Region As RegionTypeEnum
  510.            Get
  511.                Return Me.regionB
  512.            End Get
  513.        End Property
  514.        ''' <summary>
  515.        ''' (backing field) The region, which can de PAL or NTSC.
  516.        ''' </summary>
  517.        Private ReadOnly regionB As RegionTypeEnum
  518.  
  519.        ''' <summary>
  520.        ''' Gets the country code.
  521.        ''' </summary>
  522.        ''' <value>The country code.</value>
  523.        Public ReadOnly Property Code As Byte
  524.            Get
  525.                Return Me.codeB
  526.            End Get
  527.        End Property
  528.        ''' <summary>
  529.        ''' (backing field) The country code.
  530.        ''' </summary>
  531.        Private ReadOnly codeB As Byte
  532.  
  533.        ''' <summary>
  534.        ''' Gets the country name.
  535.        ''' </summary>
  536.        ''' <value>The country name.</value>
  537.        Public ReadOnly Property Name As String
  538.            Get
  539.                Return Me.nameB
  540.            End Get
  541.        End Property
  542.        ''' <summary>
  543.        ''' (backing field) The country name.
  544.        ''' </summary>
  545.        Private ReadOnly nameB As String
  546.  
  547. #End Region
  548.  
  549. #Region " Enumerations "
  550.  
  551.        ''' <summary>
  552.        ''' Specifies a SNES ROM region type.
  553.        ''' <remarks>http://romhack.wikia.com/wiki/SNES_header</remarks>
  554.        ''' </summary>
  555.        Public Enum RegionTypeEnum As Integer
  556.  
  557.            ''' <summary>
  558.            ''' A PAL SNES ROM.
  559.            ''' </summary>
  560.            Pal = 0
  561.  
  562.            ''' <summary>
  563.            ''' An NTSC SNES ROM.
  564.            ''' </summary>
  565.            Ntsc = 1
  566.  
  567.        End Enum
  568.  
  569. #End Region
  570.  
  571. #Region " Countries "
  572.  
  573.        ''' <summary>
  574.        ''' The known ROM countries, based on country code from 0 to 13, so countrycode 0 = Japan, countrycode 1 = United States, and so on...
  575.        ''' Unknown country codes are just unknown.
  576.        ''' </summary>
  577.        Private ReadOnly countryDict As New Dictionary(Of Integer, String) From
  578.            {
  579.                {0, "Japan"},
  580.                {1, "United States"},
  581.                {2, "Unknown"},
  582.                {3, "Unknown"},
  583.                {4, "Unknown"},
  584.                {5, "Unknown"},
  585.                {6, "Unknown"},
  586.                {7, "Unknown"},
  587.                {8, "Spain"},
  588.                {9, "Unknown"},
  589.                {10, "Unknown"},
  590.                {11, "Unknown"},
  591.                {12, "Unknown"},
  592.                {13, "Unknown"}
  593.            }
  594.  
  595. #End Region
  596.  
  597. #Region " Regions "
  598.  
  599.        ''' <summary>
  600.        ''' The country codes for NTSC region.
  601.        ''' <remarks>http://romhack.wikia.com/wiki/SMC_header</remarks>
  602.        ''' </summary>
  603.        Private ReadOnly ntscRegionCodes As Integer() =
  604.            {0, 1, 13}
  605.  
  606.        ''' <summary>
  607.        ''' The country codes for PAL region.
  608.        ''' <remarks>http://romhack.wikia.com/wiki/SMC_header</remarks>
  609.        ''' </summary>
  610.        Private ReadOnly palRegionCodes As Integer() =
  611.            {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
  612.  
  613. #End Region
  614.  
  615. #Region " Constructors "
  616.  
  617.        ''' <summary>
  618.        ''' Initializes a new instance of the <see cref="CountryData"/> class.
  619.        ''' </summary>
  620.        ''' <param name="countryCode">The SNES ROM country code.</param>
  621.        ''' <exception cref="ArgumentException">Invalid country code.;countryCode</exception>
  622.        Public Sub New(ByVal countryCode As Byte)
  623.  
  624.            If Not (Me.ntscRegionCodes.Concat(Me.palRegionCodes)).Contains(countryCode) Then
  625.                Throw New ArgumentException(message:="Invalid country code.", paramName:="countryCode")
  626.  
  627.            Else
  628.                Me.codeB = countryCode
  629.                Me.nameB = Me.countryDict(countryCode)
  630.  
  631.                ' Determine region.
  632.                If Me.ntscRegionCodes.Contains(countryCode) Then
  633.                    Me.regionB = RegionTypeEnum.Ntsc
  634.  
  635.                ElseIf Me.palRegionCodes.Contains(countryCode) Then
  636.                    Me.regionB = RegionTypeEnum.Pal
  637.  
  638.                End If
  639.  
  640.            End If
  641.  
  642.        End Sub
  643.  
  644.        ''' <summary>
  645.        ''' Prevents a default instance of the <see cref="CountryData"/> class from being created.
  646.        ''' </summary>
  647.        Private Sub New()
  648.        End Sub
  649.  
  650. #End Region
  651.  
  652.    End Class
  653.  
  654. #End Region
  655.  
  656. #Region " Constructors "
  657.  
  658.    ''' <summary>
  659.    ''' Prevents a default instance of the <see cref="SnesRom"/> class from being created.
  660.    ''' </summary>
  661.    Private Sub New()
  662.    End Sub
  663.  
  664.    ''' <summary>
  665.    ''' Initializes a new instance of the <see cref="SnesRom"/> class.
  666.    ''' </summary>
  667.    ''' <param name="romFilePath">The SNES ROM file path.</param>
  668.    Public Sub New(ByVal romFilePath As String)
  669.  
  670.        Me.New(File.ReadAllBytes(romFilePath))
  671.  
  672.    End Sub
  673.  
  674.    ''' <summary>
  675.    ''' Initializes a new instance of the <see cref="SnesRom"/> class.
  676.    ''' </summary>
  677.    ''' <param name="romData">The raw byte-data of the ROM file.</param>
  678.    Public Sub New(ByVal romData As Byte())
  679.  
  680.        Me.rawDataB = romData
  681.  
  682.        Me.VerifyRomFormat()
  683.        Me.VerifyBankType()
  684.        Me.ReadHeader()
  685.  
  686.    End Sub
  687.  
  688. #End Region
  689.  
  690. #Region " Private Methods "
  691.  
  692.    ''' <summary>
  693.    ''' Reads the ROM header to retrieve the header data.
  694.    ''' </summary>
  695.    Private Sub ReadHeader()
  696.  
  697.        ' Read range of bytes.
  698.        Me.nameB = Encoding.ASCII.GetString(Me.GetBytes(Me.startAddressName, Me.endAddressName)).Trim
  699.  
  700.        ' Read single bytes.
  701.        Me.layoutB = Me.GetByte(Me.startAddressLayout)
  702.        Me.cartridgeTypeB = DirectCast(Me.GetByte(Me.startAddressCartridgeType), CartridgeTypeEnum)
  703.        Me.romSizeB = Me.GetByte(Me.startAddressRomSize)
  704.        Me.ramSizeB = Me.GetByte(Me.startAddressRamSize)
  705.        Me.CountryCode = Me.GetByte(Me.startAddressCountryCode)
  706.        Me.LicenseCode = Me.GetByte(Me.startAddressLicenseCode)
  707.        Me.VersionNumber = Me.GetByte(Me.startAddressVersionNumber)
  708.  
  709.    End Sub
  710.  
  711.    ''' <summary>
  712.    ''' Verifies the SNES ROM format.
  713.    ''' </summary>
  714.    ''' <exception cref="SnesRom.InvalidRomFormatException">The SNES ROM image has an invalid format.</exception>
  715.    Private Sub VerifyRomFormat()
  716.  
  717.        If (Me.rawDataB.Length Mod 1024 = 512) Then
  718.            Me.headerTypeB = HeaderTypeEnum.Headered
  719.  
  720.        ElseIf (Me.rawDataB.Length Mod 1024 = 0) Then
  721.            Me.headerTypeB = HeaderTypeEnum.Headerless
  722.  
  723.        Else
  724.            Throw New InvalidRomFormatException(message:="The SNES ROM image has an invalid format.")
  725.  
  726.        End If
  727.  
  728.    End Sub
  729.  
  730.    ''' <summary>
  731.    ''' Verifies the SNES ROM bank type.
  732.    ''' </summary>
  733.    ''' <exception cref="Exception">Cannot recognize the bank type.</exception>
  734.    Private Sub VerifyBankType()
  735.  
  736.        If Me.HeaderIsAt(BankTypeEnum.LoRom) Then
  737.            Me.bankTypeB = BankTypeEnum.LoRom
  738.  
  739.        ElseIf Me.HeaderIsAt(BankTypeEnum.HiRom) Then
  740.            Me.bankTypeB = BankTypeEnum.HiRom
  741.  
  742.        Else
  743.            Throw New Exception(message:="Cannot recognize the bank type.")
  744.  
  745.        End If
  746.  
  747.    End Sub
  748.  
  749.    ''' <summary>
  750.    ''' Verifies the checksum.
  751.    ''' </summary>
  752.    ''' <remarks>
  753.    ''' Offset 0x07FC0 in a headerless LoROM image (LoROM rom sin smc header)
  754.    ''' Offset 0x0FFC0 in a headerless HiROM image (HiROM rom sin smc header)
  755.    ''' </remarks>
  756.    ''' <returns><c>true</c> if checksum is ok, <c>false</c> otherwise.</returns>
  757.    Private Function VerifyChecksum() As Boolean
  758.  
  759.        If Me.HeaderType = HeaderTypeEnum.Headered Then
  760.            Me.headerLocationB += 512
  761.        End If
  762.  
  763.        Me.checksumComplimentB = BitConverter.ToUInt16(Me.GetBytes(Me.startAddressChecksumCompliment, Me.endAddressChecksumCompliment), startIndex:=0)
  764.  
  765.        Me.checksumB = BitConverter.ToUInt16(Me.GetBytes(Me.startAddressChecksum, Me.endAddressChecksum), startIndex:=0)
  766.  
  767.        Return CUShort(Me.Checksum Xor Me.ChecksumCompliment).Equals(UShort.MaxValue)
  768.  
  769.    End Function
  770.  
  771.    ''' <summary>
  772.    ''' Determines whether the ROM header is in the specified address.
  773.    ''' </summary>
  774.    ''' <param name="address">The address.</param>
  775.    ''' <returns><c>true</c> if the ROM header is in the specified address, <c>false</c> otherwise.</returns>
  776.    Private Function HeaderIsAt(ByVal address As UShort) As Boolean
  777.  
  778.        Me.headerLocationB = address
  779.        Return Me.VerifyChecksum()
  780.  
  781.    End Function
  782.  
  783.    ''' <summary>
  784.    ''' Gets the specified byte from the raw byte-data.
  785.    ''' </summary>
  786.    ''' <param name="address">The address.</param>
  787.    ''' <returns>The specified byte from the raw byte-data.</returns>
  788.    Private Function GetByte(ByVal address As Integer) As Byte
  789.  
  790.        Return Buffer.GetByte(array:=Me.RawData,
  791.                              index:=Me.HeaderLocation + address)
  792.  
  793.    End Function
  794.  
  795.    ''' <summary>
  796.    ''' Gets the specified range of bytes from the raw byte-data.
  797.    ''' </summary>
  798.    ''' <param name="from">From address.</param>
  799.    ''' <param name="to">To address.</param>
  800.    ''' <returns>The specified bytes from the raw byte-data.</returns>
  801.    Private Function GetBytes(ByVal from As Integer,
  802.                              ByVal [to] As Integer) As Byte()
  803.  
  804.        Return Me.RawData.Skip(Me.HeaderLocation + from).Take(([to] - from) + 1).ToArray()
  805.  
  806.    End Function
  807.  
  808.    ''' <summary>
  809.    ''' Replaces a single byte in the raw byte-data, with the specified data.
  810.    ''' </summary>
  811.    ''' <param name="address">the address.</param>
  812.    ''' <param name="data">The byte-data.</param>
  813.    Private Sub SetByte(ByVal address As Integer,
  814.                       ByVal data As Byte)
  815.  
  816.        Buffer.SetByte(array:=Me.rawDataB,
  817.                       index:=Me.HeaderLocation + address,
  818.                       value:=data)
  819.  
  820.    End Sub
  821.  
  822.    ''' <summary>
  823.    ''' Replaces the specified range of bytes in the raw byte-data, with the specified data.
  824.    ''' </summary>
  825.    ''' <param name="from">From address.</param>
  826.    ''' <param name="to">To address.</param>
  827.    ''' <param name="data">The byte-data.</param>
  828.    ''' <exception cref="ArgumentException">The byte-length of the specified data differs from the byte-length to be replaced;data</exception>
  829.    Private Sub SetBytes(ByVal from As Integer,
  830.                        ByVal [to] As Integer,
  831.                        ByVal data As Byte())
  832.  
  833.        If data.Length <> (([to] - from) + 1) Then
  834.            Throw New ArgumentException("The byte-length of the specified data differs from the byte-length to be replaced.", "data")
  835.  
  836.        Else
  837.            Buffer.BlockCopy(src:=data, srcOffset:=0,
  838.                             dst:=Me.rawDataB, dstOffset:=Me.HeaderLocation + from,
  839.                             count:=([to] - from) + 1)
  840.  
  841.        End If
  842.  
  843.    End Sub
  844.  
  845.    ''' <summary>
  846.    ''' Sets the ROM name.
  847.    ''' </summary>
  848.    ''' <param name="name">The ROM name.</param>
  849.    ''' <exception cref="ArgumentNullException">name</exception>
  850.    ''' <exception cref="ArgumentException">The name should contain 21 or less characters;name.</exception>
  851.    Private Sub SetName(ByVal name As String)
  852.  
  853.        Dim fixedNameLength As Integer = (Me.endAddressName - Me.startAddressName) + 1
  854.  
  855.        If String.IsNullOrEmpty(name) Then
  856.            Throw New ArgumentNullException(paramName:="name")
  857.  
  858.        ElseIf (name.Length > fixedNameLength) Then
  859.            Throw New ArgumentException(message:="The name should contain 21 or less characters.", paramName:="name")
  860.  
  861.        Else
  862.            ' fill with spaces up to 21 character length.
  863.            name = name.PadRight(totalWidth:=fixedNameLength, paddingChar:=" "c)
  864.  
  865.            Me.SetBytes(Me.startAddressName, Me.endAddressName, Encoding.ASCII.GetBytes(name))
  866.  
  867.        End If
  868.  
  869.    End Sub
  870.  
  871. #End Region
  872.  
  873. #Region " Public Methods "
  874.  
  875.    ''' <summary>
  876.    ''' Save the ROM changes to the specified file path.
  877.    ''' </summary>
  878.    ''' <param name="filePath">The ROM file path.</param>
  879.    ''' <param name="replace">
  880.    ''' If set to <c>true</c>, then replaces any existing file,
  881.    ''' otherwise, throws an <see cref="IOException"/> exception if file already exists.
  882.    ''' </param>
  883.    ''' <exception cref="IOException">The destination file already exists.</exception>
  884.    Public Sub Save(ByVal filePath As String, ByVal replace As Boolean)
  885.  
  886.        If Not replace AndAlso File.Exists(filePath) Then
  887.            Throw New IOException(message:="The destination file already exists.")
  888.  
  889.        Else
  890.            Try
  891.                File.WriteAllBytes(filePath, Me.rawDataB)
  892.  
  893.            Catch ex As Exception
  894.                Throw
  895.  
  896.            End Try
  897.  
  898.        End If
  899.  
  900.    End Sub
  901.  
  902. #End Region
  903.  
  904. End Class



Ejemplo para leer los datos de una ROM:
Código
  1. Dim romDump As New SnesRom("C:\ROM.smc")
  2. ' Or...
  3. ' Dim romDump As New SnesRom(File.ReadAllBytes("C:\ROM.smc"))
  4.  
  5. Dim sb As New StringBuilder
  6. With sb
  7.    .AppendLine(String.Format("Name...............: {0}", romDump.Name))
  8.    .AppendLine(String.Format("Bank Type..........: {0}", romDump.BankType.ToString))
  9.    .AppendLine(String.Format("Cartridge Type.....: {0}", romDump.CartridgeType.ToString.ToUpper))
  10.    .AppendLine(String.Format("Checksum...........: {0}", romDump.Checksum.ToString))
  11.    .AppendLine(String.Format("Checksum Compliment: {0}", romDump.ChecksumCompliment.ToString))
  12.    .AppendLine(String.Format("Country Region.....: {0}", romDump.Country.Region.ToString.ToUpper))
  13.    .AppendLine(String.Format("Country Code.......: {0}", romDump.Country.Code.ToString))
  14.    .AppendLine(String.Format("Country Name.......: {0}", romDump.Country.Name))
  15.    .AppendLine(String.Format("Header Type........: {0}", romDump.HeaderType.ToString))
  16.    .AppendLine(String.Format("Layout.............: {0}", romDump.Layout.ToString))
  17.    .AppendLine(String.Format("License Code.......: {0}", romDump.LicenseCode.ToString))
  18.    .AppendLine(String.Format("RAM Size...........: {0}", romDump.RamSize.ToString))
  19.    .AppendLine(String.Format("ROM Size...........: {0}", romDump.RomSize.ToString))
  20.    .AppendLine(String.Format("Version Number.....: {0}", romDump.VersionNumber.ToString))
  21. End With
  22.  
  23. Clipboard.SetText(sb.ToString) : MessageBox.Show(sb.ToString)

Resultado de ejecución de la lectura de una ROM:
Código:
Name...............: THE LEGEND OF ZELDA
Bank Type..........: LoRom
Cartridge Type.....: SRAM
Checksum...........: 44813
Checksum Compliment: 20722
Country Region.....: NTSC
Country Code.......: 1
Country Name.......: United States
Header Type........: Headered
Layout.............: 32
License Code.......: 1
RAM Size...........: 3
ROM Size...........: 10
Version Number.....: 0

Ejemplo para modificar una ROM:
Código
  1. Dim romDump As New SnesRom("C:\ROM.smc")
  2. ' Or...
  3. ' Dim romDump As New SnesRom(File.ReadAllBytes("C:\Rom.smc"))
  4.  
  5. With romDump
  6.    .Name = "Elektrozoider"
  7.    .Country = New SnesRom.CountryData(countryCode:=8) ' Spain.
  8.    .VersionNumber = CByte(3)
  9.    .Save("C:\Hacked.smc", replace:=True)
  10. End With
5333  Sistemas Operativos / Windows / Re: Problema Explorer. Desaparecieron las imágenes de los iconos. en: 10 Junio 2015, 18:52 pm
Posiblemente Off topic (No le encuentro relación directa)
Durante mi experimentación con el script, encontré algo que me ha dejado desconcertado. A modo de ensayo ejecuté directamente el método :RebuildIconCache (yo se que no funciona así) pero la salida en la consola fue de lo más extraña. Se referencia un archivo llamado @OpenWithToastLogo.png en "C:\Windows\WinSxS\wow64_microsoft-windows-openwith_31....alphanumeric...." del cual no consigo ninguna información en internet. Y no entiendo por qué se llama así WTF!?

Es extraño lo que comentas.

El nombre "xxxOpenWithxxx" ya explica por si mismo o da una pista de a que característica de Windows pertenece, adentro de esa carpeta encontrarás una aplicación llamada "openwith.exe", la cual puedes iniciar por linea de comandos para pasarle el argumento de un archivo, es el menú "Abrir Con..." de Windows:



El archivo '@OpenWithToastLogo.png' intuyo que puede ser el recurso de imagen que se usa de fondo cuando haces click en la siguiente casilla, ya que parece ocupar 32x32:



Eso no lo he comprobado, solo es una suposición, a donde quiero llegar es que de todas formas ese archivo no es "importante" o "sospechoso", se trata de un archivo de Windows, y el nombre "xxxLogo.png" también explica por si mismo que no hay que preocuparse por ese archivo.

Respecto al resto de tus dudas, el directorio 'WinSXS' es donde Windows almacena los archivos de instalación, los archivos originales para que en "X" momento puedan ser restaurados si es necesario, también almacena actualizaciones y las versiones anteriores de archivos, es practicamente una copia de seguridad que NO se debe eliminar (aunque puedes eliminar bastantes archivos de forma parcial para reducir el tamaño del directorio en gran medida, si sabes lo que haces);
la cadena de texto alfanumérica a la que te refieres es un número único de identificación (pues de algún modo Windows ha de poder identificar versiones distinstas de los mismos archivos), que consiste en dos hashes, la build de Windows, y la cultura de los archivos (la región del país).

Saludos!
5334  Programación / .NET (C#, VB.NET, ASP) / Re: Leer una clase en un formulario Widnows de Visual C# en: 10 Junio 2015, 15:07 pm
Lo dejaré así mismo, me gusta.

Código
  1. textBox_Layout.Text = string.Format("0x{0}", VARIABLE.Layout);

Pero eso que haces no tiene ningún sentido aunque te guste; "0x" es el prefijo estándar para un valor hexadecimal, pero la propiedad "Layout" devuelve un valor decimal entre 0 y 255, es decir, un Byte.

Si haces eso solo conseguirás mostrar resultados confusos en la UI.

Saludos!
5335  Programación / .NET (C#, VB.NET, ASP) / Re: Leer una clase en un formulario Widnows de Visual C# en: 10 Junio 2015, 13:51 pm
El formato que le das al string es incorrecto, lee el ejemplo que he añadido en mi última respuesta.

Saludos!
5336  Programación / .NET (C#, VB.NET, ASP) / Re: Leer una clase en un formulario Widnows de Visual C# en: 10 Junio 2015, 13:37 pm
Auí hay una Web perfecta para convertir códigos.
https://www.easycalculation.com/hex-converter.php

O verlo directamenta la tabla ASCII.
http://www.elcodigoascii.com.ar/codigo-americano-estandar-intercambio-informacion/codigo-ascii.gif

El 12 que presenta es decimal, quiero se se vea hexadecimal, que es 0C. (En C# se presenta así 0x0C).

No necesitas recurrir a ningún servicio online ni tabla de caracteres, la librería de clases de .Net Framework tiene varias funciones built-in para llevar a cabo ese tipo de conversiones.

Convert.ToInt32 Method - MSDN
Convert.ToString Method - MSDN
Convert.ToChar Method - MSDN
y:
String.Format Method - MSDN

PD: Fíjate en el parámetro 'fromBase' de los overloads de la función Convert.ToInt32, y el parámetro 'toBase' de los overloads de la función Convert.ToString.

Ejemplo:
Código
  1. String.Format("0x{0}", Convert.ToString(255, toBase:=16))

Saludos!
5337  Sistemas Operativos / Windows / Re: problemas de rendimiento en: 10 Junio 2015, 12:50 pm
Los problemas de ralentización del navegador suelen ser motivo de tener demasiadas extensiones instaladas las cuales una o varías de ellas puedan causar conflictos de ese tipo;
Ten en cuenta que las extensiones son desarrolladas por terceros programadores, en muchas ocasiones lo suficientemente inexpertos cómo para que sepan realizar una buena administración del uso de la memoria asignada, la recolección de basura, cache/datos temporales, etc.

Empieza por indicar que navegador usas, y también que versión de Windows, eso cómo mínimo, después, indica que extensiones tienes instaladas, y cuantos programas y servicios tienes actualmente ejecutandose en segundo plano bajo Windows.

Realmente no se cómo esperas recibir ayuda cualificada si no das ningún detalle más que "he usado avast y ccleaner". No te dejes ningún detalle en el aire, muestra imagenes o listas de texto de todo lo que he comentado.

De todas formas, para empezar, lo que puedes intentar es desactivar TODAS las extensiones que tengas instaladas, para determinar si notas una estabilización en la velocidad de procesamiento de dicho navegador, en caso de ser así, ya sabes que el problema es alguna de las extensiones que tengas instaladas, y en ese caso puedes ir activándolas una a una con un posterior reinicio del navegador, para determinar que extensión en particular es la que causa el conflicto.
 
Saludos!
5338  Programación / .NET (C#, VB.NET, ASP) / Re: Leer una clase en un formulario Widnows de Visual C# en: 10 Junio 2015, 11:26 am
Meta, fíjate bien en lo que estás haciendo ...leches xD.

La Class "RomDump" la estás declarando e instanciando en el bloque del event-handler "button1_Click", ahí es donde empieza y donde también termina la vida de ese objeto;
luego, tú estás haciendo un (mal) intento de leer esa instancia en otro método distinto, en el bloque del método "Mostar_Datos", no puedes leer una referencia que no existe.

1. Declara una variable 'snesRom' hacia una referencia vacía de la Class 'RomDump', fuera de cualquier método.
Código
  1. SnesKit.RomDump snesRom

2. Crea una instancia la Class 'RomDump' a la variable 'snesRom', dentro del handler "button1_Click" o dentro del método que prefieras.
Código
  1. this.snesRom = new SnesKit.RomDump(bytes);

3. Ya puedes leer la referencia de la propiedad 'snesRom.Name' donde quieras:
Código
  1. MessageBox.Show(snesRom.Name);

Saludos
5339  Programación / .NET (C#, VB.NET, ASP) / Re: [C#] DataGridView congelación de app en: 10 Junio 2015, 11:02 am
Si estás utilizando el método DataGridView.Rows.Add que toma cómo argumento el número de filas a crear, entonces el thread de la UI no se podrá actualizar hasta que finalice dicha operación de inserción de filas, por ende, la UI se congelará.

Habría que ver el código para poder comprobar el qué y cómo lo estás haciendo, ya que quizás haya otros problemas que estén derivando en esa congelación del thread, así que si no das más datos no se te puede ayudar a buscar la solución más eficiente para el problema que sea en cuestión.

De todas formas, puedes añadir las filas de manera asíncrona para solventar el problema de congelación, pero esto tomará bastante más tiempo en añadir todas las filas:

Código
  1. Public Class Form1
  2.  
  3.    Private WithEvents bgw As New BackgroundWorker
  4.  
  5.    Private Sub Button1_Click(sender As Object, e As EventArgs) _
  6.    Handles Button1.Click
  7.  
  8.        DataGridView1.ColumnCount = 1
  9.        bgw.RunWorkerAsync()
  10.  
  11.    End Sub
  12.  
  13.    Sub DoRowAdd(ByVal dgv As DataGridView, ByVal row As DataGridViewRow)
  14.  
  15.        If dgv.InvokeRequired Then
  16.            dgv.Invoke(Sub() dgv.Rows.Add(row))
  17.  
  18.        Else
  19.            dgv.Rows.Add(row)
  20.  
  21.        End If
  22.  
  23.    End Sub
  24.  
  25.    Sub Work(ByVal sender As Object, ByVal e As EventArgs) _
  26.    Handles bgw.DoWork
  27.  
  28.        For rowIndex As Integer = 0 To Short.MaxValue
  29.  
  30.            Dim row As New DataGridViewRow
  31.            row.Cells.Add(New DataGridViewTextBoxCell With {.Value = rowIndex})
  32.            Me.DoRowAdd(Me.DataGridView1, row)
  33.  
  34.        Next rowIndex
  35.  
  36.    End Sub
  37.  
  38. End Class

Otra alternativa sería añadir las filas una a una cómo en el ejemplo anterior, pero utilizando el método Application.DoEvents para que tras cada inserción se procese el resto de mensajes (eventos) en cola para actualizar la UI;
el tiempo que se toma en crear las filas es practicamente el mismo que en el ejemplo de arriba.

Código
  1.        DataGridView1.Columns.Add(String.Empty, String.Empty)
  2.  
  3.        For rowIndex As Integer = 0 To Short.MaxValue
  4.  
  5.            DataGridView1.Rows.Add({rowIndex})
  6.            Application.DoEvents()
  7.  
  8.        Next rowIndex

También lo que puedes hacer al utilizar el método DataGridView.Rows.Add que toma cómo argumento el número de filas a crear, es suspender la lógica del layout del control, esto aceleraría bastante el tiempo que tarda en agregar todas las filas, pero obviamente no se desbloquearía la UI.

Código
  1.        DataGridView1.Columns.Add(String.Empty, String.Empty)
  2.        DataGridView1.SuspendLayout()
  3.        DataGridView1.Rows.Add(Short.MaxValue)
  4.        DataGridView1.ResumeLayout()



EDITO: Ups, perdón, no me di cuenta que lo preguntaste en C#, aquí tienes una conversión online:

Código
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7. public class Form1
  8. {
  9.  
  10. private BackgroundWorker withEventsField_bgw = new BackgroundWorker();
  11. private BackgroundWorker bgw {
  12. get { return withEventsField_bgw; }
  13. set {
  14. if (withEventsField_bgw != null) {
  15. withEventsField_bgw.DoWork -= Work;
  16. }
  17. withEventsField_bgw = value;
  18. if (withEventsField_bgw != null) {
  19. withEventsField_bgw.DoWork += Work;
  20. }
  21. }
  22. }
  23.  
  24. private void Button1_Click(object sender, EventArgs e)
  25. {
  26.  
  27. DataGridView1.ColumnCount = 1;
  28. bgw.RunWorkerAsync();
  29.  
  30. }
  31.  
  32. public void DoRowAdd(DataGridView dgv, DataGridViewRow row)
  33. {
  34.  
  35. if (dgv.InvokeRequired) {
  36. dgv.Invoke(() => dgv.Rows.Add(row));
  37.  
  38. } else {
  39. dgv.Rows.Add(row);
  40.  
  41. }
  42.  
  43. }
  44.  
  45. public void Work(object sender, EventArgs e)
  46. {
  47.  
  48. for (int rowIndex = 0; rowIndex <= short.MaxValue; rowIndex++) {
  49.  
  50. DataGridViewRow row = new DataGridViewRow();
  51. row.Cells.Add(new DataGridViewTextBoxCell { Value = rowIndex });
  52. this.DoRowAdd(this.DataGridView1, row);
  53.  
  54. }
  55.  
  56. }
  57.  
  58. }
  59.  
  60. //=======================================================
  61. //Service provided by Telerik (www.telerik.com)
  62. //=======================================================

Considero que los otros dos ejemplos no necesitan una conversión a C# para entenderlos.

Saludos!
5340  Foros Generales / Foro Libre / Re: [Resuelto] Como se llama ese soundtrack que le ponen a los nerds (o cerebritos) en: 10 Junio 2015, 10:28 am
No se donde ves tú que la música clásica tenga algo que ver con los nerds, pero bueno. :-\

El chiptune (o música de 8-bits) de tu firma le pega más a los nerds.

Saludos!
Páginas: 1 ... 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 [534] 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines