定義好三角形的三個(gè)點(diǎn),用line畫線連接即可。
站在用戶的角度思考問題,與客戶深入溝通,找到白塔網(wǎng)站設(shè)計(jì)與白塔網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:做網(wǎng)站、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋白塔地區(qū)。
示例如下:
Private?Sub?Form_Load()
Me.AutoRedraw?=?True
Dim?x?As?Integer
Dim?y?As?Integer
CurrentX?=?1500
CurrentY?=?500
Line?-(3000,?2000),?RGB(0,?0,?255)
Line?-(1500,?2000),?RGB(0,?0,?255)
Line?-(1500,?500),?RGB(0,?0,?255)
End?Sub
運(yùn)行效果:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim g As Graphics = PictureBox1.CreateGraphics
Dim hs As HatchStyle = HatchStyle.Cross
Dim sb As HatchBrush = New HatchBrush(hs, Color.Black, Color.White)
Dim p(3) As Point
p(0).X = 100
p(0).Y = 50
p(1).X = 0
p(1).Y = 100
p(2).X = 200
p(2).Y = 100
p(3).X = 100
p(3).Y = 50
g.FillPolygon(sb, p)
g.DrawPolygon(Pens.Black, p)
End Sub
End Class
Dim a, b, c, s, p As Single
a = Val(InputBox("請輸入三角形邊長a"))
b = Val(InputBox("請輸入三角形邊長b"))
c = Val(InputBox("請輸入三角形邊長c"))
If a + b = c Or b + c = a Or c + a = b Then
MsgBox("這樣的三角形不存在")
Else
If a = b Or b = c Or c = a Then
MsgBox("這是一個(gè)等腰三角形")
End If
If a = b = c Then
MsgBox("這是一個(gè)等邊三角形")
End If
If a ^ 2 + b ^ 2 = c ^ 2 Or b ^ 2 + c ^ 2 = a ^ 2 Or c ^ 2 + a ^ 2 = b ^ 2 Then
MsgBox("這是一個(gè)直角三角形")
End If
p = (a + b + c) / 2
s = Math.Sqrt(p * (p - a) * (p - b) * (p - c))
MsgBox("這個(gè)三角形的面積是" s)
End If
End Sub
VB系統(tǒng)的坐標(biāo)原點(diǎn)在左上角,X軸的正方向是水平向右,而Y軸的正方向是垂直向下。所以,要繪制三角函數(shù)的曲線,自己可以通過改變點(diǎn)坐標(biāo)的方法來實(shí)現(xiàn),當(dāng)然,VB.NET提供了相應(yīng)的方法可以來實(shí)現(xiàn)坐標(biāo)變換,也可以通過VB.Net的Graphics類提供的平移、旋轉(zhuǎn)等轉(zhuǎn)換來實(shí)現(xiàn)。
下面是我通過自己變換實(shí)現(xiàn)的示例,提供參考;我的環(huán)境是VB.NET 2010
Imports System.Math
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
? '1,獲得一個(gè)Graphics對象
? Dim MyGraphics As Graphics
? MyGraphics = PictureBox1.CreateGraphics
? '2,定義一個(gè)Pen對象,用于繪制圖形(輪廓線)
? Dim MyPen As New Pen(Color.Black, 1)
? '3,定義一個(gè)Brush對象,用于填充圖形(如果需要填充的話)
? Dim MyBrush As New SolidBrush(Color.Orange)
? MyGraphics.DrawLine(MyPen, 0, 200, 700, 200)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
? '1,獲得一個(gè)Graphics對象
? Dim MyGraphics As Graphics
? MyGraphics = PictureBox1.CreateGraphics
? '2,定義一個(gè)Pen對象,用于繪制圖形(輪廓線)
? Dim MyPen As New Pen(Color.Black, 1)
? '3,定義一個(gè)Brush對象,用于填充圖形(如果需要填充的話)
? Dim MyBrush As New SolidBrush(Color.Orange)
? '聲明橫向和縱向比例變量
? Dim Heng As Integer = 20
? Dim Zong As Integer = 50
? '先獲得正弦值,保存到點(diǎn)坐標(biāo)數(shù)組
? Dim MyPoints(700) As Point
? Dim i As Integer
? For i = 0 To 700
? ? ? MyPoints(i) = New Point(i * Heng, 200 + Sin(i) * Zong)
? Next
? '采用繪制光滑線連接點(diǎn)的方式繪制曲線
? MyGraphics.DrawCurve(MyPen, MyPoints)
End Sub
End Class
顯示的效果圖:
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim n As Integer, i As Integer, j As Integer, a(,) As Integer
n = 10
ReDim a(n + 1, n + 1)
For i = 1 To n + 1
a(i, 1) = 1 : a(i, i) = 1 : Next i
For i = 3 To n + 1
For j = 2 To i - 1
a(i, j) = a(i - 1, j - 1) + a(i - 1, j)
Next j, i
For i = 1 To n + 1
For j = 1 To i
TextBox1.AppendText(Space(4 - Len(Trim(Str(a(i, j))))) Trim(Str(a(i, j))))
Next j
TextBox1.AppendText(vbCrLf)
Next i
End Sub
End Class,9,
xixihahano1 舉報(bào)
謝謝了,但是你寫的代碼可以輸出多少行?多久會溢出了
舉報(bào) ccddty
沒試過,你可以試試,將n的值加大 當(dāng)n》16的時(shí)候就顯示“參數(shù)“Number”必須大于或等于 0?!绷?有沒有辦法解決?,