今天宠物迷的小编给各位宠物饲养爱好者分享vb效果图的宠物知识,其中也会对使用VB循环语句分别输出下列图形(使用vb循环语句分别输出下列图形数据)进行专业的解释,如果能碰巧解决你现在面临的宠物相关问题,别忘了关注本站哦,现在我们开始吧!
最难的是第一个图形,代码如下: Private Sub Form_Load()Form1.ShowDim Att As StringFor i = 0 To 8Att = String(i * 2 + 1, "*")Print Space(9 - i) & AttNextFor i = 8 To 1 Step -1Att = String(i * 2 - 1, "*")Print Space(10 - i) & AttNextEnd Sub Form1.ShowDim Att As StringFor i = 0 To 8Att = String(i * 2 + 1, "*")Print Space(9 - i) & AttNextFor i = 9 To 0 Step -1Att = String(i * 2 + 1, "*")Print Space(9 - i) & AttNext 第二个图形 Private Sub Form_Load()Form1.ShowDim Att As StringFor i = 0 To 8Att = String(i * 2 + 1, "*")Print Space(9 - i) & AttNextEnd Sub第三个图形 Private Sub Form_Load()Form1.ShowDim Att As StringFor i = 0 To 9Print String(10, "*")NextEnd Sub 第四个图形 Private Sub Form_Load()Form1.ShowDim Att As StringFor i = 0 To 8Print String(i + 8, "*")NextEnd Sub
用vb编写一个点击按钮随机出现一张图片的软件,例如:窗体上一个picture1和command1的控件。 1、有四张图片,他们的后缀名不相同,用户可以问这样写: Dim a$(3) Private Sub Form_Load() Randomize a(0) = "D:\xuexi.gif" a(1) = "D:
用vb编写一个点击按钮随机出现一张图片的软件,例如:窗体上一个picture1和command1的控件。 1、有四张图片,他们的后缀名不相同,用户可以问这样写: Dim a$(3) Private Sub Form_Load() Randomize a(0) = "D:\xuexi.gif" a(1) = "D:\002.jpg" a(2) = "D:\房子.png" a(3) = "D:\4.jpg" End Sub Private Sub Command1_Click() Picture1.Picture = LoadPicture(a(Int(Rnd * 3))) End Sub 2、如果后缀名相同,且图片名称按顺序编号内并在程序目录下,用户可以容这样写: Private Sub Command1_Click() Picture1.Picture = LoadPicture(App.Path & "\" & Int(Rnd * 3) & ".jpg") End Sub 扩展资料: CommandButton命令按钮最常用的事件是鼠标点击(Click)事件,当点击按钮时,犹如发出了一道命令,而这也正是“命令按钮”这个说法的由来。 CommandButton 的主要属性列举:1、Cancel(取消)属性: 当一个按钮的 Cancel 属性设置为 True 时,按 ESC 键与单击此命令按钮的作用相同,因此,这个命令按钮被称为取消按钮。在一个窗体中,只允许一个命令按钮的 Cancel 属性为 True 。 2、Default(默认)属性: 当一个按钮的 Default 属性设置为 True 时,按回车键与单击此命令按钮的作用相同,因此,这个命令按钮被称为默认按钮。 与 Cancel 的设置一样,在一个窗体中,只允许一个命令按钮的 Default 属性设置为 True 。 3、Caption(标题)属性: 跟其他控件的 Caption 属性一样,都用来显示控件标题的属性。这里要强调的是,作为按钮控件,用户可以给按钮控件的 Caption 指定快捷方式。 参考资料来源:百度百科-命令按钮
2.jpg" a(2) = "D:\房子.png" a(3) = "D:.jpg" End Sub Private Sub Command1_Click() Picture1.Picture = LoadPicture(a(Int(Rnd * 3))) End Sub 2、如果后缀名相同,且图片名称按顺序编号内并在程序目录下,用户可以容这样写: Private Sub Command1_Click() Picture1.Picture = LoadPicture(App.Path & "\" & Int(Rnd * 3) & ".jpg") End Sub 扩展资料: CommandButton命令按钮最常用的事件是鼠标点击(Click)事件,当点击按钮时,犹如发出了一道命令,而这也正是“命令按钮”这个说法的由来。 CommandButton 的主要属性列举:1、Cancel(取消)属性: 当一个按钮的 Cancel 属性设置为 True 时,按 ESC 键与单击此命令按钮的作用相同,因此,这个命令按钮被称为取消按钮。在一个窗体中,只允许一个命令按钮的 Cancel 属性为 True 。 2、Default(默认)属性: 当一个按钮的 Default 属性设置为 True 时,按回车键与单击此命令按钮的作用相同,因此,这个命令按钮被称为默认按钮。 与 Cancel 的设置一样,在一个窗体中,只允许一个命令按钮的 Default 属性设置为 True 。 3、Caption(标题)属性: 跟其他控件的 Caption 属性一样,都用来显示控件标题的属性。这里要强调的是,作为按钮控件,用户可以给按钮控件的 Caption 指定快捷方式。 参考资料来源:百度百科-命令按钮int i, j, k;
if (D)
{
for (i = 0; i < N; i++)
{
for (j = 0; j < N - i - 1; j++)
cout << " ";
for (k = 0; k < 2 * i + 1; k++)
cout << C;
}
}
else
{
for (i = N - 1; i >= 0; i--)
{
for (j = 0; j < N - i - 1; j++)
cout << " ";
for (k = 0; k < 2 * i + 1; k++)
cout << C;
}
} 应该是这样吧,没编译过 你的不会是VB的吧
Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
End Sub
Private Sub Text1_Change()
If Val(Text1.Text) > HScroll1.Max Or Val(Text1.Text) < HScroll1.Min Or Text1.Text = "" Then
MsgBox "你输入的数据超出了滚动条滚动范围,请重新输入!!"
Else
HScroll1.Value = Val(Text1.Text)
End If
End Sub
直接粘贴复制过去 建一个滚动条 和 text 就可以直接用 刚刚运行过 没问题的 你试试 这绝对是本人自己做的 不存在 溢出问题 有问题 再联系我
'这个拿去试一试,两个时钟,两个图片框,自己设定图片框2的大小,比如让它和窗体一样大
'查一查PaintPicture的用法,就明白了
'去掉Picture2
Dim Pic_num As Long
Dim Pic_name() As String
Dim pic_star As Long
Dim p_width As Single
Dim p_height As Single
Dim bili_w As Single
Dim bili_h As Single
Dim v_mod As Long
Private Sub Form_Load()
Dim L_name As String
Pic_num = 0
ReDim Pic_name(Pic_num)
L_name = Dir(App.Path & "\pic\*.JPG")
Do While L_name ""
ReDim Preserve Pic_name(Pic_num)
Pic_name(Pic_num) = L_name
Pic_num = Pic_num + 1
L_name = Dir
Loop
L_name = Dir(App.Path & "\pic\*.BMP")
Do While L_name ""
ReDim Preserve Pic_name(Pic_num)
Pic_name(Pic_num) = L_name
Pic_num = Pic_num + 1
L_name = Dir
Loop
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture1.Visible = False
' Me.AutoSize = False
Me.AutoRedraw = True
Me.Visible = True
Timer1.Interval = 10
Timer1.Enabled = False
Timer2.Interval = 50
Timer2.Enabled = False
If Pic_num > 0 Then
Picture1.Picture = LoadPicture(App.Path & "\pic\" & Pic_name(0))
Me.PaintPicture Picture1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Timer1.Enabled = True
Timer1.Interval = 2000
Else
MsgBox ("没有图片显示!")
End If
End Sub
Private Sub Form_Resize()
Me.Width = Me.Width
Me.Height = Me.Width
Me.Top = 0
Me.Left = 0
End Sub
Private Sub Timer1_Timer()
Dim L_id As Long
Randomize
L_id = Int((Pic_num) * Rnd)
Picture1.Picture = LoadPicture(App.Path & "\pic\" & Pic_name(L_id))
bili_w = Picture1.ScaleWidth / Me.ScaleWidth
bili_h = Picture1.ScaleHeight / Me.ScaleHeight
p_width = Me.Width / 100
p_height = Me.Height / 100
pic_star = 0
Randomize
v_mod = Int(10 * Rnd)
'v_mod = 9'取消单引号并修改常数数可看单一效果
Timer1.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub Timer2_Timer()
If pic_star < 101 Then
pic_star = pic_star + 1
Select Case v_mod
Case 0
Me.PaintPicture Picture1.Picture, 0, 0, Me.Width, pic_star * p_height, 0, 0, Picture1.Width, bili_h * pic_star * p_height '从上向下
Case 1
Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, Me.Height, 0, 0, bili_w * pic_star * p_width, Picture1.Height '从左向右
Case 2
Me.PaintPicture Picture1.Picture, 0, 0, Me.Width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '压缩的从上向下
Case 3
Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, Me.Height, 0, 0, Picture1.Width, Picture1.Height '压缩的从左向右
Case 4
Me.PaintPicture Picture1.Picture, 0, 0, pic_star * p_width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '压缩的从左上向右下
Case 5
Me.PaintPicture Picture1.Picture, Me.Width - pic_star * p_width, Me.Height - pic_star * p_height, pic_star * p_width, pic_star * p_height, 0, 0, Picture1.Width, Picture1.Height '压缩的从右下向左上
Case 6
Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, 0, pic_star * p_width / 2, Me.Height, 0, 0, Picture1.Width / 2, Picture1.Height '压缩的从中向左
Me.PaintPicture Picture1.Picture, Me.Width / 2, 0, pic_star * p_width, Me.Height, Picture1.Width / 2, 0, Picture1.Width, Picture1.Height '压缩的从中向右
Case 7
Me.PaintPicture Picture1.Picture, 0, Me.Height / 2 - pic_star * p_height / 2, Me.Width, pic_star * p_height / 2, 0, 0, Picture1.Width, Picture1.Height / 2 '压缩的从中向上
Me.PaintPicture Picture1.Picture, 0, Me.Height / 2, Me.Width, pic_star * p_height, 0, Picture1.Height / 2, Picture1.Width, Picture1.Height '压缩的从中向下
Case 8
Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, Me.Height / 2 - pic_star * p_height / 2, pic_star * p_width / 2, pic_star * p_height / 2, 0, 0, Picture1.Width / 2, Picture1.Height / 2 '压缩的从中向左上
Me.PaintPicture Picture1.Picture, Me.Width / 2, Me.Height / 2, pic_star * p_width, pic_star * p_height, Picture1.Width / 2, Picture1.Height / 2, Picture1.Width, Picture1.Height '压缩的从中向右下
Me.PaintPicture Picture1.Picture, Me.Width / 2, Me.Height / 2 - pic_star * p_height / 2, pic_star * p_width / 2, pic_star * p_height / 2, Picture1.Width / 2, 0, Picture1.Width / 2, Picture1.Height / 2 '压缩的从中向右上
Me.PaintPicture Picture1.Picture, Me.Width / 2 - pic_star * p_width / 2, Me.Height / 2, pic_star * p_width / 2, pic_star * p_height / 2, 0, Picture1.Height / 2, Picture1.Width / 2, Picture1.Height / 2 '压缩的从中向左下
Case 9
For k = 0 To 9
Me.PaintPicture Picture1.Picture, 0, k * Me.Height / 10, Me.Width, 5 * pic_star * p_height / 10, 0, k * (Picture1.Height / 10), Picture1.Width, (Picture1.Height / 10) '水平百叶窗
Next
If pic_star = 21 Then
pic_star = 101
End If
End Select
Else
pic_star = 0
Timer1.Enabled = True
Me.PaintPicture Picture1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
Timer2.Enabled = False
End If
End Sub
'这回做了9个,应该明白了吧,其实你第一回的5分也应该给选我,估计是你没明白用法>
下面几行代码即可达到你要的效果。
(如果是控件数组,请自行修改)
Private Sub Image1_Click()
Dim i
Image1.BorderStyle = Abs(Image1.BorderStyle - 1)
i = Timer
Do While Timer - i < 0.2
DoEvents
Loop
Image1.BorderStyle = Abs(Image1.BorderStyle - 1)
End Sub
用point 方法太慢了,还是用api的getDIBits和setDIBits吧,彩图转灰度图的代码如下: Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BitMapInfo, ByVal wUsage As Long) As Long Private Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BitMapInfo, ByVal wUsage As Long) As Long Private Type BitMapInfoHeader ''文件信息头——BITMAPINFOHEADER biSize As Long biWidth As Long biHeight As Long biPlanes As Integer biBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long biClrImportant As Long End Type Private Type RGBQuad rgbBlue As Byte rgbGreen As Byte rgbRed As Byte ''rgbReserved As Byte End Type Private Type BitMapInfo bmiHeader As BitMapInfoHeader bmiColors As RGBQuad End Type Private Sub Command1_Click() Dim ix As Integer Dim iy As Integer Dim iWidth As Integer '以像素为单位的图形宽度 Dim iHeight As Integer '以像素为单位的图形高度 Dim bytGray As Byte Dim bytThreshold As Byte Dim bits() As Byte '三维数组,用于获取原彩**像中各像素的RGB数值以及存放转化后的灰度值 Dim bitsBW() As Byte '三维数组,用于存放转化为黑白图后各像素的值 '获取图形的宽度和高度 iWidth = Picture1.ScaleWidth / Screen.TwipsPerPixelX iHeight = Picture1.ScaleHeight / Screen.TwipsPerPixelY Picture1.Picture = Picture1.Image '创建并初始化一个bitMapInfo自定义类型 Dim bi24BitInfo As BitMapInfo With bi24BitInfo.bmiHeader .biBitCount = 32 .biCompression = 0& .biPlanes = 1 .biSize = Len(bi24BitInfo.bmiHeader) .biWidth = iWidth .biHeight = Picture1.ScaleHeight / Screen.TwipsPerPixelY End With '重新定义数组大小 ReDim bits(3, 0 To iWidth, 0 To iHeight) As Byte ReDim bitsBW(3, 0 To iWidth, 0 To iHeight) As Byte '使用GetDIBits方法一次性获取picture1中各点的rgb值,比point方法或getPixel函数逐像素获取像素rgb要快出一个数量级 lrtn = GetDIBits(Picture1.hdc, Picture1.Picture.Handle, 0&, iHeight, bits(0, 0, 0), bi24BitInfo, 0&) '数组的三个维度分别代表像素的RGB分量、以图形左下角为**的X和Y坐标。 '具体说来,这时bits(0,2,3)代表从图形左下角数起横向第2个纵向第3个像素的Blue值,而bits(1,2,3)和bits(2,2,3)分别的Green值和Red值. bytThreshold = 128 '这里定义转换为黑白图像时的阈值为128,即灰色亮度大于128的像素转为白色,小于128的像素转为黑的,此值可根据需要修改为0-255之前任意数值 For ix = 0 To iWidth For iy = 0 To iHeight '***********RGB转为灰度的算法有多种,这里给出常见的两种******* 'bytGray = bits(0, ix, iy) * 0.11 + bits(1, ix, iy) * 0.59 + bits(2, ix, iy) * 0.3 '这是传统的根据三原色亮度加权得到灰阶的算法 bytGray = (bits(0, ix, iy) ^ 2.2 * 0.0722 + bits(1, ix, iy) ^ 2.2 * 0.7152 + bits(2, ix, iy) ^ 2.2 * 0.2126) ^ (1 / 2.2) '这是简化 sRGB IEC61966-2.1 [gamma=2.20],有点类似于photoshop中所用的算法 bits(0, ix, iy) = bytGray bits(1, ix, iy) = bytGray bits(2, ix, iy) = bytGray '*********转为黑白图像******** If bits(0, ix, iy) < bytThreshold Then bitsBW(0, ix, iy) = 0 bitsBW(1, ix, iy) = 0 bitsBW(2, ix, iy) = 0 Else bitsBW(0, ix, iy) = 255 bitsBW(1, ix, iy) = 255 bitsBW(2, ix, iy) = 255 End If Next Next '将灰度图显示到picture2中 Picture2.Picture = Picture2.Image '如果picture2的picture属性为空,需要在setDIBits之前将其picture属性设置一下,否则无法显示出图形 SetDIBits Picture2.hdc, Picture2.Picture.Handle, 0&, iHeight, bits(0, 0, 0), bi24BitInfo, 0& Picture2.Picture = Picture2.Image '将黑白图显示到picture3中 Picture3.Picture = Picture3.Image SetDIBits Picture3.hdc, Picture3.Picture.Handle, 0&, iHeight, bitsBW(0, 0, 0), bi24BitInfo, 0& Picture3.Picture = Picture3.Image End Sub 代码运行很快,如图所示图片基本可瞬间完成
使用ForeColor属性改变颜色
如改变text1文本框的文字颜色:
text1.forecolor=vbred '红色 绿色vbgreen 蓝色vbblue 等等
如果是标签控件 例如Label
则使用label1.forecolor=vb颜色 以此类推即可
1、首先打开VB,然后在VB窗体上添加一个文本框,如图。 2、然后点击这个添加的文本框,接着在右侧的一个窗口中,设置他的相关名称和数值,然后将文本内容清空。如图。 3、紧接着在窗体上面,再添加一个水平滚动条,如图。 4、然后单击这个水平滚动条,设置名称和数值,将Min设置为0,Max设置为100。largechange设置为5,Smallchange设置为2,如图。 5、然后双击这个文本框,将会弹出页面,便可以编辑相应的代码了,如图。 6、最后运行程序,在文本框中输入不同的数值(0-100以内的数值),观察滚动条的滚动框位置,完成效果图。
本文由宠物迷 百科常识栏目发布,非常欢迎各位朋友分享到个人朋友圈,但转载请说明文章出处“使用VB循环语句分别输出下列图形”
上一篇
卤水的隔夜处理和保存?
下一篇
9月英文怎么写