IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

quelques problèmes avec mon code


Sujet :

VB.NET

  1. #1
    Candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 35
    Points : 3
    Points
    3
    Par défaut quelques problèmes avec mon code
    Bonjour,

    SVP j'ai élaboré un code en vb.net mais il y a des erreurs et quelques rectifications que j'arrive pas à les corriger

    Y a t-il quelqu'un qui veut m'aider?

  2. #2
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    avec juste ça je ne pense pas que quelqu'un soit en mesure de le faire
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 35
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Pol63 Voir le message
    avec juste ça je ne pense pas que quelqu'un soit en mesure de le faire
    mais je veux envoyer mon code pour celui qui veux m'aider

  4. #4
    Membre habitué
    Homme Profil pro
    Inscrit en
    Mars 2008
    Messages
    161
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mars 2008
    Messages : 161
    Points : 166
    Points
    166
    Par défaut
    Il serait intéressant que tu nous fasse voir le code en question ainsi que les messages d'erreur. Sans ça il serait difficile det'aider.

  5. #5
    Candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 35
    Points : 3
    Points
    3
    Par défaut voici mon code
    Citation Envoyé par peregna2007 Voir le message
    Il serait intéressant que tu nous fasse voir le code en question ainsi que les messages d'erreur. Sans ça il serait difficile det'aider.
    Le fichier .rar ci-jointe contient le code sous VB.net

    Explication de tache:

    je dois programmé les techniques de strip packing (NextFit, FirstFit, BestFit et WorstFit): ces sont des algorithmes qui ordonne des petits rectangles dans une surface afin d'optimiser l'utilisation de surface.
    *NextFit: pose le rectangle toujours aprés le dernier rectangle deposé
    *FirstFit: cherche le premier emplacement vide qui peut contenir ce rectangle
    *BestFit:cherche le petit emplacement vide et qui peut contenir le rectengle
    *WorstFit:cherche le grand emplacement vide et qui peut contenir le rectengle
    présentation.rar explique c'est que j'ai dis par des images

    Dans le design
    *Dans un pictureBox j'ai dessiné le Grid(une matrice de petits carreaux) appelé taille de dispositif
    *les dimensions de dispositif je le fais entrer via des zones txt
    *les rectangles que je dois placer je fais entrer ses dimensions .
    *Datagridview sert a me donné les coordonnées de chaque rectangles après qu'il soit placé

    les erreurs
    *la taille de pictureBox que je dois le faire en réalité est grande 100*100
    mais si je fais ceci les bouton et seront affichés dans la grid dons je dois avoir des scrollbar ou quelque chose qui permet de voir toute la grid

    *les deux boutons de BestFit et WorstFit ne placent pas le rectangles comme j'ai prévu

    *DatagridView affiche les coordonnées correctement pour NextFit et FirstFit et pas pour les deux autres boutons.
    Fichiers attachés Fichiers attachés

  6. #6
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    sur ce forum, on aide sur des problèmes concis, c'est du "bénévolat"
    donc personnellement je ne vais pas ouvrir une solution avec des milliers de code pour chercher les bugs
    tu peux d'ailleurs constater que les autres postent quelques lignes de code avec une explication du problème
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  7. #7
    Candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 35
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par Pol63 Voir le message
    sur ce forum, on aide sur des problèmes concis, c'est du "bénévolat"
    donc personnellement je ne vais pas ouvrir une solution avec des milliers de code pour chercher les bugs
    tu peux d'ailleurs constater que les autres postent quelques lignes de code avec une explication du problème
    Merci pour vos efforts, mais c qui est bizzare comment t'as su que sont des milliers des codes sans l'avoir vu.

  8. #8
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    là n'est pas la question ...
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  9. #9
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par MiNa 7 Voir le message
    Merci pour vos efforts, mais c qui est bizzare comment t'as su que sont des milliers des codes sans l'avoir vu.
    suffit juste de regarder le nombre d'affichage à côté de tes fichiers .rar.

  10. #10
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut scroller dans un picturebox
    bonjour,
    d'abord pour commencer je t'ai deja donne le code pour scroller dans ton picturebox et voir la grille dans ce post
    http://www.developpez.net/forums/d10...tomatiquement/

    a moins que tu ne lises pas les reponnes à tes post,il suffit simplement de le rajouter à ton picturebox.
    bon firstfit,worsfit etc ... je veux les regarder et si j'arrive à comprendre ton code(avec les commentaires explicatifs si tu les a mis sinon toi-meme tu ne comprendras ton code dans trois mois).....
    ensuite aide-toi le ciel t'aideras...............dirait Lafontaine et c'est toujours valable meme en 2050....
    bon code....

  11. #11
    Candidat au Club
    Inscrit en
    Octobre 2010
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 35
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par MABROUKI Voir le message
    bonjour,
    d'abord pour commencer je t'ai deja donne le code pour scroller dans ton picturebox et voir la grille dans ce post
    http://www.developpez.net/forums/d10...tomatiquement/

    a moins que tu ne lises pas les reponnes à tes post,il suffit simplement de le rajouter à ton picturebox.
    bon firstfit,worsfit etc ... je veux les regarder et si j'arrive à comprendre ton code(avec les commentaires explicatifs si tu les a mis sinon toi-meme tu ne comprendras ton code dans trois mois).....
    ensuite aide-toi le ciel t'aideras...............dirait Lafontaine et c'est toujours valable meme en 2050....
    bon code....



    Bonsoir Mr,
    Je vous remercie infiniment, j'ai lu votre réponse concernant scrollbar et j'ai fai une petite application a part et ça bien marché mais le problème avec mon application est que je ne charge pas une image dans picutrebox je trace la matrice voici le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    Private Sub DrawGrid(ByVal myGraphics As Graphics, ByVal myPen As Pen)
    
            Dim myRectangle As Rectangle
    
            'return the current form as a drawing surface
            myGraphics = Graphics.FromHwnd(picResult().Handle)
            myGraphics.Clear(Color.Transparent)
    
            For posHeight As Integer = 0 To picResult.Height
                For posWidth As Integer = 0 To picResult.Width
                    'create a rectangle based on x,y coordinates, width, & height
                    myRectangle = New Rectangle(x:=posWidth, y:=posHeight, Width:=Ssale, Height:=Ssale)
    
                    'draw rectangle from pen and rectangle objects
                    myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
                    posWidth += Ssale - 1
                Next posWidth
                posHeight += Ssale - 1
            Next posHeight
        End Sub
    
    dans ce code picture box est de taille fixe , mais moi j'ai ajouter deux bouton pour redimensionner picturebox a la taille que je veux et là quand je mais un grand taille la matrice sera chevauche avec les boutons de mon outil.dans j'ai pas su comment ajouter la fonction de scrollbar avec mon code

  12. #12
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut first fit,bestfit,zoom sur picturebox
    bonjour
    voila je t'envoie le code source first fit,bestfit revu et corrige pour la partie bestfit(algo qui boucle) et le zoom dans picturebox
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    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
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
     
    'CORRECTION DE BUG SUR BESTFIG(VOIR C-APRES
    'FACTEUR ZOOM VA DE 0   À 200
    'FACTEUR ZOOM NORMAL =100
    Imports System.Drawing.Drawing2D
    Public Class Form1
        'DECLARATION DE VARAIABLES DOIVENT FIGURES AU DEBUT DE CLASSE
        Public Structure rectProp
            Dim haut As Integer
            Dim larg As Integer
            Dim nom As String
        End Structure
        Public Structure modu
            Dim haut As Integer
            Dim larg As Integer
        End Structure
        Private Const Ssale As Integer = 10
        Dim drawFont As New Font("Arial", 10, FontStyle.Regular)
        Dim myBrush As SolidBrush = New SolidBrush(Color.Yellow)
        Dim rectBrush As New Drawing2D.LinearGradientBrush(ClientRectangle, Color.Yellow, Color.Blue, Drawing2D.LinearGradientMode.Horizontal)
        Dim drawFormat As New StringFormat()
     
        'DECLARATION DE VARAIABLES POUR GERER ZOOM IMMEDIAT
        '--------------------------------------------------
        Dim boolDraw As Boolean
        Dim boolFirstFit As Boolean
        Dim boolBestFit As Boolean
        Dim boolWorstFit As Boolean
        Private Event OnDraw As EventHandler(Of EventArgs)
        Private Event OnFirstFit As EventHandler(Of EventArgs)
        Private Event OnBestFit As EventHandler(Of EventArgs)
        Private Event OnWorstFit As EventHandler(Of EventArgs)
        Public Sub New()
     
            ' Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
            ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
            'RAJOUT DES HANDLERS D'EVENEMENTS POUR GESTION DU ZOOM
            '-----------------------------------------------------
            AddHandler Me.OnDraw, AddressOf BtnDraw_Click
            AddHandler Me.OnFirstFit, AddressOf BtnFirstFit_Click
            AddHandler Me.OnBestFit, AddressOf btnBestFit_Click
            AddHandler Me.OnWorstFit, AddressOf btnWorstFit_Click
            'MODE STRETCH POUR PICTUREBOX
            '----------------------------
            picResult.SizeMode = PictureBoxSizeMode.StretchImage
            'INIT TRACKERBAR
            '---------------
            trckEchelle.TickFrequency = 1
            trckEchelle.Dock = DockStyle.None
            trckEchelle.Value = 1  'valeur initiale
            trckEchelle.Minimum = 1 'valeur Mini pour Zoom
            trckEchelle.Maximum = 20 'valeur Maxi pour Zoom
            trckEchelle.LargeChange = 1 'grand increment sur click 
            trckEchelle.SmallChange = 1 'petit increment sur click
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            txtHauteur.Text = picResult.Height / Ssale
            txtLargeur.Text = picResult.Width / Ssale
        End Sub
        Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInputs.TextChanged
            txtInputs.Select(0, 0)
        End Sub
        Private Sub txtInputs_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInputs.TextChanged
        End Sub
        Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
        End Sub
        Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter
        End Sub
        Private Sub Algorithme_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Algorithme.Enter
        End Sub
     
        Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        End Sub
     
        Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs, Optional ByVal show_graphically As Boolean = True) Handles btnOK.Click
            Dim the_pen As New Pen(Color.Blue, 0)
            Dim bin_wid As Integer = txtHauteur.Text
            Dim haut As Integer = Val(txtHauteur.Text)
            Dim larg As Integer = Val(txtLargeur.Text)
     
            If show_graphically Then
                picResult.Width = larg * Ssale + 5
                picResult.Height = haut * Ssale
                Dim bm As New Bitmap(picResult.Width, picResult.Height)
                Dim gr As Graphics = Graphics.FromImage(bm)
                gr.ScaleTransform(Ssale, Ssale)
                gr.Clear(picResult.BackColor)
                ' Draw a unit grid.
                Dim hgt As Single = picResult.Height / Ssale
                Dim white_pen As New Pen(Color.White, 0)
     
                For i As Integer = 1 To bin_wid
                    gr.DrawLine(white_pen, i, 0, i, hgt)
                Next i
                For i As Integer = 1 To hgt
                    gr.DrawLine(white_pen, 0, i, bin_wid, i)
                Next i
                white_pen.Dispose()
                the_pen.Dispose()
                gr.Dispose()
                picResult.Image = bm
            End If
        End Sub
        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
            txtInputs.Text += txtNbLigne.Text + "*" + txtNbCol.Text + vbNewLine
        End Sub
        Private Sub BtnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
            Dim myGraphics As Graphics
            Dim myRectangle As Rectangle
            Dim myPen As New Pen(Color.Blue)
     
            'return the current form as a drawing surface
            myGraphics = Graphics.FromHwnd(picResult().Handle)
            myGraphics.Clear(Color.WhiteSmoke)
            'FACTEUR DE ZOOM
            '---------------
            myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
            DrawGrid(myGraphics, myPen)
            If (txtInputs.Text.Length = 0) Then
                MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Dim txt As String = txtInputs.Text
                If txt.EndsWith(vbCrLf) Then
                    txt = txt.Substring(0, txt.Length - vbCrLf.Length)
                End If
     
                Dim lines() As String = txt.Split(vbCrLf)
                Dim modules(lines.Length - 1) As rectProp
     
                For i As Integer = 0 To lines.Length - 1
                    Dim strucRec() As String = lines(i).Split("*")
                    modules(i).haut = Integer.Parse(strucRec(0))
                    modules(i).larg = Integer.Parse(strucRec(1))
                    modules(i).nom = "M" + i.ToString()
                Next
     
                Dim XPosition As Integer = 0
                Dim YPosition As Integer = 0
                myPen = New Pen(Color.Azure)
                Dim Ymax As Integer = 0
                Dim C As Integer = 0
     
                DataGridView1.RowCount = lines.Length
                For i As Integer = 0 To lines.Length - 1
                    If ((XPosition + (Ssale * modules(i).larg)) > picResult.Width) Then
                        For j As Integer = C To (i - 1)
                            If (Ssale * modules(j).haut) > Ymax Then
                                Ymax = Ssale * modules(j).haut
                            End If
                        Next
                        C = i
                        XPosition = 0
                        YPosition += Ymax
                        Ymax = 0
                    End If
     
                    If Not ((YPosition + (Ssale * modules(i).haut)) > picResult.Height) Then
                        myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * modules(i).larg, Height:=Ssale * modules(i).haut)
                        myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
                        myRectangle.Inflate(-1.0, -1.0)
                        Dim myLinearGradientBrush As New LinearGradientBrush( _
                        myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
                        myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
                        myGraphics.DrawString(modules(i).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
                        XPosition += myRectangle.Width
                        'XPosition += Math.Ceiling(myRectangle.Width / 20) * 20
                        'Afficher les caractéristiques des Modules
                        DataGridView1.Rows(i).Cells(0).Value = modules(i).nom
                        DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
                        DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
                        DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
                        DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
                    Else
                        MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    End If
                Next
                'BOUTON Draw A ETE ACTIVE
                '------------------------
                boolDraw = True
                boolFirstFit = boolBestFit = boolWorstFit = False
            End If
        End Sub
        Private Sub BtnFirstFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFirstFit.Click
            Dim myGraphics As Graphics
            Dim myPen As New Pen(Color.Blue)
            Dim myRectangle As Rectangle
     
            'return the current form as a drawing surface
            myGraphics = Graphics.FromHwnd(picResult().Handle)
            myGraphics.Clear(Color.Transparent)
            'FACTEUR DE ZOOM
            '---------------
            myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
            DrawGrid(myGraphics, myPen)
     
            If (txtInputs.Text.Length = 0) Then
                MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Dim txt As String = txtInputs.Text
                If txt.EndsWith(vbCrLf) Then
                    txt = txt.Substring(0, txt.Length - vbCrLf.Length)
                End If
     
                Dim lines() As String = txt.Split(vbCrLf)
                Dim modules(lines.Length - 1) As rectProp
                Dim nouveau(lines.Length - 1) As rectProp
     
                For i As Integer = 0 To lines.Length - 1
                    Dim strucRec() As String = lines(i).Split("*")
                    modules(i).haut = Integer.Parse(strucRec(0))
                    modules(i).larg = Integer.Parse(strucRec(1))
                    modules(i).nom = "M" + i.ToString()
                Next
     
                Dim XPosition As Integer = 0
                Dim YPosition As Integer = 0
                myPen = New Pen(Color.Azure)
                Dim Ymax As Integer = 0
                Dim C As Integer = 0
                Dim k As Integer = 0
                Dim existe As Boolean = True
     
                While (existe)
                    For i As Integer = 0 To modules.Length - 1
                        If ((modules(i).larg <> 0) And (modules(i).haut <> 0) And (XPosition + (Ssale * modules(i).larg) < picResult.Width)) Then
                            nouveau(k).haut = modules(i).haut
                            modules(i).haut = 0
                            nouveau(k).larg = modules(i).larg
                            modules(i).larg = 0
                            nouveau(k).nom = modules(i).nom
                            k += 1
                            XPosition += Ssale * nouveau(i).larg
     
                        End If
                    Next
                    Dim trouver As Integer = 0
                    For i As Integer = 0 To modules.Length - 1
                        If ((modules(i).larg = 0) And (modules(i).haut = 0)) Then
                            trouver += 1
                        End If
                    Next
                    If (trouver = modules.Length) Then
                        existe = False
                    End If
                    XPosition = 0
                End While
     
                DataGridView1.RowCount = lines.Length
                For i As Integer = 0 To nouveau.Length - 1
                    If ((XPosition + (Ssale * nouveau(i).larg)) > picResult.Width) Then
                        For j As Integer = C To (i - 1)
                            If (Ssale * nouveau(j).haut) > Ymax Then
                                Ymax = Ssale * nouveau(j).haut
                            End If
                        Next
                        C = i
                        XPosition = 0
                        YPosition += Ymax
                        Ymax = 0
                    End If
                    If Not ((YPosition + (Ssale * nouveau(i).haut)) > picResult.Height) Then
                        myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * nouveau(i).larg, Height:=Ssale * nouveau(i).haut)
                        myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
                        myRectangle.Inflate(-1.0, -1.0)
                        Dim myLinearGradientBrush As New LinearGradientBrush( _
                        myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
                        myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
                        myGraphics.DrawString(nouveau(i).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
                        'XPosition += myRectangle.Width
                        XPosition += Math.Ceiling(myRectangle.Width / 40) * 40
                        'Afficher les caractéristiques des Modules
                        DataGridView1.Rows(i).Cells(0).Value = nouveau(i).nom
                        DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
                        DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
                        DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
                        DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
     
                    Else
                        MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    End If
                Next
                'BOUTON FirstFit A ETE ACTIVE
                '---------------------------
                boolFirstFit = True
                boolDraw = boolBestFit = boolWorstFit = False
            End If
        End Sub
     
        Private Sub DrawGrid(ByVal myGraphics As Graphics, ByVal myPen As Pen)
            Dim myRectangle As Rectangle
            'return the current form as a drawing surface
            myGraphics = Graphics.FromHwnd(picResult().Handle)
            myGraphics.Clear(Color.Transparent)
     
            For posHeight As Integer = 0 To picResult.Height * 2
                For posWidth As Integer = 0 To picResult.Width * 2
                    'create a rectangle based on x,y coordinates, width, & height
                    myRectangle = New Rectangle(x:=posWidth, y:=posHeight, Width:=Ssale, Height:=Ssale)
     
                    'draw rectangle from pen and rectangle objects
                    myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
                    posWidth += Ssale - 1
                Next posWidth
                posHeight += Ssale - 1
            Next posHeight
     
        End Sub
        'ALGO RECTIFIE CAR VAR "Position" DONNE DES VALEURS NEGATIVES
        'voir plus bas la ligne
        Private Sub btnBestFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBestFit.Click
            If (txtInputs.Text.Length = 0) Then
                MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Dim txt As String = txtInputs.Text
                If txt.EndsWith(vbCrLf) Then
                    txt = txt.Substring(0, txt.Length - vbCrLf.Length)
                End If
     
                Dim lines() As String = txt.Split(vbCrLf)
                Dim modules(lines.Length) As rectProp
                Dim nouveau(lines.Length) As rectProp
     
                For i As Integer = 0 To lines.Length - 1
                    Dim strucRec() As String = lines(i).Split("*")
                    modules(i).haut = Integer.Parse(strucRec(0))
                    modules(i).larg = Integer.Parse(strucRec(1))
                    modules(i).nom = "M" + i.ToString()
                Next
     
                Dim Matrice((lines.Length), (lines.Length)) As rectProp
                'Remplir la Matrice
                Dim restligne(lines.Length) As Double
     
                For i As Integer = 0 To modules.Length - 1
                    restligne(i) = txtLargeur.Text
                Next
     
                For i As Integer = 0 To modules.Length - 1
                    For j As Integer = 0 To modules.Length - 1
                        Matrice(i, j).haut = 0
                        Matrice(i, j).larg = 0
                        Matrice(i, j).nom = ""
                    Next
                Next
     
                Dim colPosition As Integer = 0
                For k As Integer = 0 To modules.Length - 1
                    'chercher le min dans les lignes
                    'Dim min As Integer = restligne.Min
                    Dim min As Integer = minTable(restligne)
                    Dim Position As Integer = 0
                    Dim copieRestligne(restligne.Length) As Double
                    For p As Integer = 0 To restligne.Length - 1
                        copieRestligne(p) = restligne(p)
                    Next
                    While (min < modules(k).larg)
                        'copieRestligne(Position) = copieRestligne.Max + 1
                        copieRestligne(Position) = maxTable(copieRestligne) + 1
                        'min = copieRestligne.Min
                        min = minTable(copieRestligne)
                        'Position = Array.IndexOf(copieRestligne, copieRestligne.Min)
     
                        Position = Array.IndexOf(copieRestligne, min)
                        'ALGO RECTIFIE CAR VAR "Position" DONNE DES VALEURS NEGATIVES 
                        If Position < 0 Then
                            Position = 0
                        End If
                    End While
                    'Remplir la matrice des valeurs 
                    Matrice(Position, colPosition).haut = modules(k).haut
                    Matrice(Position, colPosition).larg = modules(k).larg
                    Matrice(Position, colPosition).nom = modules(k).nom
                    colPosition += 1
                    restligne(Position) -= modules(k).larg
                Next
     
                'Dessiner les rectangles
                Dim myGraphics As Graphics
                Dim myRectangle As Rectangle
                Dim myPen As New Pen(Color.Blue)
     
                'return the current form as a drawing surface
                myGraphics = Graphics.FromHwnd(picResult().Handle)
                myGraphics.Clear(Color.Transparent)
                'FACTEUR DE ZOOM
                '---------------
                myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
                DrawGrid(myGraphics, myPen)
     
                Dim XPosition As Integer = 0
                Dim YPosition As Integer = 0
                myPen = New Pen(Color.Azure)
                Dim Ymax As Integer = 0
                Dim C As Integer = 0
                DataGridView1.RowCount = lines.Length
                For i As Integer = 0 To lines.Length - 1
     
                    For j As Integer = 0 To lines.Length - 1
                        'si la case de Matrice n'est pas vide
                        If Not (Matrice(i, j).haut = 0) Then
                            'Prendre une position sur l'axe des Y
                            If ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width) Then
                                For y As Integer = C To (i - 1)
                                    For x As Integer = 0 To lines.Length
                                        If (Ssale * Matrice(y, x).haut) > Ymax Then
                                            Ymax = Ssale * Matrice(y, x).haut
                                        End If
                                    Next
                                Next
                                C = i
                                XPosition = 0
                                YPosition += Ymax
                                Ymax = 0
                            End If
     
                            If Not ((YPosition + (Ssale * Matrice(i, j).haut)) > picResult.Height) Then
                                myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * Matrice(i, j).larg, Height:=Ssale * Matrice(i, j).haut)
                                myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
                                myRectangle.Inflate(-1.0, -1.0)
                                Dim myLinearGradientBrush As New LinearGradientBrush( _
                                myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
                                myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
                                myGraphics.DrawString(Matrice(i, j).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
                                XPosition += myRectangle.Width
                                'XPosition += Math.Ceiling(myRectangle.Width / 40) * 40
                                'Afficher les caractéristiques des Modules
                                DataGridView1.Rows(i).Cells(0).Value = Matrice(i, j).nom
                                DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
                                DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
                                DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
                                DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
                            Else
                                MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                            End If
     
                        End If
                    Next
                Next
                'BOUTON BestFit A ETE ACTIVE
                '---------------------------
                boolBestFit = True
                boolDraw = boolFirstFit = boolWorstFit = False
            End If
     
        End Sub
     
        Private Sub btnWorstFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWorstFit.Click
            If (txtInputs.Text.Length = 0) Then
                MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Else
                Dim txt As String = txtInputs.Text
                If txt.EndsWith(vbCrLf) Then
                    txt = txt.Substring(0, txt.Length - vbCrLf.Length)
                End If
     
                Dim lines() As String = txt.Split(vbCrLf)
                Dim modules(lines.Length) As rectProp
                Dim nouveau(lines.Length) As rectProp
     
                For i As Integer = 0 To lines.Length - 1
                    Dim strucRec() As String = lines(i).Split("*")
                    modules(i).haut = Integer.Parse(strucRec(0))
                    modules(i).larg = Integer.Parse(strucRec(1))
                    modules(i).nom = "M" + i.ToString()
                Next
     
                Dim Matrice((lines.Length), (lines.Length)) As rectProp
                'Remplir la Matrice
                Dim restligne(lines.Length) As Double
                For i As Integer = 0 To modules.Length - 1
                    restligne(i) = txtLargeur.Text
                Next
                For i As Integer = 0 To modules.Length - 1
                    For j As Integer = 0 To modules.Length - 1
                        Matrice(i, j).haut = 0
                        Matrice(i, j).larg = 0
                        Matrice(i, j).nom = ""
                    Next
                Next
     
                Dim colPosition As Integer = 0
                For k As Integer = 0 To modules.Length - 1
                    'chercher le max dans les lignes
                    'Dim max As Integer = restligne.Min
                    Dim max As Integer = minTable(restligne)
                    Dim Position As Integer = 0
                    If (restligne(Position) < modules(k).larg) Then
                        'Position = Array.IndexOf(restligne, restligne.Max)
                        Position = Array.IndexOf(restligne, maxTable(restligne))
                    End If
     
                    'Remplir la matrice des valeurs 
                    Matrice(Position, colPosition).haut = modules(k).haut
                    Matrice(Position, colPosition).larg = modules(k).larg
                    Matrice(Position, colPosition).nom = modules(k).nom
                    colPosition += 1
                    restligne(Position) -= modules(k).larg
                Next
     
                'Dessiner les rectangles
                Dim myGraphics As Graphics
                Dim myRectangle As Rectangle
                Dim myPen As New Pen(Color.Blue)
     
                'return the current form as a drawing surface
                myGraphics = Graphics.FromHwnd(picResult().Handle)
                myGraphics.Clear(Color.Transparent)
                'FACTEUR DE ZOOM
                '---------------
                myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
                DrawGrid(myGraphics, myPen)
     
                Dim XPosition As Integer = 0
                Dim YPosition As Integer = 0
                myPen = New Pen(Color.Azure)
                Dim Ymax As Integer = 0
                Dim C As Integer = 0
                DataGridView1.RowCount = lines.Length
                For i As Integer = 0 To lines.Length - 1
     
                    For j As Integer = 0 To lines.Length - 1
                        'si la case de Matrice n'est pas vide
                        If Not (Matrice(i, j).haut = 0) Then
                            'Prendre une position sur l'axe des Y
                            If ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width) Then
                                For y As Integer = C To (i - 1)
                                    For x As Integer = 0 To lines.Length
                                        If (Ssale * Matrice(y, x).haut) > Ymax Then
                                            Ymax = Ssale * Matrice(y, x).haut
                                        End If
                                    Next
                                Next
     
                                C = i
                                XPosition = 0
                                YPosition += picResult.Height
                                Ymax = 0
                            End If
     
                            If Not ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width) Then
                                'If Not (((YPosition + (Ssale * Matrice(i, j).haut)) > picResult.Height) Or ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width)) Then
                                myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * Matrice(i, j).larg, Height:=Ssale * Matrice(i, j).haut)
                                myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
                                myRectangle.Inflate(-1.0, -1.0)
                                Dim myLinearGradientBrush As New LinearGradientBrush( _
                                myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
                                myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
                                myGraphics.DrawString(Matrice(i, j).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
                                XPosition += myRectangle.Width
                                'XPosition += Math.Ceiling(myRectangle.Width / 40) * 40
                                'Afficher les caractéristiques des Modules
                                DataGridView1.Rows(i).Cells(0).Value = Matrice(i, j).nom
                                DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
                                DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
                                DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
                                DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
                            Else
                                MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                            End If
     
                        End If
                    Next
                Next
                'BOUTON WorstFit A ETE ACTIVE A
                '------------------------------
                boolWorstFit = True
                boolDraw = boolFirstFit = boolBestFit = False
            End If
        End Sub
     
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuitter.Click
            Me.Close()
        End Sub
     
        Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        End Sub
        Private Sub picResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picResult.Click
        End Sub
        Private Sub txtLargeur_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLargeur.TextChanged
        End Sub
        Friend Sub DisplayResults(ByVal bin_wid As Integer, ByVal rects() As Rectangle, Optional ByVal show_graphically As Boolean = True, Optional ByVal show_textually As Boolean = False)
        End Sub
        'FONCTION Mini RAJOUTE CAR FONCTION Mini SUR TABLEAU N'EXISTE POUR TABLEAU EN .NET FRAMEWORK 2
        Private Shared Function minTable(ByVal tableDouble() As Double) As Double
            Dim nbMin As Double = 0.0
            Array.Sort(tableDouble)
            nbMin = tableDouble(0)
            Return nbMin
        End Function
        'FONCTION Maxi RAJOUTE CAR FONCTION Max SUR TABLEAU N'EXISTE POUR TABLEAU EN .NET FRAMEWORK 2
        Private Shared Function maxTable(ByVal tableDouble() As Double) As Double
            Dim nbMax As Double = 0.0
            Array.Sort(tableDouble)
            nbMax = tableDouble(tableDouble.Length - 1)
            Return nbMax
        End Function
     
        Private Sub trckEchelle_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trckEchelle.ValueChanged
            Dim fact As Integer = trckEchelle.Value
            ToolTip1.ToolTipTitle = "Zoom % " & 10 * fact.ToString
            'If grapichGlobal IsNot Nothing Then
            '    Dim ee As PaintEventArgs = New PaintEventArgs(picResult.CreateGraphics, picResult.ClientRectangle)
            '    picResult.Refresh()
            'End If
            If boolDraw Then
                RaiseEvent OnDraw(Me, EventArgs.Empty)
            ElseIf boolFirstFit Then
                RaiseEvent OnFirstFit(Me, EventArgs.Empty)
            ElseIf boolBestFit Then
                RaiseEvent OnBestFit(Me, EventArgs.Empty)
            ElseIf boolWorstFit Then
                RaiseEvent OnWorstFit(Me, EventArgs.Empty)
            End If
        End Sub
    End Class
    le code a ete compile en vs2008 mais apparement tu travailles encore avec vs2003 ce qui m'a complique la tache.Il faut changer et vite VS2008.
    bon code...............

Discussions similaires

  1. Réponses: 3
    Dernier message: 15/03/2008, 15h15
  2. problème avec mon code pour accès au serveur ftp
    Par mimi51340 dans le forum Général Java
    Réponses: 1
    Dernier message: 03/03/2008, 23h24
  3. Problème avec mon code - un aperçu
    Par nsimon70 dans le forum Flash
    Réponses: 1
    Dernier message: 14/02/2008, 12h47
  4. [MySQL] problème avec mon code (envoi données) ?
    Par cuisto44000 dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 20/12/2007, 09h45
  5. probléme avec mon code JAVA et MYSQL
    Par ulysse031 dans le forum JDBC
    Réponses: 5
    Dernier message: 10/05/2007, 00h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo