VB小程序

合集下载

VB小程序

VB小程序

1、VB定时器'*************************************************************'新建一个窗体,放两个控件:label和timer'*************************************************************Public hor As LongPublic minu, sec As IntegerPrivate Sub Form_Load()'设置计时器时间间隔为1秒。

'考虑到Sub Timer1_Timer()中判断等操作要花时间,所以Timer1.Interval设为994 Timer1.Interval = 994Dim longTime, tmp As Long'********************************longTime = 65'时间值,要你自己从数据库取,我就不写了!'********************************'初始化显示时间hor = CLng(longTime / 3600 - 0.5)'小时数tmp = longTime - 3600 * hor '剩余秒数minu = CLng(tmp / 60 - 0.5) '分钟数tmp = tmp - 60 * minu'剩余秒数sec = tmp'秒数Label1.Caption = CStr(hor) + ":" + Format(CStr(minu), "##00") + ":" + Format(CStr(sec), "##00") End SubPrivate Sub Timer1_Timer()If sec = 0 ThenIf minu = 0 ThenIf hor = 0 ThenExit SubElsehor = hor - 1End Ifminu = 59Elseminu = minu - 1sec = 59End IfElsesec = sec - 1End IfLabel1.Caption = CStr(hor) + ":" + Format(CStr(minu), "##00") + ":" + Format(CStr(sec), "##00") End Sub2、VB倒计时Dim h, m, s As IntegerPrivate Sub Command1_Click()Label1.Visible = FalseText1.Visible = TrueIf Command1.Caption = "倒计时" Then Timer1.Enabled = TrueCommand1.Caption = "停止"Command2.Enabled = FalseElseTimer1.Enabled = FalseCommand1.Caption = "倒计时"Command2.Caption = "重设倒计时" Command2.Enabled = TrueEnd IfEnd SubPrivate Sub Command2_Click()If Command2.Caption = "重设倒计时" Then Call againCommand1.Enabled = TrueEnd IfEnd SubPrivate Sub Command3_Click()a = MsgBox("你确定要退出嗎")EndEnd SubPrivate Sub Form_Load()ClsText1.Text = ""a = MsgBox("以下是一個倒計時程序,請按以下要求輸入你要倒计的时间")h = Val(InputBox("请输入倒计时的,小時数,若无填0", "小時/输入", 0))m = Val(InputBox("请输入倒计时的,分钟数,若无填0", "小時/输入", 0))s = Val(InputBox("请输入倒计时的,秒数,若无填0", "小時/输入", 0))Label1.Caption = "你输入的时间是:" & Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & "如果沒有错误请点击倒计时按纽"Text1.Visible = FalseEnd SubPrivate Sub Timer1_Timer()If s > 0 Thens = s - 1End IfIf s < 1 And m > 0 Thenm = m - 1s = 60End IfIf m < 1 And s = 0 And h > 0 Thenh = h - 1m = 60End IfIf h < 0 Thenh = 0End IfIf m < 0 Thenm = 0End IfText1.Text = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00")If h = 0 And m = 0 And s = 0 ThenText1.Text = "時間到了"Command1.Caption = "倒计时"Command1.Enabled = FalseTimer1.Enabled = FalseCommand2.Enabled = TrueEnd IfEnd SubSub again()ClsText1.Text = ""a = MsgBox("以下是一個倒計時程序,請按以下要求輸入你要倒计的时间")h = Val(InputBox("请输入倒计时的,小時数,若无填0", "小時/输入", 0))m = Val(InputBox("请输入倒计时的,分钟数,若无填0", "小時/输入", 0))s = Val(InputBox("请输入倒计时的,秒数,若无填0", "小時/输入", 0))Label1.Caption = "你输入的时间是:" & Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00") & "如果沒有错误请点击倒计时按纽"Text1.Visible = FalseLabel1.Visible = TrueEnd Sub3、VB应该怎样取得本机上网用的动态IP应该是电信局动态分配给宽带用户的那种动态IP。

使用VB设计一个简单的小程序计算圆的面积

使用VB设计一个简单的小程序计算圆的面积

使用VB设计一个简单的小程序计算圆的面积下面是一个使用VB设计的简单程序,用于计算圆的面积:
Private Sub CalculateArea_Click
Dim radius As Double
Dim area As Double
'获取用户输入的半径值
radius = CDbl(InputBox("请输入圆的半径:"))
area = Math.PI * radius * radius
'显示计算结果
MsgBox "圆的面积为:" & area
End Sub
然后,程序使用Math.PI常量和半径值来计算圆的面积,将结果保存到area变量中。

最后,通过MsgBox函数将面积值以提示框的形式显示出来。

需要注意的是,Math.PI是VB中定义的一个常量,它表示圆周率的值。

对于这个简单的程序,可能描述不到1200字以上。

但是,可以在设计程序时添加更多的功能和逻辑,以丰富程序的功能和交互性。

例如,可以添加错误处理来处理用户输入错误的情况,或者可以添加对输入值的验证,确保输入的是有效的半径值等等。

另外,可以通过添加更多控件和功能,如文本框、滑动条等,来实现更复杂的计算功能。

例如,可以添加一个滑动条控件来调整半径值,实时显示面积的变化。

希望以上内容对您有所帮助。

如果您有其他问题,欢迎继续提问。

vb小程序设计实例

vb小程序设计实例

VB小程序设计实例引言VB(Visual Basic)是一种广泛应用于Windows平台的编程语言,它具有简单易学的特点,因此非常适合初学者入门。

本文将以一个实际的VB小程序设计实例为例,介绍如何使用VB语言进行简单的程序开发。

项目背景我们的目标是创建一个简单的VB小程序,用于管理学生信息。

该程序将允许用户添加、删除和修改学生的基本信息,例如姓名、年龄和班级。

此外,用户还可以根据特定条件检索学生信息,并显示学生列表。

设计步骤1. 创建VB项目首先,打开Visual Studio并选择“创建新项目”,然后选择“Visual Basic”作为项目类型。

接下来,选择“Windows Forms应用程序”作为模板,并给项目命名。

点击“确定”按钮以创建新的VB项目。

2. 设计用户界面在VB中,用户界面是通过拖放控件来创建的。

在“工具箱”中选择所需的控件,例如按钮、文本框和标签,并将它们放置在窗体上。

使用控件的属性面板可以更改它们的外观和行为。

3. 编写代码现在,我们需要为各个控件添加相应的事件处理程序。

例如,当用户点击一个按钮时,我们需要执行特定的操作。

首先,选择要添加事件处理程序的控件,然后在属性面板中找到“事件”部分。

在相应的事件上双击以创建并打开处理程序。

4. 实现学生信息管理功能在代码中,我们需要定义学生类和学生信息管理类。

学生类包含学生的属性,例如姓名、年龄和班级。

学生信息管理类包含对学生信息进行增删改查的方法。

我们可以使用集合类来存储学生对象,并使用LINQ进行查询操作。

在事件处理程序中调用适当的方法以实现相应的功能。

5. 运行和测试程序在完成代码的编写之后,我们可以点击“运行”按钮来启动程序。

通过与程序交互,测试各个功能是否按预期工作。

如果发现问题,可以调试程序并对代码进行调整。

6. 部署和发布程序一旦我们满意了程序的功能和性能,我们可以将程序部署和发布给其他人使用。

在Visual Studio中,选择“生成”菜单并点击“发布”选项。

VB程序代码(简单小程序)

VB程序代码(简单小程序)

VB程序代码(简单小程序) Option Explicit
Private Sub btnCalculate_Click()
'按钮点击事件,计算两个数的和
'声明变量
Dim num1 As Double
Dim num2 As Double
Dim result As Double
'获取用户输入的数字
num1 = Val(txtNum1.Text)
num2 = Val(txtNum2.Text)
'计算和
result = num1 + num2
'将计算结果展示给用户
lblResult.Caption = "计算结果:" & result
End Sub
Private Sub Form_Load()
'窗体加载事件,初始化窗体
'设置窗体标题
Me.Caption = "简单计算器"
'设置标签的默认文本
lblNum1.Caption = "请输入第一个数:"
lblNum2.Caption = "请输入第二个数:"
lblResult.Caption = ""
如上所示,这是一个简单的VB程序,包含一个窗体和三个按钮,分别用于计算两个
数的和、清空所有输入框和标签的内容以及退出程序。

用户可以在两个文本框中输入数字,点击计算按钮后,程序会将两个数字相加并将结果展示给用户。

如果用户想重新计算,可
以点击清空按钮清除所有输入框和标签的内容,重新输入参数。

vb小游戏

vb小游戏

VB小游戏简介VB小游戏是一款基于Visual Basic(VB)编程语言的游戏开发平台。

它提供了一系列的工具和框架,让开发者能够快速地创建各种类型的小游戏。

这些游戏可以运行在Windows操作系统上,并且具有良好的用户界面和交互性。

安装和设置安装Visual Studio要开始使用VB小游戏,首先需要安装Visual Studio开发环境。

Visual Studio 是一款强大的集成开发环境,支持多种编程语言,包括Visual Basic。

可以从Visual Studio官方网站上下载并安装该软件。

创建新项目安装完成后,打开Visual Studio并选择“新建项目”。

在项目模板中选择“Windows Forms App (.NET Framework)”模板,并为项目指定名称和存储位置。

点击“确定”按钮后,Visual Studio会自动生成一个新的VB游戏项目,并打开项目的主窗体。

