效果如图,代码如下:
10年积累的成都网站建设、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有湖州免费网站建设让你可以放心的选择与我们合作。
Public Class Form1
'Circle类
Class Circle
Public Center As Point
Public Radius As Single
Public Sub New(c As Point, r As Single)
Center = c
Radius = r
End Sub
'绘制
Public Sub Draw(g As Graphics, pen As Pen)
g.DrawEllipse(pen, New RectangleF(Center.X - Radius, Center.Y - Radius, Radius * 2, Radius * 2))
End Sub
End Class
Private downPoint As Point '记录鼠标按下位置
Private circleList As New List(Of Circle) '已存放圆的列表
Private tmpCircle As Circle '临时圆(正在拖动)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DoubleBuffered = True '启用双缓冲绘图,避免闪烁
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
downPoint = e.Location '记下位置
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.Button Windows.Forms.MouseButtons.Left Then Return '左键没按下则退出
Dim r As Single = Math.Sqrt((e.X - downPoint.X) ^ 2 + (e.Y - downPoint.Y) ^ 2) '算出半径
tmpCircle = New Circle(downPoint, r) '更新临时圆
Refresh() '先刷新掉之前绘制的临时圆
tmpCircle.Draw(Me.CreateGraphics, Pens.Black) '绘制临时圆
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
circleList.Add(tmpCircle) '鼠标弹起,把临时圆加入圆列表
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
For Each c As Circle In circleList
c.Draw(e.Graphics, Pens.Black) '绘制出每个圆
Next
End Sub
End Class
VB的运算顺序是:先乘除、后加减,有括号的先算括号内,有负号的先算负号。
请你比较一下这个运算中x和y的值:
Dim n As Single = 4
Dim x As Single
Dim y As Single
x = n + 1
x = x / n
x = x - 1
x = Math.Sqrt(x)
y = Math.Sqrt((n + 1) / n - 1)
这样就会发现,你的代码中括号的位置错了。
正确的应该是: Math.Sqrt((n + 1) / n - 1)
我是这么做的,你参考一下:
所有Panel的Visiable属性都是False
'设置全局变量
Private lblMenu As Object = Nothing '鼠标移动的前一菜单项
Private MenuSelect As Object = Nothing '鼠标点击的前一菜单项
Private FrmShow As Object = Nothing '前一菜单项所指向内容
Private Sub MixedControls_Click(sender As System.Object, e As System.EventArgs) Handles _
Label1.Click, Label2.Click, Label3.Click, Label4.Click, Label5.Click, Label6.Click, Label7.Click
If MenuSelect IsNot Nothing Then
MenuSelect.forecolor = Color.White '前面选择的菜单项前景色变为白色
End If
If FrmShow IsNot Nothing Then
FrmShow.visible = False '前一菜单项内容隐藏
End If
sender.forecolor = Color.Chartreuse '当前选择的菜单项前景色为亮绿色
MenuSelect = sender '保存当前选择菜单项
Select Case sender.name.ToString
Case "Label1"
FrmShow = Panel1 '保存当前菜单项选择
Me.Panel1.Dock = DockStyle.Fill '显示运行界面
Me.Panel1.Visible = True
Case "Label2"
FrmShow = Panel2 '保存当前菜单项选择
Me.Panel2.Dock = DockStyle.Fill '显示设置界面
Me.Panel2.Visible = True
Case "Label3"
FrmShow = Panel3 '保存当前菜单项选择
Me.Panel3.Dock = DockStyle.Fill '显示关于界面
Me.Panel3.Visible = True
End Select
End Sub
Private Sub MixedControls_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles _
Label1.MouseDown, Label2.MouseDown, Label3.MouseDown, Label4.MouseDown, Label5.MouseDown, Label6.MouseDown, Label7.MouseDown
sender.BorderStyle = BorderStyle.FixedSingle '鼠标按下菜单效果
End Sub
Private Sub MixedControls_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles _
Label1.MouseUp, Label2.MouseUp, Label3.MouseUp, Label4.MouseUp, Label5.MouseUp, Label6.MouseUp, Label7.MouseUp
sender.BorderStyle = BorderStyle.None '鼠标抬起取消菜单效果
End Sub
Private Sub MixedControls_MouseEnter(sender As Object, e As System.EventArgs) Handles _
Label1.MouseEnter, Label2.MouseEnter, Label3.MouseEnter, Label4.MouseEnter, Label5.MouseEnter, Label6.MouseEnter, Label7.MouseEnter
If lblMenu IsNot Nothing Then
Call MixedControls_MouseLeave(lblMenu, e) '前一菜单项恢复初始状态
End If
sender.backcolor = Color.DeepSkyBlue '鼠标进入菜单范围的效果:背景色变深蓝
lblMenu = sender '保存当前进入菜单项
End Sub
Private Sub MixedControls_MouseLeave(sender As Object, e As System.EventArgs) Handles _
Label1.MouseLeave, Label2.MouseLeave, Label3.MouseLeave, Label4.MouseLeave, Label5.MouseLeave, Label6.MouseLeave, Label7.MouseLeave
sender.backcolor = Color.Transparent '鼠标离开菜单项恢复默认效果,背景色透明
sender.BorderStyle = BorderStyle.None '菜单项边框取消
lblMenu = Nothing '删除保存的菜单项
End Sub
绝对值是“|”,可以直接显示,同理对数可用log(x)代替,根号和其他不支持显示。
如果要显示数学式子,只能画吧。
计算时可用“^”求幂或求根,“/”表示除法和分数线,还有math类。
额,我可以用vb6.0的语句回答您,给您参考,就是不知道您可以转化成.net语句与否。
'添加text1,text2,text3用于记录a,b,c的值
Private Sub Command1_Click()
On Error GoTo check
Dim a, b, c, result1, result2
a = Text1.Text
b = Text2.Text
c = Text3.Text
result1 = (((-1) * b) + Sqr(b ^ 2 - 4 * a * c)) / 2 * a
result2 = (((-1) * b) - Sqr(b ^ 2 - 4 * a * c)) / 2 * a
MsgBox "x1= " result1 " x2= " result2
Exit Sub
check:
MsgBox "error!please check your number!"
End Sub
注意只能对整型执行按位运算。浮点值必须转换为整型后,才能执行按位运算。按位运算采用二进制(以 2 为基)形式计算两个整数值。它们比较对应位置上的位,然后基于比较的结果赋值。下面的示例演示了 And 运算符。复制Dim x As Integerx = 3 And 5 前面的示例将 x 的值设置为 1。发生这种情况的原因如下:这些值以二进制形式处理:二进制格式的 3 为 011二进制格式的 5 为 101And 运算符比较这些二进制表示方式,一次比较一个二进制位置(位)。如果给定位置的两个位都为 1,则将 1 放在结果中的该位置。如果任何一个位是 0,则将 0 放在结果中的该位置。在前面的示例中,按如下所示计算结果:011(二进制格式的 3)101(二进制格式的 5)001(二进制格式的计算结果)计算结果以十进制形式处理。值 001 是 1 的二进制表示形式,因此 x = 1。除了在任何一个比较位是 1 或两个比较位都是 1 的情况下将 1 赋予结果位以外,按位 Or 运算与此类似。Xor 在比较的位正好只有一个是 1(而不是两者都是 1)时将 1 赋给结果位。Not 采用单个操作数并反转所有位(包括符号位),然后将该值赋予结果。这意味着,对于有符号正数,Not 始终返回负值,而对于负数,Not 始终返回正值或零。AndAlso 和OrElse 运算符不支持按位运算。 追问: 好复杂啊...还是不会,还有整数怎么转换为二进制数? 回答: 为什么一定要用位运算呢,你那个乘法只能通过左移操作符“