说明:1.共有4个文本框其,其中三个是填入或输出数据的(名称分别是:txta txtb txtc),剩下的那个是符号(txtd)2.共7个按钮,4个是符号按钮,一个计算,一个清零.这是我弄的程序”袖珍计算器”代码也是自己编写的,代码如下:通用声明Dim j As Integer '定义j为整型
在莆田等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、网站制作、外贸营销网站建设 网站设计制作按需开发,公司网站建设,企业网站建设,品牌网站设计,营销型网站,成都外贸网站建设,莆田网站建设费用合理。
Private Sub Text1_Change()End SubPrivate Sub Command1_Click()
txtfuhao.Text = "+" '将”+”显示到文本框txtfuhao.Text中
End SubPrivate Sub Command2_Click()
txtfuhao.Text = "-" ''将”-”显示到文本框txtfuhao.Text中
End SubPrivate Sub Command3_Click()
txtfuhao.Text = "×" '将”×”显示到文本框txtfuhao.Text中
End SubPrivate Sub Command4_Click()
txtfuhao.Text = "÷" 将”÷”'显示到文本框txtfuhao.Text中
End Sub
Private Sub Command5_Click()
Dim a, b, c As Integer
a = Val(txta.Text) '将txta.Text里的内容转化为数值型,然后再赋给a
b = Val(txtb.Text) '将txtb.Text里的内容转化为数值型,然后再赋给b
If txtfuhao.Text = "+" Then '运算过程
c = a + b '运算过程
ElseIf txtfuhao.Text = "-" Then '运算过程
c = a - b '运算过程
ElseIf txtfuhao.Text = "÷" Then '运算过程
c = a / b '运算过程
ElseIf txtfuhao.Text = "×" Then '运算过程
c = a * b '运算过程
Else
j = MsgBox("您输入的符号不正确", vbOKOnly, "错误信息")
End If
txtc.Text = c '将运算结果c输出到文本框txtc中
End SubPrivate Sub Command6_Click()
txta.Text = "" '将空字符输入到文本框内(刷新)
txtb.Text = "" '将空字符输入到文本框内(刷新)
txtc.Text = "" '将空字符输入到文本框内(刷新)
txtfuhao.Text = "" '将空字符输入到文本框内(刷新)
End SubPrivate Sub Command7_Click()
End '结束程序
End SubPrivate Sub Form_Load()End Sub
获取控件的Graphic对象,绘图方法都集中在了该对像中了。
1. 通过控件GreateGrapic方法获得
2. Paint 事件参数e中也有此对象
相应的图形方法是DrawImage,vb.net中没有自动重绘功能,图形不是持久的,所以应当在Paint事件中绘图。
Private Sub PictureBox2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
e.Graphics.SetClip(e.ClipRectangle)
e.Graphics.DrawImage(PictureBox1.Image, New Rectangle(0, 0, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height), New Rectangle(5, 5, 100, 100), GraphicsUnit.Pixel)
End Sub
新建窗口,添加picture控件
利用line()方法画线
line(开始x坐标,开始y坐标)-(结束x坐标,结束y坐标),线的颜色,画线的方式(默认为线,B为矩形无填充,BF为填充的矩形)
For i = 1 To 16
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(255, 0, 0)
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(255, 0, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(0, 255, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(0, 255, 0)
Next i
如果要在窗口上画也可以调用窗口的line方法即form.line()
VB.net里有个很简单的办法,就是把Form1的TransparencyKey 属性设置成白色,你的图片的白色就会变成透明的了,很方便吧。
代码:
Public Class Form1
'*********************************************************************
'作者:章鱼哥,QQ:3107073263 群:309816713
'如有疑问或好的建议请联系我,大家一起进步
'*********************************************************************
'绘制圆角矩形函数
Private Function GetRoundedRectPath(ByVal rect As Rectangle, ByVal radius As Integer) As System.Drawing.Drawing2D.GraphicsPath
rect.Offset(-1, -1)
Dim RoundRect As New Rectangle(rect.Location, New Size(radius - 1, radius - 1))
Dim path As New System.Drawing.Drawing2D.GraphicsPath
path.AddArc(RoundRect, 180, 90) '左上角
RoundRect.X = rect.Right - radius '右上角
path.AddArc(RoundRect, 270, 90)
RoundRect.Y = rect.Bottom - radius '右下角
path.AddArc(RoundRect, 0, 90)
RoundRect.X = rect.Left '左下角
path.AddArc(RoundRect, 90, 90)
path.CloseFigure()
Return path
End Function
'绘制矩形
Private Sub DrawingRect()
Dim g As Graphics = Me.CreateGraphics
Dim Pen As New Pen(Brushes.DarkRed, 2)
Dim Hei As Integer = Me.Height
Dim Wid As Integer = Me.Width
'矩形的位置和长宽随着窗体的变化而改变
Dim Rec As New Rectangle(Int(Wid / 5), Int(Hei / 5), Int(Wid / 2), Int(Hei / 2))
' g.DrawRectangle(Pen, Rec)
'清楚现有的矩形
g.Clear(Me.BackColor)
g.DrawPath(Pen, GetRoundedRectPath(Rec, 30))
End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
DrawingRect()
End Sub
Private Sub Form1_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
Me.Invalidate() '此函数可引发Paint事件
End Sub
End Class
效果截图:
原窗口:
缩小后: