1.
Imports system.componentmodelpublic class pic inherits system.windows.forms.userControl
#Region "Windows Form Designer Generated Code"
'UserControl1 Rewinds Dispose to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub
'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer
'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.
End Sub
#End region
Public const m_maxlen as integer = 48 'fixed wide and high public const m_maxheight as integer = 48 Public Sub New (BYVAL M As Image) "Mainly used to use mybase.new when you create instances in the PicControls component
'This call is required for the Windows Form Designer. InitializeComponent ()
'Add any initialization m_image = m = m_im () mybase.new () in initializeComponent ()
'This call is required for the Windows Form Designer. InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
End Sub
Private m_image as image = image.fromfile ("G: / Exercise / Important Rollers / Using Issues (Pictures in Plaid) / Gounda Takeshi.ico")
Imports my_namespaceimports system.componentmodelpublic class piccontrols inherits system.componentmodel.component
#REGION "Component Designer Generated Code"
'Component override Dispose to clean the component list. Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub 'designer component required Private components As System .Componentmodel.icontainer
'Note: The following procedure is that the component designer must modify this process using the Component Designer. 'Don't modify it using the code editor.
#End region public subnewele (byval container as system.componentmodel.icontainer) myclass.new ()
'Windows.Forms Class Writing Designer Support for Container.Add (ME)
ChangePic () 'If the selected picture has changed, then the creation of the card set should also change accordingly.
End Sub
Public Sub new () mybase.new ()
'This call is necessary for the component designer. InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
ChangePic () 'If the selected picture has changed, then the creation of the card set should also change accordingly.
End Sub '
Dim m_piccontrols as new system.collections.ArrayList () 'total number Public Sub shuffle () 'mixed card, that is, generated a set of random card sets. (Here the algorithm!) Dim r as new system.random () DIM D AS New System.Collections.ArrayList () Dim P AS Pic While (m_piccontrols.count> 0) Dim RemoveIndex as integer = r.next (0, m_piccontrols.Count - 1) p = CType (m_piccontrols (removeindex), my_namespace.pic) m_piccontrols.RemoveAt (removeindex) d.Add (p) End While m_piccontrols = d End SubPrivate m_image As imagelist END CLASS 3. Imports System.comPonentmodelpublic Class PicShow Inherits System.Windows.Forms.userControl # Region "Windows Form Designer Generated Code" Public Sub new () mybase.new () 'This call is required for the Windows Form Designer. InitializeComponent () 'Add any initialization after INITIALIZECOMPONENT () End Sub 'UserControl overrides Dispose to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub 'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer 'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor. #End region '// This program Principle // First make a PIC control, you can set the corresponding picture, do not allow the size, to override SizeChange, onpait event //' // to do a collection component PicControls to accommodate a certain number of PIC cards but do not display it because it is a component. Just the container // '// finally makes a PICSHOW control to display the number of cards for the number of PicControls.count. // '// More important places are how to carry out randomized mixing (SHUFFLE methods of PicControls) and PICSHOW controls // contrains, start methods. Always pay attention to the order of sorting: Yes, it is blended (randomly) in the collection, so // '// we have obtained is random, then in the PicShow control according to each card Doubles The id attribute is to perform // '// sort, separate random and sorting. Of course, they can also merge them into the PICSHOW control. But here is not recommended. // '// Because for the PicControls component, its collection is a randomly generated card collection. This is better understood. // Private const m_spacing as integer = 10 'Interval Setting constant private m_rows as integer = 2' For an array, 2 lines should be more meaningful. Protected Overrides Sub OnPaint (ByVal e As System.Windows.Forms.PaintEventArgs) Dim height As Integer = my_namespace.pic.m_maxheight Dim width As Integer = my_namespace.pic.m_maxlen Me.Width = (width m_spacing) * m_columns m_spacing Me .Height = (height m_spacing) * m_rows m_spacing Dim g As Graphics = Me.CreateGraphics Dim row, column As Integer For row = 0 To m_rows - 1 For column = 0 To m_columns - 1 g.DrawRectangle (System.Drawing. Pens.gray, column * (width m_spacing) m_spacing, _ row * (Height m_spacing) m_spacing, width, height) Next Next End subprivate m_double as pic 'record the same card Private m_last as integer 'records the last card in the lattice 'Starting public sub start () Me.Controls.clear () 'First empty container If not isnothing (m_collection) THEN 'Judgment Rat Column The number of the cards is equal to if (m_collection.count <> m_rows * m_column) THROW New Exception ("The number of cards:" & cstr (m_collection.count) & "grid quantity To: "& CSTR (m_rows * m_columns) Endiff '/// M_last = -2 'initialization, because starting from 0 to the first lattice, so the initial value is -2 m_collection.setfalse () 'Because you start sorting, you will set all the Double properties of all card PICs to True. So, here you have to set back to False m_collection.shuffle () 'Mix the card DIM cardcount as integer = 0 'card pointer DIM ROW, Column As INTEGER For row = 0 to m_rows - 1 for column = 0 To m_columns - 1 DIM APIC APIC APIC APIC AS PIC = CTYPE (m_collection (cardcount), PIC) 'Add to ME Control Set Me.Controls.Add (APIC)' Control Collection The original card is traversed, see if there is a single card DIM RINT AS INTEGER = Contrains (APIC) SELECT CASE RINT CASE 0 'matching arrangement APIC.PIC = M_DOUBLE.PIC .m_maxlen apic.top = m_double.top case 1 'No match, interval arrangement 'Opening, pay attention must be used to transform using int, otherwise it will be rounded. DIM R AS INTEGER = INT (m_last / (m_rows)) 'column DIM C AS INTEGER = M_LAST MOD (M_ROWS)' After obtaining the ranks, you can set the position directly. APIC.LEFT = C * (pic.m_maxlen m_spacing) m_spacing apic.top = r * (pic.m_maxheight m_spacing) m_spacing End Select CardCount = 1 'Next Card Next Next MessageBox.show ("Sorted!") End if End Sub 'Sorted Functions Public Function Contrains (Byval P AS PIC) AS Integer M_Double = Nothing' The initial value is empty, and set to empty each time you sort. DIM APIC AS PIC DIM I AS INTEGER DIM Count As integer = me.controls.count - 1 for i = 0 to count - 1 'From 0 to the end - 1, remove yourself, you don't have to compare APIC = CType (Me.Controls (i), PIC) IF (APIC.ID = P.ID) and apic.doubles = false the 'and i <> count apic.doubles = true' matching p.douBles = true 'matches m_double = APIC END IF NEXT 'found the matching IF not (m_double is nothing) Then Return 0 else m_last = 2' separated a lattice (here the lattice starts to be 0, and finally m_collection count-1) Return 1 End IFend Functionend Class