Помогите пожалуйста решить задачу по программированию, точнее не столько по программированию сколько по математике...
Есть PictureBox с шириной PictureBox1.Width и высотой PictureBox1.Height. Внутри PictureBox-а есть прямоугольник, разбитый на ячейки. d.cx ячеек по ширине и d.cy ячеек по высоте. между ячейками есть промежутки fat_x по ширине и fat_у по высоте. Прямоугольник ограничивающий ячейки должен отступать от краев PictureBox-а на расстоянии одной ячейки, т.е., c_w по оси Х и c_h по оси У соответственно и располагаться по середине. Однако, отступы почему-то не равны. В чем я ошибаюсь?
Вот Код:
Public Structure Cbase
Private _cx As Integer
Private _cy As Integer
Public Property cX() As Integer
Get
Return _cx
End Get
Set(ByVal value As Integer)
_cx = value
End Set
End Property
Public Property cY() As Integer
Get
Return _cy
End Get
Set(ByVal value As Integer)
_cy = value
End Set
End Property
End Structure
Public Class Form1
Dim d As New Cbase
Dim cell() As Integer
Dim cell_select() As Boolean
Dim fat_x As Single
Dim fat_y As Single
Dim back_cell_Brush = New SolidBrush(Color.Black)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
d.cX = 10
d.cY = 10
PictureBox1.BackColor = Color.Aqua
fat_x = 1
fat_y = 1
End Sub
Private Sub PictureBox1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Dim gr As Graphics = e.Graphics
Dim c_h, c_w As Single
Dim box_w As Single
Dim box_h As Single
Dim drawFormat As New StringFormat
Dim cell_Brush As SolidBrush
c_h = ((PictureBox1.Height - 4) + d.cY * (1 - fat_y) - 0) / (d.cY + 2)
c_w = ((PictureBox1.Width - 4) + d.cX * (1 - fat_x) - 0) / (d.cX + 2)
box_w = c_w * d.cX + fat_x * (d.cX - 1) + 2
box_h = c_h * d.cY + fat_y * (d.cY - 1) + 2
gr.FillRectangle(Brushes.Blue, c_w - 1, c_h - 1, box_w, box_h)
For y As Single = 0 To d.cY + 1
For x As Single = 0 To d.cX + 1
Dim m_x As Single = c_w * x + fat_x * (x - 1)
Dim m_y As Single = c_h * y + fat_y * (y - 1)
If x > 0 And x < d.cX + 1 And y > 0 And y < d.cY + 1 Then
cell_Brush = New SolidBrush(Color.Chartreuse)
gr.FillRectangle(cell_Brush, m_x, m_y, c_w, c_h)
End If
Next x, y
End Sub
Другие языки программирования и технологии
Помогите пожалуйста решить задачу по программированию. В чем я ошибаюсь?
Class Range
' Fields
Private ReadOnly _from As Double
Private ReadOnly _step As Double
' Methods
Public Sub New(ByVal from As Integer, ByVal [to] As Integer, ByVal count As Integer)
_from = from
_step = CDbl(([to] - from)) / CDbl(count)
End Sub
Public Function GetLength(ByVal count As Integer) As Integer
Return CInt(count * _step)
End Function
Public Function GetValue(ByVal i As Integer) As Integer
Return CInt(_from + (_step * i))
End Function
End Class
Class Grid
' Fields
Private ReadOnly _horizontal As Range
Private ReadOnly _vertical As Range
' Methods
Public Sub New(ByVal rectangle As Rectangle, ByVal size As Size)
_horizontal = New Range(rectangle.Left, rectangle.Right, size.Width)
_vertical = New Range(rectangle.Top, rectangle.Bottom, size.Height)
End Sub
Public Sub Draw(ByVal graphics As Graphics, ByVal bounds As Rectangle, ByVal foreground As Pen, ByVal background As Brush)
Dim location As New Point(_horizontal.GetValue(bounds.Left), _vertical.GetValue(bounds.Top))
Dim size As New Size(_horizontal.GetLength(bounds.Width), _vertical.GetLength(bounds.Height))
Dim rectangle As New Rectangle(location, size)
graphics.FillRectangle(background, rectangle)
graphics.DrawRectangle(foreground, rectangle)
Dim i As Integer
For i = bounds.Left To bounds.Right
Dim y As Integer = _vertical.GetValue(i)
graphics.DrawLine(foreground, New Point(rectangle.Left, y), New Point(rectangle.Right, y))
Next
For i = bounds.Top To bounds.Bottom
Dim x As Integer = _horizontal.GetValue(i)
graphics.DrawLine(foreground, New Point(x, rectangle.Top), New Point(x, rectangle.Bottom))
Next
End Sub
End Class
Private Sub PictureBoxPaint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles _picture_box.Paint
Dim size As New Size(10, 10) ' 10x10 ячеек
Dim grid as New Grid(_picture_box.ClientRectangle, (size + New Size(2, 2)))
grid.Draw(e.Graphics, New Rectangle(New Point(1, 1), size), Pens.Black, Brushes.Green)
End Sub
' Fields
Private ReadOnly _from As Double
Private ReadOnly _step As Double
' Methods
Public Sub New(ByVal from As Integer, ByVal [to] As Integer, ByVal count As Integer)
_from = from
_step = CDbl(([to] - from)) / CDbl(count)
End Sub
Public Function GetLength(ByVal count As Integer) As Integer
Return CInt(count * _step)
End Function
Public Function GetValue(ByVal i As Integer) As Integer
Return CInt(_from + (_step * i))
End Function
End Class
Class Grid
' Fields
Private ReadOnly _horizontal As Range
Private ReadOnly _vertical As Range
' Methods
Public Sub New(ByVal rectangle As Rectangle, ByVal size As Size)
_horizontal = New Range(rectangle.Left, rectangle.Right, size.Width)
_vertical = New Range(rectangle.Top, rectangle.Bottom, size.Height)
End Sub
Public Sub Draw(ByVal graphics As Graphics, ByVal bounds As Rectangle, ByVal foreground As Pen, ByVal background As Brush)
Dim location As New Point(_horizontal.GetValue(bounds.Left), _vertical.GetValue(bounds.Top))
Dim size As New Size(_horizontal.GetLength(bounds.Width), _vertical.GetLength(bounds.Height))
Dim rectangle As New Rectangle(location, size)
graphics.FillRectangle(background, rectangle)
graphics.DrawRectangle(foreground, rectangle)
Dim i As Integer
For i = bounds.Left To bounds.Right
Dim y As Integer = _vertical.GetValue(i)
graphics.DrawLine(foreground, New Point(rectangle.Left, y), New Point(rectangle.Right, y))
Next
For i = bounds.Top To bounds.Bottom
Dim x As Integer = _horizontal.GetValue(i)
graphics.DrawLine(foreground, New Point(x, rectangle.Top), New Point(x, rectangle.Bottom))
Next
End Sub
End Class
Private Sub PictureBoxPaint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles _picture_box.Paint
Dim size As New Size(10, 10) ' 10x10 ячеек
Dim grid as New Grid(_picture_box.ClientRectangle, (size + New Size(2, 2)))
grid.Draw(e.Graphics, New Rectangle(New Point(1, 1), size), Pens.Black, Brushes.Green)
End Sub
нарисуй, скорее всего в координатах ошибся, они от левого верхнего угла, там 0,0 и ось У в них положительна. На бэйсик похоже, это в Экселе?
Похожие вопросы
- Помогите пожалуйста решить задачу по программированию (язык программирования СИ)
- Помогите пожалуйста решить задачи по программированию. P.S: задачи по паскалю.
- Помогите пожалуйста решить задачу по программированию или напишите, как удалить подряд стоящие точки. (Си, Си++ Билдер)
- помогите пожалуйста решить задачу по работе компьютера!
- Помогите,пожалуйста,решить задачу в Паскале.
- Pascal. Помогите пожалуйста решить задачу в паскале !
- Помогите, пожалуйста, с задачей по программированию(Pascal).
- Помогите,пожалуйста,решить задачу на двумерные массивы,в паскале.(задача вн.)Спасибо.
- Помогите пожалуйста решить задачу С++
- Помогите пожалуйста решить задачи по информатике, одномерные массивы. Си шарп. Очень срочно. Пожалуйста!!!!
Про координаты с нуля знаю....