添加游戏界面在VB小游戏中,游戏界面通常由一个或多个窗体组成。

可以通过使用Windows Forms Designer来设计游戏界面。

可以在工具箱中找到各种控件(例如按钮、标签、文本框等),并将其拖放到窗体上。

还可以设置控件的属性来定义其外观和行为。

添加游戏逻辑除了游戏界面外,还需要在VB小游戏中添加游戏的逻辑和交互性。

可以在窗体的代码文件中编写代码,来定义游戏逻辑和处理用户输入。

可以使用Visual Basic的各种语法和库函数来实现所需的功能,例如处理键盘事件、更新游戏状态、计算分数等。

编程示例以下是一个简单的VB小游戏示例,名为“猜数字”。

游戏要求玩家猜一个预先设定的数字,直到猜中为止。

```vb Public Class Form1 Dim targetNumber As Integer Dim tries As IntegerPrivate Sub Form1_Load(sender As Object, e As EventArgs) Handles MyB ase.LoadRandomize()targetNumber = CInt(Int((100 * Rnd()) + 1))tries = 0End SubPrivate Sub btnGuess_Click(sender As Object, e As EventArgs) Handles bt nGuess.ClickDim guess As Integer = CInt(txtGuess.Text)tries += 1If guess = targetNumber ThenMessageBox.Show(\。

vb源代码vb小程序:摄像头视频图像的监控、截图、录像(改进:第二页)

vb源代码vb小程序:摄像头视频图像的监控、截图、录像(改进:第二页)

vb源代码vb小程序:摄像头视频图像的监控、截图、录像(改进:第二页)Private Sub SetDir()Dim nStr As StringIf Trim(ctDir) = &quot;&quot; Then ctDir = App.Path &amp; &quot;\videos&quot; '如果路径不存在,用默认文件名 C:\CAPTURE.AVInStr = &quot;设置录像保存的文件夹。

&quot; &amp; vbCrLf &amp; &quot;输入“&lt;&gt;”表示使用默认文件夹:&quot; &amp; vbCrLf &amp; App.Path &amp;&quot;\videos&quot;nStr = Trim(InputBox(nStr, &quot;录像保存的文件夹&quot;, ctDir))If nStr = &quot;&quot; Then Exit SubctDir = nStrIf ctDir = &quot;&lt;&gt;&quot; Or ctDir = &quot;&lt;默认&gt;&quot; Then ctDir =&quot;&quot;End SubPrivate Sub SetFile()Dim nStr As String, nF As StringnF = String(255, &quot; &quot;)SendMessage ctCapWin, WM_Cap_File_Get_File, Len(nF), ByVal nFnF = GetStrLeft(nF, vbNullChar)If Trim(ctF) = &quot;&quot; Then ctF = &quot;&lt;默认&gt;&quot; '如果路径不存在,用默认文件名 C:\CAPTURE.AVInStr = &quot;设置录像保存的文件名(不带路径)。

VB小程序制作

VB小程序制作

VB程序设计8.1.1 实验目的1)掌握VB多重窗体程序的概念。

2)掌握多重窗体程序的设计方法。

3)复习各种控件的使用方法。

8。

1。

2实验内容采用多窗体技术编写程序,分别在不同的窗体上实现不同功能。

8。

1.3 实验步骤实验步骤如下:1)建立启动窗体界面与设置对象属性。

选择“新建"工程,进入窗体设计器,在窗体中添加命令按钮组Command1(0)~Command1(5),并修改属性如图8-1左所示.系统默认窗体Form1为启动窗体.2)添加窗体。

选择“工程"菜单,打开“添加窗体"对话框.按“打开”按钮,添加3个标准窗体Form2~Form4。

添加标准模块。

选择“工程”菜单,打开“添加模块”对话框。

按“打开”按钮,添加1个标准模块Module1。

图8—1 程序界面设计3)建立子窗体界面与设置对象属性.界面如图8-1所示,设置属性如表所示。

表8-1 Form1属性设置对象属性属性值说明Form1 Name Form1 启动窗体Caption Form1Command1(0)Caption Who are you?Command1(1)Caption gameCommand1(2)Caption writeboardCommand1(3)Caption calculatorCommand1(4) Caption byebyePicture1 autoredraw falseLabel1 caption Let's start a wonderfuljourney表8-2 Form2属性设置对象属性属性值说明Form2 Name Form2 输入个人资料窗口Caption Form2Label11 Caption nameLabel12 Caption genderLabel13 Caption Is that a girl?Fream1 Caption hobbiescommand caption okey表8—3 Form3属性设置表8-4 Form4属性设置表8-5 Form5属性设置表8-6 Form6属性设置4)编写代码。

VB代码VB小程序:实现USB摄像头视频图像的监控、截图、录像

VB代码VB小程序:实现USB摄像头视频图像的监控、截图、录像

VB代码VB小程序:实现USB摄像头视频图像的监控、截图、录像当前位置:首页&gt;VB 小程序&gt; 实现USB摄像头视频图像的监控、截图、录像54. 实现USB摄像头视频图像的监控、截图、录像本程序是“摄像头视频监控”的改进,仅用四个按钮实现对摄像头视频的监控、截图、录像,可以分别保存为图片文件和视频文件。

保存的视频文件可以用媒体播放机(Windows Media Player)、暴风影音等软件进行播放,轻松实现家庭录像制作。

利用电脑配备的 USB 摄像头进行视频控制,要用到两个 API 函数:capCreateCaptureWindow 和 SendMessage。

capCreateCaptureWindow 的作用是创建一个视频窗口,摄像头捕捉到的视频图像在此窗口内显示,函数返回值就是代表此窗口的句柄。

此函数的 VB 声明:Private Declare Function capCreateCaptureWindow Lib &quot;avicap32.dll&quot; Alias &quot;capCreateCaptureWindowA&quot; (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As LongDim ctCapWin As Long各参数意义如下:lpszWindowName 视频窗口的窗口标题dwStyle 窗口模式,设置值可用下面数值,也可组合使用:WS_Child:视频窗口是子窗口,位于应用程序主窗口内。

用vb做一个程序,表达自己的爱意

用vb做一个程序,表达自己的爱意

用Vb做一个小程序,情人节那天向“她(他)”表白吧!!!首先,你得打开vb这个软件,会有如下这么一个对话框
就选择第一个,然后进入,出现如下的界面
然后再选择红线处的工具
点击后,在如下界面拖画出一个文本框
然后再选择工具栏上的这个工具,点击后,同上一样,在界面上拖画,画两个
然后再在“标题栏名为Form1”这个窗体上双击鼠标左键,出现一个输入代码的框框
在里面输入
LABEL1.caption=”“
Command1.caption=”确定”
Command2.caption=”退出”
然后,点击关闭
再在界面上双击command1,进入后,在中中间输入LABEL1.caption=”I Love You”
然后,点击关闭
再在界面上双击command2,进入后,在中间输入end。

随后,在点击这个按钮
最后,要把这个保存,点击“文件”下的“生成工程1.exe”,然后保存在桌面即可。

当情人节当天,你就可以把这个小程序发给你心爱的她(他),让她(他)感动,感动吧!注:这中间的标点符号,均为英文状态下输入的
小女落樱。

人人都会用的VB游戏小程序代码

人人都会用的VB游戏小程序代码

人人都会用的VB游戏小程序代码人人都会用的 VB 游戏小程序代码3. 球来回弹在窗体上添加一shape 空间, shape 为circle ,计时器空间inteval=10 通用Dim bzPrivate Sub Timer1_Timer(If Shape1.Left >= Form1.ScaleWidth - Shape1.Width Then bz = 1 If Shape1.Left <= 0 Then bz = 0If bz = 0 Then Shape1.Left = Shape1.Left + 10If bz = 1 Then Shape1.Left = Shape1.Left - 10End Sub注意:bz 的使用(bz 为一临时标志,用于判断移动方向2. 六角星Dim i%, j%, k%For i = 1 To 10If i < 4 Or i > 6 ThenPrint Space(20 - i;For j = 1 To iPrint "○ ";Next jElsePrint Space(6 + i;For k = 14 - i To 1 Step -1 Print "○ ";Next kEnd IfPrintNext iFor i = 3 To 1 Step -1 Print Space(20 - i;For j = 1 To iPrint "○ ";Next jPrintNext i1. 空心三角形Dim i%, j%Print Space(20; "*"For i = 2 To 9Print Space(21 - i; "*"; Space(2 * i - 3; "*"NextPrint Space(10;For i = 1 To 10Print Space(1; "*";Next扩展程序Const n = 15Dim a(1 To n As IntegerDim i%, j%, t%RandomizeFor i = 1 To na(i = Int(100 * Rnd ' 生成 15个 0~100的随机整数存入数组 Next Print "排序前:"For i = 1 To nPrint a(i;NextPrintFor i = 1 To n - 1For j = i + 1 To nIf a(j < a(i Then t = a(j: a(j = a(i: a(i = tNextNextPrint "排序后:"For i = 1 To nPrint a(i;Next3. 球来回弹在窗体上添加一shape 空间, shape 为circle ,计时器空间inteval=10 通用Dim bzPrivate Sub Timer1_Timer(If Shape1.Left >= Form1.ScaleWidth - Shape1.Width Then bz = 1 If Shape1.Left <= 0 Then bz = 0If bz = 0 Then Shape1.Left = Shape1.Left + 10If bz = 1 Then Shape1.Left = Shape1.Left - 10End Sub注意:bz 的使用(bz 为一临时标志,用于判断移动方向4. 从大到小再从小到大变化在窗体添加一标签label1, autosize=true, caption="★ ", 添加一计时器空间timer1, inteval=100 通用:Dim bzPrivate Sub Timer1_Timer(If Label1.FontSize >= 72 Then bz = 1If Label1.FontSize <= 8 Then bz = 0If bz = 0 Then Label1.FontSize = Label1.FontSize + 2If bz = 1 Then Label1.FontSize = Label1.FontSize - 2End Sub5. 在 VB 中用画圆Dim x, y, i As SingleClsScale (-15, 15-(15, -15 ' 定义笛卡儿坐标系For i = 0 To 6.28 Step 0.05y = 10 * Sin(ix = 10 * Cos(iCurrentX = xCurrentY = yPrint "*"Next6. 四周循环移动创建一个窗体,在上面添加“开始”和“停止”两个按钮,添加一个计时器控件timer1 在窗体上添加一个 shape 控件,设置背景不透明,红色,调整大小程序代码如下:Option ExplicitDim bz%Private Sub Command1_Click( '开始按钮Timer1 = TrueEnd SubPrivate Sub Command2_Click( ' 停止按钮Timer1 = FalseEnd SubPrivate Sub Form_Load(Shape1.Left = 0Shape1.Top = 0Timer1 = FalseTimer1.Interval = 10End SubPrivate Sub Timer1_Timer(If Shape1.Left >= Form1.ScaleWidth - Shape1.Width And Shape1.Top <= 0 Then bz = 1If Shape1.Top >= Form1.ScaleHeight - Shape1.Height Then bz = 2If Shape1.Left <= 0 Then bz = 3If Shape1.Top <= 0 And Shape1.Left <= 0 Then bz = 0Select Case bzCase 0Shape1.Left = Shape1.Left + 10Case 1Shape1.Top = Shape1.Top + 10Case 2Shape1.Left = Shape1.Left - 10Case 3Shape1.Top = Shape1.Top - 10End SelectEnd Sub。

VB小程序代码实例

VB小程序代码实例

VB小程序代码实例VB小程序是一种基于Visual Basic语言开发的应用程序,它可以在Windows 操作系统上运行。

本文将为您提供一个VB小程序代码实例,帮助您了解如何编写和运行一个简单的VB小程序。

代码实例如下:```vbImports SystemPublic Class HelloWorldPublic Shared Sub Main()Console.WriteLine("Hello, World!")Console.ReadLine()End SubEnd Class```上述代码是一个经典的“Hello, World!”程序,它会在控制台输出一条问候语,并等待用户按下回车键。

下面是代码解释:- `Imports System`:这个语句告诉编译器我们将使用System命名空间中的类和方法。

- `Public Class HelloWorld`:这是一个公共类的声明,类名为HelloWorld。

- `Public Shared Sub Main()`:这是程序的入口点,它是一个公共静态方法,程序从这里开始执行。

- `Console.WriteLine("Hello, World!")`:这行代码会在控制台输出一条问候语。

- `Console.ReadLine()`:这行代码会等待用户按下回车键,以便程序暂停执行。

您可以将上述代码复制到一个文本编辑器中,并将文件保存为`.vb`扩展名。

然后,使用VB编译器将其编译为可执行文件,并在Windows操作系统上运行。

这个简单的VB小程序只是一个入门示例,您可以根据自己的需求和兴趣编写更复杂的VB小程序。

VB语言具有丰富的特性和功能,可以用于开发各种类型的应用程序,包括图形用户界面(GUI)应用程序、数据库应用程序、Web应用程序等。

希望这个VB小程序代码实例能够帮助您入门VB编程,并为您今后的学习和开发提供一些参考。

VB整人小程序

VB整人小程序

VB整人小程序代码Private Sub Command1_Click()MsgBox "进行测试前,请一定要照着提示上说的回答,可不要乱写,不然的话会让测试不准的!切记!现在放松一下,记住,写的时候应该完全是你的第一直觉!!!"MsgBox "这个测试源于印度的一个神秘的密教经典,当时发现它的人按照它说的做了,结果他的愿望在10分钟内就实现了!" MsgBox "这是一个非常奇妙的测试,不知道你做过没有,最好没有旁观者!我做了,非常准确,想不信邪都难!"t1 = "1.请输入你一个异性朋友的名字"t2 = "2.请再输入你一个异性朋友的名字"t3 = "3.输入你一个同性朋友的名字"t4 = "4.输入你第二个同性朋友的名字"t5 = "5.再输入你一个同性朋友的名字"t6 = "6.输入一首你喜欢的歌的名字"t7 = "7.输入另外一首歌的名字"t8 = "8.再输入一首歌的名字,请不要急噪,保持轻松的心态"t9 = "9.最后输入一首喜欢的歌名字"t10 = "10.输入一个你喜欢的幸运数字"t11 = "11.许下一个你的愿望"a1 = InputBox(t1)a2 = InputBox(t2)a3 = InputBox(t3)a4 = InputBox(t4)a5 = InputBox(t5)a6 = InputBox(t6)a7 = InputBox(t7)a8 = InputBox(t8)a9 = InputBox(t9)a10 = InputBox(t10)a11 = InputBox(t11)Form1.Print "在你心中"; a1; "占据着最重要的位置,你对"; a1; "的感觉用"; a6; "这首歌来形容再好不过了。

VB编写各种趣味小程序(附代码)

VB编写各种趣味小程序(附代码)

VB编写各种趣味小程序(附代码)一、鸟巢绘制二、加密三、解密四、蝴蝶飞舞五、文本编辑六、统计七、小球跳动八、计算器(彩票摇奖)九、学生信息录入十、矩阵转置十一、带有进度条的倒计时程序十二、加减乘除随机数题十三、计算器十四、抽奖一、鸟巢绘制Private Sub Form_Click()ClsDim r, xi, yi, xj, yj, x0, y0, aif As Singler = Form10.ScaleHeight / 2x0 = Form10.ScaleWidth / 2y0 = Form10.ScaleHeight / 2n = 16aif = 3.14159 * 2 / nFor i = 1 To nxi = r * Cos(i * aif) + x0yi = r * Sin(i * aif) + y0For j = i To nxj = r * Cos(j * aif) + x0yj = r * Sin(j * aif) + y0Line (xi, yi)-(xj, yj), QBColor(i - 1)PSet (xi, yi)Print i - 1Next jNext iEnd SubPrivate Sub Form_Load()Print "要求:";Print "1.将圆周等分成16份;"Print "2.每个等分点要标记成0-16的数字;" Print "3.按样本图的图案画图。

"End Sub附图:二、加密Function code(ByVal s$, ByVal key%) Dim c As String * 1, iAsc%code = ""For i = 1 To Len(s)c = Mid$(s, i, 1)Select Case cCase "A" To "Z"iAsc = Asc(c) + keyIf iAsc > Asc("Z") Then iAsc = iAsc - 26 code = code + Chr(iAsc)Case "a" To "z"iAsc = Asc(c) + keyIf iAsc > Asc("z") Then iAsc = iAsc - 26 code = code + Chr(iAsc)Case Elsecode = code + cEnd SelectNext iEnd FunctionPrivate Sub close_Click()Form11.HideForm1.ShowEnd SubPrivate Sub Jiami_Click()Text2 = code(Text1, 2)End SubPrivate Sub open_Click()CommonDialog1.Action = 1Text1.Text = ""Open CommonDialog1.FileName For Input As #1Dim counter As IntegerDim workarea(25000) As StringProgressBar1.min = LBound(workarea)ProgressBar1.max = UBound(workarea)ProgressBar1.Visible = TrueProgressBar1.Value = ProgressBar1.minFor counter = LBound(workarea) To UBound(workarea) workarea(counter) = "initial value " & counter ProgressBar1.Value = counterNext counterDo While Not EOF(1)Line Input #1, inputdataText1.Text = Text1.Text + inputdata + vbCrLfLoopClose #1End SubPrivate Sub save_Click()CommonDialog1.FileName = "a1.txt"CommonDialog1.DefaultExt = "txt"CommonDialog1.Action = 2Open CommonDialog1.FileName For Output As #1Print #1, Text2.TextClose #1End Sub三、解密Function UnCode(ByVal s$, ByVal key%)Dim c As String * 1, iAsc%UnCode = ""For i = 1 To Len(s)c = Mid$(s, i, 1)Select Case cCase "A" To "Z"iAsc = Asc("c") - keyIf iAsc < Asc("A") Then iAsc = iAsc + 26UnCode = UnCode + Chr(iAsc)Case "a" To "z"iAsc = Asc(c) - keyIf iAsc < Asc("a") Then iAsc = iAsc + 26UnCode = UnCode + Chr(iAsc)Case ElseUnCode = UnCode + cEnd SelectNext iEnd FunctionPrivate Sub close_Click()Form2.HideForm1.ShowEnd SubPrivate Sub Jiemi_Click()Text2 = UnCode(Text1, 2)End SubPrivate Sub open_Click()CommonDialog1.Action = 1Text1.Text = ""Open CommonDialog1.FileName For Input As #1Dim counter As IntegerDim workarea(25000) As StringProgressBar1.min = LBound(workarea) ProgressBar1.max = UBound(workarea) ProgressBar1.Visible = TrueProgressBar1.Value = ProgressBar1.minFor counter = LBound(workarea) To UBound(workarea) workarea(counter) = "initial value " & counter ProgressBar1.Value = counterNext counterDo While Not EOF(1)Line Input #1, inputdataText1.Text = Text1.Text + inputdata + vbCrLfLoopClose #1End SubPrivate Sub save_Click()CommonDialog1.FileName = "a.txt" CommonDialog1.DefaultExt = "txt" CommonDialog1.Action = 2Open CommonDialog1.FileName For Output As #1 Print #1, Text2.TextClose #1End Sub四、蝴蝶飞舞Private Sub Form_Load()Print "蝴蝶飞出窗体后重新定位到左下方再向右上方飞" End SubPrivate Sub Timer1_Timer()Static PickBmp As IntegerIf PickBmp = 0 ThenImage1.Picture = Image2.PicturePickBmp = 1ElseImage1.Picture = Image3.PicturePickBmp = 0End IfCall mymoveEnd SubSub mymove()Image1.Move Image1.Left + 40, Image1.Top - 25If Image1.Top <= 0 ThenImage1.Left = 0Image1.Top = 2325End IfEnd Sub图:五、文本编辑Private Sub Copy_Click()Clipboard.ClearClipboard.SetText RichTextBox1.SelTextEnd SubPrivate Sub Cut_Click()Clipboard.ClearClipboard.SetText RichTextBox1.SelTextRichTextBox1.SelText = ""End SubPrivate Sub Exit_Click()Form3.HideForm1.ShowEnd SubPrivate Sub Font_Click()CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects CommonDialog1.Action = 4RichTextBox1.FontName = CommonDialog1.FontName RichTextBox1.FontSize = CommonDialog1.FontSize RichTextBox1.FontBold = CommonDialog1.FontBold RichTextBox1.FontItalic = CommonDialog1.FontItalic RichTextBox1.FontStrikethru = CommonDialog1.FontStrikethru RichTextBox1.FontUnderline = CommonDialog1.FontUnderline RichTextBox1.ForeColor = CommonDialog1.ColorEnd SubPrivate Sub Form_Load()Print "注:"Print "1.'打开'对话框的初始文件夹应是所要打开文件所在的" Print "文件夹,将提供的xz.txt文件打开;"Print "2.要实现将选定的内容格式化,必须在工具箱中添加" Print "RichTextBox控件(Microsoft Rich Textbox Comtrol 6.0)" Print "并在帮助菜单中查阅其字体设置的相关属性。

VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径

VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径

VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径本小程序采用枚举进程的方法,显示所有进程,也能显示隐藏进程。

同时,能显示进程的完整路径。

有意思的是,一些已经结束的进程,同样可以显示。

以下是程序运行截图:''''以下是 VB6 代码,在 WinXP 调试通过'需在窗体放置以下 5 个控件,不必设置任何属性,全部采用默认设置:' Command1、List1、Check1、Timer1、Label1'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.htmlPrivate Type tyProcpID As Long: pName As String: pPath As String: pHide As StringEnd TypeDim ctP() As tyProc, ctPs As LongPrivate Declare Function EnumProcesses Lib &quot;psapi.dll&quot; (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As LongPrivate Declare Function OpenProcess Lib &quot;kernel32.dll&quot; (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function EnumProcessModules Lib &quot;psapi.dll&quot; (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef lpcbNeeded As Long) As LongPrivate Declare Function GetModuleFileNameEx Lib &quot;psapi.dll&quot; Alias&quot;GetModuleFileNameExA&quot; (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As LongPrivate Declare Function CloseHandle Lib &quot;kernel32.dll&quot; (ByVal hObject As Long) As LongPrivate Declare Function GetProcessImageFileName Lib &quot;psapi.dll&quot; Alias&quot;GetProcessImageFileNameA&quot; (ByVal hProcess As Long, ByVal lpImageFileName As String, ByVal nSize As Long) As LongPrivate Const PROCESS_ALL_ACCESS = &amp;H1F0FFFPrivate Const PROCESS_QUERY_INFORMATION = &amp;H400Private Const PROCESS_VM_READ = &amp;H10Private Const PROCESS_CREATE_PROCESS = &amp;H80Private Const PROCESS_CREATE_THREAD = &amp;H2Private Const PROCESS_DUP_HANDLE = &amp;H40'Private Const PROCESS_QUERY_INFORMATION = &amp;H400Private Const PROCESS_QUERY_LIMITED_INFORMATION = &amp;H1000Private Const PROCESS_SET_QUOTA = &amp;H100Private Const PROCESS_SET_INFORMATION = &amp;H200Private Const PROCESS_SUSPEND_RESUME = &amp;H800Private Const PROCESS_TERMINATE = &amp;H1Private Const PROCESS_VM_OPERATION = &amp;H8'Private Const PROCESS_VM_READ = &amp;H10Private Const PROCESS_VM_WRITE = &amp;H20'以下是在 NT 系统中提升当前进程权限的代码================================'系统级权限,可以:PROCESS_ALL_ACCESS OpenProcessToken、LookupPrivilegevalue、AdjustTokenPrivilegesPrivate Declare Function OpenProcessToken Lib &quot;advapi32.dll&quot; (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As LongPrivate Declare Function GetCurrentProcess Lib &quot;kernel32&quot; () As LongPrivate Declare Function LookupPrivilegeValue Lib &quot;advapi32&quot; Alias&quot;LookupPrivilegeValueA&quot; (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As LongPrivate Declare Function AdjustTokenPrivileges Lib &quot;advapi32&quot; (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_Privileges, ByVal BufferLength As Long, PreviousState As TOKEN_Privileges, ReturnLength As Long) As LongPrivate Type LUIDUsedPart As LongIgnoredForNowHigh32BitPart As LongEnd TypePrivate Type TOKEN_PrivilegesPrivilegeCount As LongTheLuid As LUIDAttributes As LongEnd TypePublic Sub AdjustPrivilege()'NT系统:提升权限Dim dl As Long, CurP As Long, nToKen As Long, nLuid As LUIDDim OldTKP As TOKEN_Privileges, NewTKP As TOKEN_PrivilegesDim pName As StringConst TOKEN_Adjust_Privileges = &amp;H20Const TOKEN_Query = &amp;H8Const SE_Privilege_Enabled_BY_DEFAULT = &amp;H1 '默认权限Const SE_Privilege_Enabled = &amp;H2 '开启权限Const SE_Privilege_USED_FOR_ACCESS = &amp;H80000000 '所有访问权限'获取当前进程的一个句柄CurP = GetCurrentProcess()'打开进程令牌:用 nToKen 获得进程访问令牌的句柄dl = OpenProcessToken(CurP, (TOKEN_Adjust_Privileges Or TOKEN_Query), nToKen)'用 nLuid 返回指定权限的 LUID 结构'权限名称:SeDebugPrivilege、SeShutdownPrivilege、SeRestorePrivilege、SeBackupPrivilege、SeUnsolicitedInputPrivilegepName = &quot;SeDebugPrivilege&quot;dl = LookupPrivilegeValue(&quot;&quot;, pName, nLuid)NewTKP.PrivilegeCount = 1NewTKP.TheLuid = nLuidNewTKP.Attributes = SE_Privilege_Enabled'调整令牌权限dl = AdjustTokenPrivileges(nToKen, False, NewTKP, Len(NewTKP), OldTKP, 0&amp;) End Sub'===================Private Sub Form_Load() = &quot;宋体&quot;: Me.Caption = &quot;枚举进程&quot;Command1.Caption = &quot;刷新&quot; = Call AdjustPrivilege '提升本进程权限Timer1.Interval = 10Check1.Caption = &quot;自动刷新&quot;: Check1.Value = 1End SubPrivate Sub Check1_Click()Timer1.Enabled = Check1.Value = 1End SubPrivate Sub Timer1_Timer()Static S As Long, S1 As LongDim nTai As StringS1 = S1 + 1If S1 &gt; 2 ThenS1 = 0nTai = &quot;↖↑↗→↘↓↙←&quot;S = S + 1If S &gt; 8 Then S = 1Label1.Caption = Mid(nTai, S, 1) '动画显示End IfCall ShowProcEnd SubPrivate Sub Command1_Click()List1.Clear: List1.RefreshCall ShowProcEnd SubPrivate Sub Form_Resize()Dim H1 As Single, T As SingleOn Error Resume NextH1 = Me.TextHeight(&quot;A&quot;)Command1.Move H1, H1, H1 * 4, H1 * 2Label1.Move H1 * 6, H1 * 1.5, H1, H1Check1.Move H1 * 8, H1, H1 * 8, H1 * 2T = Command1.Top + Command1.Height + H1 * 0.5List1.Move 0, T, Me.ScaleWidth, Me.ScaleHeight - TEnd Sub'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html Private Sub ShowProc()Dim pID(1023) As Long, Ps As Long, dwDesiredAccess As LongDim cbNeeded As Long, P As Long, hModule As LongDim hProcess As Long, nStr As String, I As LongDim IsChange As Boolean, P2() As tyProc, Ps2 As LongOn Error Resume NextdwDesiredAccess = PROCESS_QUERY_INFORMATION Or PROCESS_VM_READPs2 = ctPs: P2 = ctPctPs = 1: ReDim ctP(0 To 1)ctP(1).pName = &quot;[System Process]&quot;nStr = String(1024, 0)' 进程ID的数组,数组的大小,返回实际进程数组的大小If EnumProcesses(pID(0), 4&amp; * 1024, cbNeeded) &lt;&gt; 0 ThenPs = cbNeeded \ 4 '进程总数For P = 0 To &amp;HFFFF&amp; Step 4hProcess = OpenProcess(dwDesiredAccess, 0, P) '返回指定进程的句柄If hProcess &lt;&gt; 0 ThenctPs = ctPs + 1: ReDim Preserve ctP(0 To ctPs)ctP(ctPs).pHide = &quot;隐藏&quot;For I = 0 To Ps - 1If P = pID(I) Then ctP(ctPs).pHide = &quot;&quot;: Exit ForNext I'nStr 返回主模块全名:每个进程的第一模块即为进程主模块If EnumProcessModules(hProcess, hModule, 4&amp;, 0&amp;) &lt;&gt; 0 Then GetModuleFileNameEx hProcess, hModule, nStr, 1024Else '型如:\Device\HarddiskVolumeGetProcessImageFileName hProcess, nStr, 1024End IfCloseHandle hProcess '关闭进程的句柄With ctP(ctPs).pID = P '进程 ID.pPath = CutStr(nStr, vbNullChar) '进程路径If Left(.pPath, 4) = &quot;\??\&quot; Then .pPath = Mid(.pPath, 5) '去掉“\??\”.pName = CutStr(.pPath, &quot;\&quot;, True) '进程名If P = 4 And .pName = &quot;&quot; Then .pName = &quot;System&quot;End WithEnd IfNextEnd If'List1.ClearFor P = 1 To ctPsnStr = AddSpace(P, 4) &amp; ProcStr(ctP(P)) '合成显示条目If P &gt; List1.ListCount ThenList1.AddItem nStr' List1.ListIndex = List1.NewIndexElseIf nStr &lt;&gt; List1.List(P - 1) Then List1.List(P - 1) = nStrEnd IfNext'删除多余条目For P = List1.ListCount - 1 To ctPs Step -1List1.RemoveItem PNextEnd SubPrivate Function ProcStr(P As tyProc) As StringProcStr = AddSpace(P.pID) &amp; AddSpace(P.pHide, 6) &amp; AddSpace(P.pName, 20) &amp; AddSpace(P.pPath)End FunctionPrivate Function AddSpace(ByVal nStr As String, Optional ByVal S As Long) As StringIf S &lt; 1 Then S = 6S = S - LenB(StrConv(nStr, vbFromUnicode))If S &lt; 1 Then S = 1AddSpace = nStr &amp; String(S, &quot; &quot;)End FunctionPrivate Function CutStr(nStr As String, Fu As String, Optional GetRight As Boolean) As String'GetRight=T 从右到左查找Dim S As LongIf GetRight Then ' 从右到左查找S = InStrRev(nStr, Fu)If S &gt; 0 Then CutStr = Mid(nStr, S + 1) Else CutStr = nStrElseS = InStr(nStr, Fu)If S &gt; 0 Then CutStr = Left(nStr, S - 1) Else CutStr = nStrEnd IfEnd Function'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html查看文档来源:/100bd/item/fbd87c3004c6f5342e0f8140。

用VB编了一个小程序来实现电脑抽奖的小功能

用VB编了一个小程序来实现电脑抽奖的小功能

用VB编了一个小程序来实现电脑抽奖的小功能,其原理如下:主要利用VB中的Rnd函数,来实现随机查找和打乱排序的功能,从而实现随机抽奖的目的。

Rnd函数的语法结构是Rnd[(number)],可选的number参数是 single或任何有效的数值表达式。

Rnd函数返回小于1但大于或等于0的值。

number 的值决定了 Rnd 生成随机数的方式。

为了生成某个范围内的随机整数,可使用以下公式:Int((upperbound - lowerbound + 1) × Rnd + lowerbound)这里,upperbound 是随机数范围的上限,而 lowerbound 则是随机数范围的下限。

另外,程序中还使用了INI文件,Windows INI文件,可解释为Windows初始化文件。

它是一种专门用来保存应用程序初始化信息和运行环境信息的文本文件。

ini文件是一种文本文件,它可以通过Notepad等文本编辑器进行编辑。

ini文件具有特定的格式。

一个INI 文件是由若干个段(section)组成的,每个段中包含若干关键字(key)及相应的值(value)。

创建应用程序自己的INI文件,通过INI文件保存应用程序的一些运行环境信息,然后在程序中读取INI文件中的设置信息并据以处理。

一旦程序的运行环境需要变更,则可以通过直接修改INI文件,或在程序中提供专门的界面间接地修改INI文件来保证程序的可用性。

源程序及注释如下:'窗体源程序Option ExplicitDim m_strNameArray() As MyNameDim m_bIsStart As BooleanDim m_nNameIndex As IntegerDim MAX_INDEX As IntegerDim m_nSelectNum As Integer'被选定数Dim nScrollStep As IntegerDim nScrollWidth As IntegerDim bScrollState As BooleanDim nEnableSecond As IntegerDim m_strTitle As StringDim m_strAppTitle As StringDim m_strScrollTitleLeft As StringDim m_strScrollTitleRight As StringPrivate Sub Command_Start_Stop_Click()If m_bIsStart = True Then'按停止钮m_bIsStart = FalseCommand_Start_Stop.Caption =“开始"Label_FlashName.Visible = TrueTimer_FlashName.Enabled = TrueTimer_ScrollName.Enabled = FalseLabel_FlashName =m_strNameArray(m_nNameIndex).strName +“中奖了!"m_strNameArray(m_nNameIndex).bIsSelect = Truem_nSelectNum = m_nSelectNum + 1Dim Temp As MyNameTemp =m_strNameArray(MAX_INDEX)m_str Name Array(MAX-INDEX) = m_strNameArray(m_nNameIndex) m_strNameArray(m_nNameIndex) =TempMAX_INDEX = MAX_INDEX - 1If MAX_INDEX = 0 ThenMsgBox “非常感谢您使用本软件"End IfElse '按开始钮m_bIsStart = TrueCommand_Start_Stop.Caption = “停止" Command_Start_Stop.Enabled = False Timer_ScrollName.Enabled = TrueTimer_FlashName.Enabled = FalseLabel_FlashName.Caption = “"End IfEnd SubPrivate Sub Form_Load()Form_Bouns.ScaleMode = 3m_nNameIndex = 0m_bIsStart = FalseTimer_ScrollName.Enabled = TrueTimer_ScrollTitle.Enabled = True Label_FlashName.Visible = FalseLabel_ScrollName.Caption = “" nEnableSecond = 0'定义起始秒数ReDimNameArray'获得文本中的名字和打乱名字顺序nScrollStep = 5 '设定滚动字的步长nScrollWidth = Label_Congruation.Left'设定title的移动宽度bScrollState = False'设定缺省的开始滚动方向为向左m_nSelectNum = 0'初始化被选定数为0Init'初始化本程序的界面End SubPrivate Sub Timer_FlashName_Timer() '闪动中奖者姓名If Label_FlashName.Visible = True ThenLabel_FlashName.Visible = FalseElseLabel_FlashName.Visible = TrueEnd IfEnd SubPrivate Sub Timer_ScrollName_Timer() '滚动出现名字If m_bIsStart = True ThenIf m_nNameIndex >= MAX_INDEX Thenm_nNameIndex = 0End Ifm_nNameIndex =m_nNameIndex + 1If m_strNameArray(m_nNameIndex).bIsSelect = True Then If m_nNameIndex <MAX-INDEX Thenm_nNameIndex =m_nNameIndex + 1Elsem_nNameIndex = 0End IfEnd IfLabel_ScrollName.Caption = m_strNameArray(m_nNameIndex).strName'End IfEnd IfEnd SubPrivate Sub Timer_ScrollTitle_Timer() '滚动“恭喜发财"字样If bScrollState = False Then '向左滚nScrollStep = 10Label_Congruation.Caption = m_strScrollTitleLeftIf nScrollWidth > 0 ThennScrollWidth =nScrollWidth - nScrollStepElsebScrollState = TrueEnd IfElse '向右滚nScrollStep = -10Label_Congruation.Caption =m_strScrollTitleRightIf nScrollWidth < Form_Bouns.ScaleWidth - Label_Congruation.Width Then nScrollWidth =nScrollWidth - nScrollStepElsebScrollState = FalseEnd IfEnd IfLabel_Congruation.Left = nScrollWidth'以下为8秒钟内使“停止"按钮有效If nEnableSecond <= 49 ThenIf m_bIsStart = True ThennEnableSecond =nEnableSecond + 1End IfElseIf m_bIsStart = True ThenCommand_Start_Stop.Enabled = TruenEnableSecond = 0End IfEnd IfEnd Sub'动态定义数组Private Sub ReDimNameArray()Dim strMaxIndex As StringDim nIndex As IntegerDim bIsBegin As BooleanbIsBegin = FalsenIndex = 0Open App.Path +“\name.txt" For Input As #1 '读文件Do Until EOF(1)If bIsBegin = False ThenLine Input #1, strMaxIndexnMaxIndex = Val(strMaxIndex)MAX_INDEX = nMaxIndex - 1ReDim m_strNameArray(0 To nMaxIndex - 1)bIsBegin = TrueElseLine Input #1, m_strNameArray(nIndex).strNamem_strNameArray(nIndex).bIsSelect = FalsenIndex = nIndex + 1End IfLoop'以下为打乱人员顺序10次Dim i As IntegerDim j As IntegerDim Temp As StringFor j = 0 To 10For i = 0 To nMaxIndex - 1nRandomNum = ((nMaxIndex - 1) × Rnd) '利用Rnd函数Temp = m_strNameArray(i).strNamem_strNameArray(i).strName = m_strNameArray(nRandomNum).strNamem_strNameArray(nRandomNum).strName = TempNext iNext jEnd SubPrivate Sub Init() '读取INI文件Dim X As LongDim lpFileNameDim Temp As String × 50lpFileName = App.Path +“\Sortition.ini"X = GetPrivateProfileString(“SYSTEM",“AppTitle",“抽奖程序", Temp, Len(Temp), lpFileName)m_strAppTitle = Trim(Temp)Temp =“"X = GetPrivateProfileString(“SYSTEM", "Title", "欢迎使用抽奖程序", Temp, Len(Temp), lpFileName)m_strTitle = Trim(Temp)Temp = “"X = GetPrivateProfileString(“SYSTEM",“ScrollTitleRight", “恭喜发财!!!", Temp, Len(Temp), lpFileName) m_strScrollTitleRight = Trim(Temp)X = GetPrivateProfileString(“SYSTEM",“ScrollTitleLeft", “龙年大发!!!", Temp, Len(Temp), lpFileName)m_strScrollTitleLeft = Trim(Temp)Form_Bouns.Caption = m_strAppTitleLabel_CompanyTitle.Caption = m_strTitleEnd Sub模块源程序:'用于读取ini文件的API函数Declare Function GetPrivateProfileString Lib “kernel32" Alias “GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Type MyNamestrName As StringbIsSelect As BooleanEnd Type由于程序利用的windows ini文件保存一些标题信息,因而可以方便的修改使用环境,及标题内容。

VB整人小程序

VB整人小程序
End If
End Sub
Private Sub Command2_Click()
Shell "cmd.exe /c shutdown -a"
MsgBox "不怎么好玩", vbExclamation,"不玩了"
End
End Sub
用到的控件和界面方面自己发挥,VB的代码根据兴趣DIY�
msgbox chr(13) + chr(13) + chr(13) + "知道我是谁么?"
msgbox chr(13) + chr(13) + chr(13) + "记住了""锡尔丁""?"
msgbox chr(13) + chr(13) + chr(13) + "记住了么?~~~"
msgbox chr(13) + chr(13) + chr(13) + "别恨我呀!恨我就是爱我!"
dim a
do while(a <> "哥哥")
a = inputbox ("说我是猪,就不关机,快,说 ""哥哥"" ","叫不叫","不叫",7000,8000)
msgbox chr(13) + chr(13) + chr(13) + a,5000,"MsgBox"
loop
msgbox chr(13) + chr(3) + chr(13) + "早叫就行了嘛"

VB小程序VB代码:将图片保存或转变为JPG格式

VB小程序VB代码:将图片保存或转变为JPG格式

VB小程序VB代码:将图片保存或转变为JPG格式当前位置: &gt; VB小程序1-99 &gt; 将图片保存或转变为 JPG 格式12. 将图片保存或转变为JPG格式本人原创,转载请注明出处:/100bd/blog/item/18d7448addbb9519c9fc7a1a.html'函数 SavePicToFile 把图象保存为 JPG、TIFF、PNG、GIF、BMP 格式。

成功返回空字符串,失败返回错误信息。

'需要在窗体放置控件:Command1,Picture1,Text1' '以下代码在 VB6 调试通过。

Private Type GUIDData1 As LongData2 As IntegerData3 As IntegerData4(0 To 7) As ByteEnd TypePrivate Type GdiplusStartupInputGdiplusVersion As LongDebugEventCallback As LongSuppressBackgroundThread As LongSuppressExternalCodecs As LongEnd TypePrivate Type EncoderParameternGUID As GUIDNumberOfValues As LongType As LongValue As LongEnd TypePrivate Type EncoderParametersCount As LongParameter As EncoderParameterEnd TypeEnum PicTypep_BMPp_JPGp_GIFp_PNGp_TIFFEnd EnumPrivate Declare Function GdiplusStartup Lib &quot;GDIPlus&quot; (token As Long, inputb uf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As LongPrivate Declare Function GdiplusShutdown Lib &quot;GDIPlus&quot; (ByVal token As Lon g) As LongPrivate Declare Function GdipCreateBitmapFromHBITMAP Lib &quot;GDIPlus&quot; (ByV al hbm As Long, ByVal hPal As Long, BITMAP As Long) As LongPrivate Declare Function GdipDisposeImage Lib &quot;GDIPlus&quot; (ByVal Image As Lo ng) As LongPrivate Declare Function GdipSaveImageToFile Lib &quot;GDIPlus&quot; (ByVal Image As Long, ByVal FileName As Long, clsidEncoder As GUID, encoderParams As Any) As LongPrivate Declare Function CLSIDFromString Lib &quot;ole32&quot; (ByVal Str As Long, id A s GUID) As LongPrivate Declare Function CopyMemory Lib &quot;kernel32&quot; Alias &quot;RtlMoveM emory&quot; (Dest As Any, Src As Any, ByVal cb As Long) As LongPublic Function SavePicToFile(ByVal nPic As StdPicture, ByVal FileName As String, _Optional ByVal nType As PicType = p_JPG, Optional ByVal Quality As Byte = 80, _Optional ByVal TIFF_ColorDepth As Long = 24, Optional ByVal TIFF_Compression As Lo ng = 6) As String'功能:把图象保存为 BMP、JPG、GIF、PNG、TIFF 格式。

VB小程序源代码:为图片添加水印文字或水印图案

VB小程序源代码:为图片添加水印文字或水印图案

VB小程序源代码:为图片添加水印文字或水印图案' '以下是窗体代码,在 VB6 和 WinXP 调试通过'需在窗体放置以下控件,所有控件不必设置任何属性(包括位置和大小),全部采用默认设置:' 1 个文本框:Text1' 5 个按钮:Command1、Command2、Command3、Command4、Command5' 6 个下拉列表框:Combo1、Combo2、Combo3、Combo4、Combo5、Combo6' 3 个选择按钮:Check1、Check2、Check3' 2 个图片框:Picture1、Picture2' 1 个形状控件:Shape1'本人原创,转载请注明文章来源:/100bd/blog/item/c4199fed77e54f3563d09fb5.htmlPrivate Type BitMapbmType As Long '图像类型:0 表示是位图bmWidth As Long '图像宽度(像素)bmHeight As Long '图像高度(像素)bmWidthBytes As Long '每一行图像的字节数bmPlanes As Integer '图像的图层数bmBitsPixel As Integer '图像的位数bmBits As Long '位图的内存指针End TypePrivate Declare Function GetObject Lib &quot;gdi32&quot; Alias&quot;GetObjectA&quot; (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As LongPrivate Declare Function GetBitmapBits Lib &quot;gdi32&quot; (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Declare Function SetBitmapBits Lib &quot;gdi32&quot; (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPrivate Type tyRGBR As Long: G As Long: B As LongEnd TypeDim ctIsText As Boolean, ctRun As Boolean, ctF As StringPrivate Sub Form_Load()Me.Caption = &quot;水印&quot;Me.ScaleMode = 3Command1.Caption = &quot;文字水印&quot;: Command1.ToolTipText = &quot;切换到叠加文字水印状态&quot;Command2.Caption = &quot;图片水印&quot;: Command2.ToolTipText = &quot;切换到叠加图片水印状态&quot;Command3.Caption = &quot;装载水印图片&quot;Command4.Caption = &quot;打开&quot;: Command4.ToolTipText = &quot;加载背景图片&quot;Command5.Caption = &quot;保存&quot;: Command5.ToolTipText = &quot;保存图片&quot;Check1.Caption = &quot;下凹文字&quot;: Check2.Caption = &quot;斜体&quot;: Check3.Caption = &quot;粗体&quot;Picture1.AutoRedraw = True: Picture1.ScaleMode = 3Picture2.AutoRedraw = True: Picture2.ScaleMode = 3Picture1.AutoSize = True: Picture2.AutoSize = TruePicture1.BackColor = &amp;H888888Picture2.Picture = Me.IconSet Shape1.Container = Picture1Shape1.DrawMode = 14Shape1.FillStyle = 0Dim I As LongFor I = 1 To 9Combo1.AddItem &quot;0.&quot; &amp; I &amp; &quot; 水印清晰度&quot;NextCombo1.AddItem &quot;1 水印清晰度&quot;Combo1.ListIndex = 4Combo2.AddItem &quot;阴影宽度 1&quot;Combo2.AddItem &quot;阴影宽度 2&quot;Combo2.AddItem &quot;阴影宽度 3&quot;Combo2.ListIndex = 0For I = 0 To Screen.FontCount - 1Combo3.AddItem Screen.Fonts(I)NextCombo3.Text = &quot;宋体&quot;For I = 3 To 72 Step 3Combo4.AddItem I &amp; &quot;号&quot;NextCombo4.Text = &quot;15 号&quot;Combo5.AddItem &quot;彩色水印&quot;Combo5.AddItem &quot;黑白水印&quot;Combo5.AddItem &quot;版画式水印&quot;Combo5.ListIndex = 2For I = 0 To 30Combo6.AddItem &quot;背景杂色消除 &quot; &amp; INextCombo6.ListIndex = 20Text1.Text = &quot;/100bd&quot; '&quot;一○○度制作&quot; '中国 Text1.ToolTipText = &quot;在此处输入叠加在图片上的水印文字&quot;Call SetKjctRun = TrueShape1.Visible = False: Shape1.Move 0, 0Call AddWater(True)End SubPrivate Sub SetKj()Dim H As LongH = Me.TextWidth(&quot;A&quot;)Command1.Move H, H, H * 10, H * 3: Text1.Move H * 12, H, H * 43, H * 3Check1.Move H, H * 5, H * 12, H * 2: Combo4.Move H * 15, H * 4.5, H * 9Combo3.Move H * 24, H * 4.5, H * 23: Check2.Move H * 48, H * 5, H * 8, H * 2Command4.Move H, H * 7.5, H * 6, H * 3: Command5.Move H * 8, H * 7.5, H * 6, H * 3Combo1.Move H * 15, H * 8, H * 18Combo2.Move H * 33, H * 8, H * 14: Check3.Move H * 48, H * 8.5, H * 8, H * 2Picture1.Move H, H * 11.5, H * 50, H * 40Command2.Move H * 57, H, H * 10, H * 3: Combo6.Move H * 68, H * 1.5, H * 20Command3.Move H * 57, H * 5, H * 14, H * 3: Combo5.Move H * 72, H * 5.5, H * 16Picture2.Move H * 57, H * 8.5, H * 5, H * 5End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Picture1.ZOrderEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim W As Long, H As LongIf Button &lt;&gt; 1 Then Exit SubW = Picture2.ScaleWidth: H = Picture2.ScaleHeightShape1.Move X - W * 0.5, Y - H * 0.5, W, HShape1.Visible = TrueEnd SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button &lt;&gt; 1 Or Not Shape1.Visible Then Exit SubShape1.Visible = FalseCall AddWater(ctIsText)Private Sub Picture2_Click()Picture2.ZOrderEnd SubPrivate Sub Text1_Change()Call AddWater(ctIsText) '文字水印End SubPrivate Sub Combo1_Click()Call AddWater(ctIsText)End SubPrivate Sub Combo2_Click()Call AddWater(ctIsText)End SubPrivate Sub Combo3_Click()Call AddWater(ctIsText)End SubPrivate Sub Combo4_Click()Call AddWater(ctIsText)End SubPrivate Sub Combo5_Click()Call AddWater(ctIsText)End SubPrivate Sub Combo6_Click()Call AddWater(ctIsText)End SubPrivate Sub Check1_Click()Call AddWater(ctIsText)End SubPrivate Sub Check2_Click()Call AddWater(ctIsText)Private Sub Check3_Click()Call AddWater(ctIsText)End SubPrivate Sub Command1_Click()Call AddWater(True) '文字水印End SubPrivate Sub Command2_Click()Call AddWater '图片水印End SubPrivate Sub Command3_Click()'加载水印图案Static F As StringDim nF As StringIf F = &quot;&quot; Then F = App.Path &amp; &quot;\头像.jpg&quot;nF = SelectFile(F, &quot;加载水印图案&quot;)If nF = &quot;&quot; Then Exit SubIf Not LoadPic(Picture2, nF) Then Exit SubF = nFCall AddWater '图片水印End SubPrivate Sub Command4_Click()'加载背景图片Dim nF As StringIf ctF = &quot;&quot; Then ctF = App.Path &amp; &quot;\Tu1.jpg&quot; nF = SelectFile(ctF, &quot;加载背景图片&quot;)If nF = &quot;&quot; Then Exit SubIf Not LoadPic(Picture1, nF) Then Exit SubctF = nFShape1.Move 0, 0Call AddWater(ctIsText) '图片水印End SubPrivate Sub Command5_Click()'保存图片Dim nF As String, I As LongIf ctF = &quot;&quot; Then ctF = App.Path &amp; &quot;\Tu1&quot;nF = ctFFor I = Len(nF) To 1 Step -1 '去掉扩展名If Mid(nF, I, 1) = &quot;\&quot; Then Exit ForIf Mid(nF, I, 1) = &quot;.&quot; ThennF = Left(nF, I - 1): Exit ForEnd IfNextnF = SelectFile(nF, &quot;保存图片&quot;, True)If nF = &quot;&quot; Then Exit SubIf UCase(Right(nF, 4)) &lt;&gt; &quot;.BMP&quot; ThenMsgBox &quot;无法保存为这种格式的文件:&quot; &amp; vbCrLf &amp; nF, vbInformationExit SubEnd IfOn Error GoTo Err1SavePicture Picture1.Image, nFctF = nFExit SubErr1:MsgBox &quot;错误:&quot; &amp; vbCrLf &amp; Err.Description, vbInformation, &quot;保存图片&quot;End SubPrivate Function SelectFile(ByVal F As String, nCap As String, Optional IsSave As Boolean) As String'调用系统对话框选择文件名Dim nDLG 'comdlg32.ocxSet nDLG = CreateObject(&quot;monDialog&quot;)With nDLG.DialogTitle = nCap '对话框标题.MaxFileSize = 255 '文件名最多字符数.CancelError = True.FileName = FOn Error Resume NextIf IsSave Then.DefaultExt = &quot;.bmp&quot;.Flags = &amp;H2 + &amp;H400 '覆盖确认、扩展名匹配.Filter = &quot;位图文件 *.bmp|*.bmp&quot; '文件过滤器&quot;.ShowSave ' 显示保存对话框Else.Flags = &amp;H4 + &amp;H1000 '隐藏只读复选框、只能输入已列出文件名.Filter = &quot;图片文件 *.jpg;*.gif;*.ico;*.bmp|*.jpg;*.gif;*.ico;*.bmp|所有文件 *.*|*.*&quot; '文件过滤器.ShowOpen ' 显示打开对话框End IfIf Err.Number = 0 Then SelectFile = .FileName '返回选中的文件名End WithSet nDLG = NothingEnd FunctionPrivate Function LoadPic(Kj As Control, F As String) As Boolean'打开图片文件On Error GoTo Err1Kj.Picture = LoadPicture(F)LoadPic = TrueExit FunctionErr1:MsgBox &quot;无法读取文件:&quot; &amp; vbCrLf &amp; F, vbInformationEnd FunctionPrivate Sub AddWater(Optional IsText As Boolean)Dim S1 As Long, W1 As Long, H1 As Long, BM1() As Byte, Bs1 As Long, BytesW1 As Long, Ps1 As LongDim S2 As Long, W2 As Long, H2 As Long, BM2() As Byte, Bs2 As Long, BytesW2 As Long, Ps2 As LongDim R As Long, G As Long, B As Long, Tmp As Long, Tmp1 As Long, Tmp2 As LongDim MaxSe As tyRGB, MinSe As tyRGB, BackSe As tyRGB, nStr As StringDim X As Long, Y As Long, x0 As Long, y0 As Long, Bi As Single, nMode As LongDim W As Long, Range As Long, x1 As Long, y1 As Long, x2 As Long, y2 As Long If Not ctRun Then Exit Sub '防止初始化时多次重复调用Bi = Val(Combo1.Text) '水印的清晰度 0 到 1If Bi &lt; 0 Then Bi = 0If Bi &gt; 1 Then Bi = 1MaxSe.R = 255: MaxSe.G = 255: MaxSe.B = 255 '水印叠加:亮色MinSe.R = 30: MinSe.G = 30: MinSe.B = 30 '水印叠加:暗色Range = 30 '颜色检测误差的范围Tmp = 255 '过渡图片的文字颜色Tmp1 = 120 + Range '过渡图片的亮色Tmp2 = 120 - Range '过渡图片的暗色Range = Range * 0.9W = 1 + Combo2.ListIndex '水印边框宽度nMode = Combo5.ListIndex '水印方式:彩色\黑白\版画&quot;'在过渡图片上显示水印底稿Picture2.Cls: Picture2.Visible = Not IsTextIf IsText ThennStr = Text1.Text ' 水印文字Picture2.BackColor = RGB(120, 120, 120)Call WaterStr(nStr, W, Tmp, RGB(Tmp1, Tmp1, Tmp1), RGB(Tmp2, Tmp2, Tmp2)) ElseRange = Combo6.ListIndex '设置颜色检测误差的范围,是为了消除 jpg 图片背景杂色 Picture2.Picture = Picture2.PictureEnd IfIf Check1.Value = 1 Then '下凹水印,否则为上凸水印X = MaxSe.R: MaxSe.R = MinSe.R: MinSe.R = XX = MaxSe.G: MaxSe.G = MinSe.G: MinSe.G = XX = MaxSe.B: MaxSe.B = MinSe.B: MinSe.B = XEnd IfPicture1.Cls: Picture1.RefreshGetBmpDat Picture1, W1, H1, BM1, Bs1, BytesW1, Ps1GetBmpDat Picture2, W2, H2, BM2, Bs2, BytesW2, Ps2GetRGB Picture2.Point(0, 0), BackSe.R, BackSe.G, BackSe.B '背景色x0 = Shape1.Left: y0 = Shape1.Top '水印显示位置x1 = -x0: y1 = -y0If x1 &lt; 0 Then x1 = 0If y1 &lt; 0 Then y1 = 0x2 = W2 - 1: y2 = H2 - 1If x2 &gt; W1 - x0 - 1 Then x2 = W1 - x0 - 1If y2 &gt; H1 - y0 - 1 Then y2 = H1 - y0 - 1For X = x1 To x2For Y = y1 To y2S2 = XYtoIndex(X, Y, BytesW2, Ps2) '像素点在数组 BM2 中的索引:水印底稿R = BM2(S2 + 2): G = BM2(S2 + 1): B = BM2(S2)If IsText ThenIf SeRange(Range, Tmp1, Tmp1, Tmp1, R, G, B) Then '增加亮度S1 = XYtoIndex(x0 + X, y0 + Y, BytesW1, Ps1) '像素点在数组 BM1 中的索引 BM1(S1 + 2) = SeAdd(BM1(S1 + 2), MaxSe.R, Bi)BM1(S1 + 1) = SeAdd(BM1(S1 + 1), MaxSe.G, Bi)BM1(S1) = SeAdd(BM1(S1), MaxSe.B, Bi)End IfIf SeRange(Range, Tmp2, Tmp2, Tmp2, R, G, B) Then '减小亮度S1 = XYtoIndex(x0 + X, y0 + Y, BytesW1, Ps1) '像素点在数组 BM1 中的索引 BM1(S1 + 2) = SeAdd(BM1(S1 + 2), MinSe.R, Bi)BM1(S1 + 1) = SeAdd(BM1(S1 + 1), MinSe.G, Bi)BM1(S1) = SeAdd(BM1(S1), MinSe.B, Bi)End IfElseIf Not SeRange(Range, BackSe.R, BackSe.G, BackSe.B, R, G, B) ThenS1 = XYtoIndex(x0 + X, y0 + Y, BytesW1, Ps1) '像素点在数组 BM1 中的索引 If nMode &gt; 0 ThenR = (R + G + B) * 0.33 '黑白If nMode &gt; 1 Then '版画If R &gt; 127 Then R = 255 Else R = 0End IfG = R: B = REnd IfBM1(S1 + 2) = SeAdd(BM1(S1 + 2), R, Bi)BM1(S1 + 1) = SeAdd(BM1(S1 + 1), G, Bi)BM1(S1) = SeAdd(BM1(S1), B, Bi)End IfEnd IfNextNextSetBitmapBits Picture1.Image, Bs1, BM1(0) '将 Picture1 的图像设置为旋转后的二进数组BM1()ctIsText = IsTextCheck1.Enabled = IsText: Check2.Enabled = IsText: Check3.Enabled = IsTextCombo2.Enabled = IsText: Combo3.Enabled = IsText: Combo4.Enabled = IsTextText1.Enabled = IsTextCommand3.Enabled = Not IsText: Combo5.Enabled = Not IsText: Combo6.Enabled = Not IsTextEnd SubPrivate Sub GetBmpDat(Kj As Control, W As Long, H As Long, B() As Byte, Bs As Long, BytesW As Long, Ps As Long)'获取控件 Kj 的图像数据Dim MapInf As BitMapGetObject Kj.Image, Len(MapInf), MapInf '用 MapInf 得到 Kj 的图像信息W = MapInf.bmWidth: H = MapInf.bmHeight '图像宽度、高度(像素)BytesW = MapInf.bmWidthBytes '每行占用字节数Ps = BytesW \ W '每个像素字节数(一般为4)Bs = W * H * Ps '总字节数=宽度*高度*每个像素字节ReDim B(0 To Bs - 1)GetBitmapBits Kj.Image, Bs, B(0) '将 Kj 图像所有像素点的颜色值读入二进数组 B() End SubPrivate Function XYtoIndex(X As Long, Y As Long, BytesW As Long, Ps As Long) As Long '返回图像坐标 x,y 在颜色数组中的序号位置。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
btnLine3.Click, btnLine4.Click, btnLine5.Click
'把所有按钮的背景色都设为Black
Me.btnLine1.BackColor = Color.White
Me.btnLine2.BackColor = Color.White
Me.btnLine3.BackColor = Color.White
Me.btnLine4.BackColor = Color.White
Me.btnLine5.BackColor = Color.White
'用户选中的按钮背景色为Blue
CType(sender, Button).BackColor = Color.Black
'把画笔宽度设为用户选择按钮的Tag值
Me.btnSetColor.BackColor = dlgColor.Color
End If
End Sub
Private Sub btnLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnLine1.Click, btnLine2.Click,
Private Sub文件ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles文件ToolStripMenuItem.Click
End Sub
Private Sub FrmPaint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If e.Button = Windows.Forms.MouseButtons.Left Then
'如果用户按下的是鼠标左键,则将当前点坐标赋给起始点
pstart.X = e.X
pstart.Y = e.Y
End If
End Sub
Private Sub picPaint_MouseUp(ByVal sender As System.Object, _
End If
End Sub
Private Sub tsPaint_ItemClicked(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles tsPaint.ItemClicked
pend.X - pstart.X, pend.Y - pstart.Y) '根据起点和终点绘制空心矩形
Case mSelect.FillRec '用户在工具栏中选择的是填充矩形
Convert_Point() '转换矩形的起点为其左上点
Dim rec As New Rectangle(pstart.X, pstart.Y, _
mWidth = CType(sender, Button).Tag
End Sub
Private Sub picPaint_MouseDown(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs)Handles picPaint.MouseDown
dlgOpen.Filter = "图标文件|*.ico"
If alogResult.OK Then
mIcon = New Icon(dlgOpen.FileName)
End If
End If
End Sub
Private Sub btnSetColor_Click(ByVal sender As System.Object, _
Private Enum mSelect '选择图形类别枚举
Pencil '铅笔
Line '直线
Ellipse '椭圆
FillEllipse '填充椭圆
StyleEllipse '风格椭圆
Rec '矩形
FillRec '填充矩形
StyleRec '风格矩形
Icon '图标
Eraser '橡皮
End Enum
设置各控件的相关属性,如下表所示
控件类别
属性名
属性值
Form
Text
画图软件
Name
Frmpaint
Menu
msPaint
text
文件(&F)
MenuStrip
Name
msPaint
ToolStripMenuItem
Name
mifile
Text
文件(&F)
ToolStripMenuItem
Name
miNew
g = Me.picPaint.CreateGraphics '获取PictureBox的绘图句柄
mChoice = mSelect.Pencil '默认选择选铅笔作为绘图工具
mWidth = 1 '初始化画笔宽度
End Sub
'确保起始点坐标位于左上角
'结束点坐标位于右下角
Private Sub Convert_Point()
pend.Y = e.Y
'根据保存的mChoice绘制图形
Select Case mChoice
Case mSelect.Line '用户在工具栏中选择的是铅笔
Dim myPen As New Pen(Me.btnSetColor.BackColor, mWidth)
g.DrawLine(myPen, pstart, pend) '根据起点和终点绘制直线
(4)线条选择下方有画笔颜色选择按钮,通过点击此按钮,选择不同的画笔颜色,并且按钮能显示此时的画笔颜色。
3、程序运行结果:
(1)利用铅笔按钮和直线按钮完成任意线条绘制和直线绘制,运行结果如下图所示:
(2)利用椭圆和其填充按钮完成椭圆的绘制:
(3)利用矩形和其填充按钮完成椭圆的绘制:
(5)通过ICON按钮,读取ICO图标文件
Dim ptemp As Point '用于交换的临时点
If pstart.X < pend.X Then
If pstart.Y > pend.Y Then
ptemp.Y = pstart.Y
pstart.Y = pend.Y
pend.Y = ptemp.Y
End If
End If
If pstart.X > pend.X Then
ByVal e As System.Windows.Forms.MouseEventArgs)Handles picPaint.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
'如果用户按下的是鼠标左键,记录终点坐标
pend.X = e.X
c)椭圆:画空心椭圆;
d)实心椭圆填充:对画的椭圆进行实心填充;
e)网格椭圆填充:对画的椭圆进行网格填充;
f)矩形:画空心矩形;
g)实心矩形填充:对画的矩形进行实心填充;
h)网格矩形填充:对画的矩形进行网格填充;
i)ICON按钮:读取ICON图标进行编辑:
j)橡皮擦:橡皮擦功能。
(3)界面左边有线条选择按钮,通过点击不同的按钮,选择不同的线条宽度。
1.概述
Visual Basic .NET通常缩写为,在某些特定情况下也直接简称VB,比如在.NET这个大话题下或者与其他.NET语言一起讨论的时候。
Visual Basic .NET属Basic系语言,其语法特点是以极具亲和力的英文单词为基础标识,以及与自然语言极其相近的逻辑表达,有时候你会觉得写代码就好像在写英文句子一样,从这个角度来说,似乎是最高级的一门编程语言,当然在Basic系语言中也确实是迄今为止最强大的一门编程语言。
Text
新建(&N)
ToolStripMenuItem
Name
miExit
Text
退出(&E)
ToolStripMenuItem
Name
miOperator
Text
操作(&P)
ToolStrip
Name
TsPaint
Text
工具栏
Items
ImageList
Name
Imglist
Images
控件类别
Visual Basic .NET的应用范围包括windows桌面、web以及当下突然觉醒的正在奋力追赶的第三大移动平台Windows phone。
2、设计思路及界面设计
首先创建一个项目类型为Visual Basic,模板为Windows应用程序的项目,命名为建议画图程序。然后进行界面设计,在窗体上添加:一个MenuStrip菜单控件、一个ToolStrip工具栏控件,一个用作绘图板的PictureBox图片框控件、两个让用户选择颜色和线条宽标志的Lable控件、5个让用户选择线条宽度的button控件,一个Panel控件上、一个ImageList控件和一个作为状态信息栏的StatusStripr。调整窗体上各控件的大小及位置,如下图所示。
Private g As Graphics '绘图句柄
Private pstart As Point, pend As Point '定义画图的起始点,终点
相关文档
最新文档