PDA

View Full Version : سوال: کشیدن مستطیل با طول و عرضی که کاربر میده؟؟



sara1368
پنج شنبه 06 آبان 1389, 09:22 صبح
سلام دوستان..
لطفا کمکم کنین میخوام دوتا تکست باکس توی فرمم بذارم که یکی طول و یکی عرض باشه و بعد ز اینکه کاربر طول و عرض مورد نظرشو داخل تکست باکس زد بعد از زدن دکمه اون مستطیل رسم بشه.
میدونم چه جوری میشه تویخوده برنامه اندازه ها رو تعریف کرد اما میخوام حتما این اندازه از کاربر گرفته بشه بعد رسم بشه.:چشمک:
ممنون از همگی

ali_najari
پنج شنبه 06 آبان 1389, 09:55 صبح
دوست عزيز اميد وارم كه منظورتون رو درست فهميده باشم

يه مثال براتون آماده كرم

Mani_rf
پنج شنبه 06 آبان 1389, 09:58 صبح
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim G As Graphics = Me.CreateGraphics
Dim X As Integer = Val(TextBox2.Text)
Dim Y As Integer = Val(TextBox3.Text)
G.DrawRectangle(Pens.Blue, 100, 100, X, Y)
End Sub

sara1368
پنج شنبه 06 آبان 1389, 10:41 صبح
ممنون
حالا چه جوری کاربر میتونه یه خط داخل این مستطیل بکشه؟

ali_najari
پنج شنبه 06 آبان 1389, 11:45 صبح
خود كاربر اينكارو بكنه؟
با كشيدن موس؟

ali_najari
پنج شنبه 06 آبان 1389, 14:55 عصر
دوست عزيز اين هم يه نمونه خيلي ساده واسه كاري كه شما ميخوايد انجام بديد
اميد وارم به كارتون بياد



Dim X, Y, _X, _Y As Integer
Dim Clicks As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "" And TextBox2.Text <> "" Then
Dim Graphic As Graphics = MyBase.CreateGraphics
Graphic.FillRectangle(Brushes.SpringGreen, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
Graphic.DrawRectangle(Pens.Black, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
Graphic.Dispose()
End If
End Sub
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Select Case Clicks
Case 0
X = e.X
Y = e.Y
Clicks = 1
Case 1
_X = e.X
_Y = e.Y
Clicks = 0
End Select
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Clicks = 1 Then
_X = e.X
_Y = e.Y
Line()
End If
End Sub
Private Sub Line()

Dim Graphic As Graphics = MyBase.CreateGraphics
Graphic.Clear(Me.BackColor)
If TextBox1.Text <> "" And TextBox2.Text <> "" Then
Graphic.FillRectangle(Brushes.SpringGreen, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
Graphic.DrawRectangle(Pens.Black, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
End If
Graphic.DrawLine(Pens.Red, X, Y, _X, _Y)
Graphic.Dispose()
End Sub

ali_najari
جمعه 07 آبان 1389, 14:38 عصر
Dim Col As New Collection
Dim Clicks As Int16
Dim X, Y, _X, _Y As Integer

Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

Select Case Clicks
Case 0
X = e.X
Y = e.Y
Clicks = 1
Case 1
_X = e.X
_Y = e.Y
Clicks = 0
Col.Add(X & "," & Y & "," & _X & "," & _Y)
End Select

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

If Clicks = 1 Then
_X = e.X
_Y = e.Y
Line()
End If

End Sub

Private Sub Line()

Dim Graphic As Graphics = MyBase.CreateGraphics
Graphic.Clear(Me.BackColor)

Dim Sp()

For i = 1 To Col.Count
Sp = Split(Col.Item(i), ",")
Graphic.DrawLine(Pens.Red, CInt(Sp(0)), CInt(Sp(1)), CInt(Sp(2)), CInt(Sp(3)))
Next

Graphic.DrawLine(Pens.Blue, X, Y, _X, _Y)
Graphic.Dispose()

End Sub