用vbnet画爱心 vbs爱心特效教程

用VB程序怎么做一个心型图?

Dim X1, Y1, X2, Y2 As Integer

创新互联自2013年起,是专业互联网技术服务公司,拥有项目成都网站建设、网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元奉节做网站,已为上家服务,为奉节各地企业和个人服务,联系电话:13518219792

Dim I As Integer

Dim J As Boolean

Dim K As IntegerDim WithEvents Label1 As Label

Dim WithEvents Timer1 As TimerPrivate Sub Form_Activate()

I = 100

K = 100

X1 = Me.Width / 2

Y1 = Me.Height / 3

X2 = X1

Y2 = Y1

Label1.Top = Me.Height / 2 - Label1.Height / 2

Label1.Left = Me.Width / 2 - Label1.Width / 2

End SubPrivate Sub Form_Load() Me.BackColor = H0

Me.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

Me.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

Me.DrawMode = 13

Me.DrawWidth = 2

Me.FillStyle = 7

Set Label1 = Me.Controls.Add("VB.Label", "Label1")

Set Timer1 = Me.Controls.Add("VB.Timer", "Timer1")

Label1.Visible = True

Label1.AutoSize = True

Label1.BackStyle = 0

Label1.Caption = "I LOVE YOU"

Label1.Font.Size = 60

Label1.ForeColor = HFF00

Timer1.Enabled = True

Timer1.Interval = 10

Me.WindowState = 2

End SubPrivate Sub Timer1_Timer()

Me.Circle (X1, Y1), 250

Me.Circle (X2, Y2), 250

If Y1 = Me.Height - 1200 Then

X1 = X1 + K

Y1 = Y1 - I

X2 = X2 - K

Y2 = Y2 - I

I = I - 2

If Y1 = Me.Height / 3 Then

K = K - 1

ElseIf Y1 = Me.Height / 3 Then

K = K - 5

End If

Else

I = 100

K = 100

X1 = Me.Width / 2

Y1 = Me.Height / 3

X2 = X1

Y2 = Y1

Me.FillColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)

Me.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255) End If

Me.DrawWidth = 3

Me.PSet (Rnd * Me.Width, Rnd * Me.Height), RGB(Rnd * 225, Rnd * 225, Rnd * 225)

Me.DrawWidth = 2

End SubPrivate Sub Form_Click()

End

End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

End

End Sub

如何用VB.NET画同心圆

窗体上添加一个按钮,在该按钮的单击事件里编写代码如下:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'声明窗体的Me.CreateGraphics对象

Dim MyGraphics As Graphics = Me.CreateGraphics

Dim Cx As Integer = 150 '圆心的X坐标

Dim Cy As Integer = 150 '圆心的Y坐标

Dim R As Integer '圆的半径

'绘制半径为R的圆

For R = 5 To 100 Step 5

MyGraphics.DrawEllipse(Pens.Black, New Rectangle(Cx - R, Cy - R, 2 * R, 2 * R))

Next

End Sub

‘用黑色画笔绘制一组同心圆,半径从5开始,增量为5。

说明:

DrawEllipse是VB.Net的Graphics类的绘制椭圆的方法;他有几种格式,上面使用的是一种;

DrawEllipse(画笔的颜色,绘制椭圆所需要的矩形区域)

其中:绘制椭圆所需要的矩形区域,如果被定义为正方形,就演变成绘制圆,定义该区域由死个数值确定,第1个数值,确定该区域左上角的X坐标,第2个数值,确定该区域左上角的Y坐标,第3个数值,确定该区域的宽度,第4个数值,确定该区域的高度。

例如1:

DrawEllipse(Pens.Black, New Rectangle(150, 150, 50, 50))

就是以圆心坐标为(100,100),绘制半径为50 的圆。其实在VB.NET中,是告诉系统在以左上角坐标(150,150),边长为50的正方形里绘制内切圆。理解了是在正方形里绘制内切圆,就可以通过数学计算,知道如何绘制了。

同理例如2:

DrawEllipse(Pens.Black, New Rectangle(150, 150, 100, 50))

就是以圆心坐标为(100,100),绘制半径为50 的圆。其实在VB.NET中,是告诉系统在以左上角坐标(150,150),长轴为100,短轴为50的内切椭圆。

在VB.Net中如何画实心的圆

在PictureBox1上画红色的实心圆:

Private Sub DrawCircle(ByVal cp As Point, ByVal radius As Integer, ByVal color As Brush)

Dim gr As Graphics

gr = PictureBox1.CreateGraphics

Dim rect As Rectangle = New Rectangle(cp.X - radius, cp.Y - radius, 2 * radius, 2 * radius)

gr.DrawEllipse(Pens.Black, rect)

gr.FillEllipse(color, rect)

End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

DrawCircle(New Point(120, 100), 80, Brushes.Red)

End Sub

VB编写爱心形状的窗体

你的描述我不是很明白,可以给你个思路!首先找个爱心形状的图片,加载进窗体的picturebox中,调整到合适大小。然后用以下让窗体透明。'设置Me.BorderStyle = 0

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Const WS_EX_LAYERED = H80000

Private Const GWL_EXSTYLE = (-20)

Private Const LWA_ALPHA = H2

Private Const LWA_COLORKEY = H1

Private Declare Function ReleaseCapture Lib "user32" () As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_NCLBUTTONDOWN = HA1

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Sub Form_Load()

Me.BackColor = HFF0000

Dim rtn As Long

rtn = GetWindowLong(hwnd, GWL_EXSTYLE)

rtn = rtn Or WS_EX_LAYERED

SetWindowLong hwnd, GWL_EXSTYLE, rtn

SetLayeredWindowAttributes hwnd, HFF0000, 0, LWA_COLORKEY

End Sub


新闻名称:用vbnet画爱心 vbs爱心特效教程
文章位置:http://abwzjs.com/article/dosgdig.html