تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] How to display image as a Grid?
#8
الكود التالي يوضح أحد الأفكار لرسم الجريد ثم و عند اختيارة خلية معينة يتم اعادة تلوينها
الكود يعتبر أساس جيد لتنفيذ فكرتك
انا هنا رسمت الجريد علي الفورم مباشرة 
و اعتقد ان عليك استخدام نفس الأسلوب لرسم الجريد علي الكونترول الذي تحدده أنت


PHP كود :
Public Class Form1

    Private cellCount 
As Integer 100
    Private cellPerRow 
As Integer 10
    Private cellSize 
As Integer 20
    Private cells 
As List(Of Rectangle) = Nothing
    Private clikedCells 
As List(Of Rectangle) = New List(Of Rectangle)()
 
   Private selectedCell As Rectangle Nothing
    Private xStart 
As Integer 0
    Private yStart 
As Integer 0

    Private Sub Form1_Load
(sender As ObjectAs EventArgsHandles MyBase.Load
        Me
.DoubleBuffered True
        Me
.SetupCells()
 
   End Sub

    Private Sub SetupCells
()
 
       cells = New List(Of Rectangle)()
 
       Dim indent As Integer 0
        Dim rows 
As Integer cellCount cellPerRow
        Dim x 
As Integer xStart
        Dim y 
As Integer yStart
        Dim rectSize 
As Size = New Size(cellSizecellSize)
 
       For i 0 To rows 1
            y 
xStart
            For j 
As Integer 1 To cellPerRow
                Dim pt 
As New Point(yx)
 
               Dim cell As New Rectangle(ptrectSize)
 
               cells.Add(cell)
 
               y += (cellSize indent)
 
           Next
            x 
+= (cellSize indent)
 
       Next

    End Sub

    Private Sub DrawCells
(As GraphicscellBackColor As ColorcellBorderColor As Color)
 
       For Each cell As Rectangle In cells
            g
.FillRectangle(New SolidBrush(cellBackColor), cell)
 
           g.DrawRectangle(New Pen(cellBorderColor), cell)
 
       Next
    End Sub

    Protected Overrides Sub OnPaint
(As PaintEventArgs)
 
       MyBase.OnPaint(e)
 
       DrawCells(e.GraphicsMe.BackColorColor.Red)

 
       ' ----------------------------------
        ' 
هذاالسطر من الكود للتوضيح فقط

        If Me
.selectedCell <> Nothing Then
            Dim r 
As Rectangle Me.selectedCell
            r
.+= 2
            r
.+= 2
            r
.Width -= 4
            r
.Height -= 4

            e
.Graphics.FillRectangle(New SolidBrush(Color.Blue), r)
 
       End If
 
       ' ----------------------------------

    End Sub

    Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
        MyBase.OnMouseDown(e)
        Me.selectedCell = Me.GetSelectedCell(e.Location)
        If selectedCell <> Nothing Then
            If Not clikedCells.Contains(selectedCell) Then
                Me.clikedCells.Add(selectedCell)
                ' 
----------------------------------
 
               ' هذاالسطر من الكود للتوضيح فقط
                Me.Text = selectedCell.ToString
                Me.Invalidate(selectedCell)
                ' 
----------------------------------
 
           End If
 
       End If
 
   End Sub

    Protected Overrides Sub OnSizeChanged
(As EventArgs)
 
       MyBase.OnSizeChanged(e)
 
       Me.SetupCells()
 
       Me.Invalidate()
 
   End Sub

    Protected Overrides Sub OnLocationChanged
(As EventArgs)
 
       MyBase.OnLocationChanged(e)
 
       Me.SetupCells()
 
       Me.Invalidate()
 
   End Sub

    Private 
Function GetSelectedCell(pt As Point) As Rectangle
        For Each cell 
As Rectangle In cells
            If cell
.Contains(ptThen
                Return cell
                Exit 
For
 
           End If
 
       Next
        Return Nothing
    End 
Function

End Class 
Retired
الرد }}}
تم الشكر بواسطة: amna jamal


الردود في هذا الموضوع
How to display image as a Grid? - بواسطة amna jamal - 23-11-17, 06:10 AM
RE: How to display image as a Grid? - بواسطة HASAN6.0 - 23-11-17, 12:51 PM
RE: How to display image as a Grid? - بواسطة amna jamal - 24-11-17, 07:36 PM
RE: How to display image as a Grid? - بواسطة silverlight - 24-11-17, 12:46 AM
RE: How to display image as a Grid? - بواسطة silverlight - 24-11-17, 04:58 AM
RE: How to display image as a Grid? - بواسطة silverlight - 24-11-17, 01:42 PM
RE: How to display image as a Grid? - بواسطة silverlight - 25-11-17, 11:58 AM
RE: How to display image as a Grid? - بواسطة silverlight - 27-11-17, 06:54 PM


التنقل السريع :


يقوم بقرائة الموضوع: