vb空心菱形求助 20
【实验题5-3】用Print方法、文本框和标签框输出菱形图案,比较它们的不同用法,运行结果见图。程序启动时,通过弹出的输入对话窗口输入窗体中显示的菱形图案的顶点列数,则窗...
【实验题5-3】用Print方法、文本框和标签框输出菱形图案,比较它们的不同用法,运行结果见图。程序启动时,通过弹出的输入对话窗口输入窗体中显示的菱形图案的顶点列数,则窗体中显示菱形图案;点击文本框或标签框时在文本框或标签框中也显示菱形图案,初始界面见图5-4。(提示:①文本框设置多行显示属性Multiline 为 True。②文本框的换行用Chr(13) & Chr(10)实现。③标签框的换行用Chr(13) 实现。④为了区分窗体上的菱形和标签框中的菱形,将标签设为有边框。)
*
* *
*
依次类推 展开
*
* *
*
依次类推 展开
1个回答
展开全部
把下面代码保存成form1.frm文件,双击并运行:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6360
ClientLeft = 60
ClientTop = 450
ClientWidth = 9915
LinkTopic = "Form1"
ScaleHeight = 6360
ScaleWidth = 9915
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 2655
Left = 4920
MultiLine = -1 'True
TabIndex = 1
Text = "Form1.frx":0000
Top = 3600
Width = 3975
End
Begin VB.Label Label2
Caption = "点击窗体也会显示,不知道为什么label1显示有问题"
Height = 735
Left = 3000
TabIndex = 2
Top = 3240
Width = 1815
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
Height = 3015
Left = 4920
TabIndex = 0
Top = 240
Width = 3975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim iCols As Integer
Dim str As String
Private Sub Form_Click()
MsgBox str
End Sub
Private Sub Form_Load()
Me.Show
iCols = InputBox("输入顶点列数,只能为奇数:")
str = drow(iCols)
Print str
End Sub
Private Function drow(iCols As Integer) As String
Dim s As String, k As Integer
If iCols Mod 2 = 0 Or iCols < 3 Then
MsgBox "输入数值非法"
Exit Function
End If
s = s & Space((iCols - 1) / 2) & "*" & Space((iCols - 1) / 2) & vbCrLf
For i = 3 To iCols Step 2
s = s & Space((iCols - i) / 2) & "*" & Space(i - 2) & "*" & Space((iCols - i) / 2) & vbCrLf
Next
For i = iCols - 2 To 3 Step -2
s = s & Space((iCols - i) / 2) & "*" & Space(i - 2) & "*" & Space((iCols - i) / 2) & vbCrLf
Next
s = s & Space((iCols - 1) / 2) & "*" & Space((iCols - 1) / 2) & vbCrLf
drow = s
End Function
Private Sub Label1_Click()
'此图形没问,是label显示有问题
Label1.Caption = str
End Sub
Private Sub Text1_Click()
Text1.Text = str
End Sub
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6360
ClientLeft = 60
ClientTop = 450
ClientWidth = 9915
LinkTopic = "Form1"
ScaleHeight = 6360
ScaleWidth = 9915
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 2655
Left = 4920
MultiLine = -1 'True
TabIndex = 1
Text = "Form1.frx":0000
Top = 3600
Width = 3975
End
Begin VB.Label Label2
Caption = "点击窗体也会显示,不知道为什么label1显示有问题"
Height = 735
Left = 3000
TabIndex = 2
Top = 3240
Width = 1815
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
Height = 3015
Left = 4920
TabIndex = 0
Top = 240
Width = 3975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim iCols As Integer
Dim str As String
Private Sub Form_Click()
MsgBox str
End Sub
Private Sub Form_Load()
Me.Show
iCols = InputBox("输入顶点列数,只能为奇数:")
str = drow(iCols)
Print str
End Sub
Private Function drow(iCols As Integer) As String
Dim s As String, k As Integer
If iCols Mod 2 = 0 Or iCols < 3 Then
MsgBox "输入数值非法"
Exit Function
End If
s = s & Space((iCols - 1) / 2) & "*" & Space((iCols - 1) / 2) & vbCrLf
For i = 3 To iCols Step 2
s = s & Space((iCols - i) / 2) & "*" & Space(i - 2) & "*" & Space((iCols - i) / 2) & vbCrLf
Next
For i = iCols - 2 To 3 Step -2
s = s & Space((iCols - i) / 2) & "*" & Space(i - 2) & "*" & Space((iCols - i) / 2) & vbCrLf
Next
s = s & Space((iCols - 1) / 2) & "*" & Space((iCols - 1) / 2) & vbCrLf
drow = s
End Function
Private Sub Label1_Click()
'此图形没问,是label显示有问题
Label1.Caption = str
End Sub
Private Sub Text1_Click()
Text1.Text = str
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询