请教:用vb能够写window自带画图程序中的矩形剪裁吗?谢谢。

 我来答
终雯
2011-09-27 · TA获得超过491个赞
知道答主
回答量:463
采纳率:0%
帮助的人:236万
展开全部
Dim x1 As Single, y1 As Single, s As Integer
Const pi = 3.14159265
Private Sub Form_Load()
Command1.Caption = "圆"
Command2.Caption = "矩形"
Command3.Caption = "三角"
Command4.Caption = "五角"
Command5.Caption = "清"
End Sub
Private Sub Command1_Click()
s = 1
End Sub

Private Sub Command2_Click()
s = 2
End Sub

Private Sub Command3_Click()
s = 3
End Sub

Private Sub Command4_Click()
s = 4
End Sub

Private Sub Command5_Click()
Picture1.Cls
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then x1 = x: y1 = y
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
Picture1.AutoRedraw = False
Picture1.Refresh
Picture1.PSet (x1, y1)
Select Case s
Case 1
Picture1.Circle (x1, y1), Sqr((x - x1) ^ 2 + (y - y1) ^ 2)
Case 2
Picture1.Line (x1, y1)-(x, y), , B
Case 3
duobianxing x1, y1, x, y, 3, 60
Case 4
duobianxing x1, y1, x, y, 5, 36
End Select
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
Picture1.AutoRedraw = True
Select Case s
Case 1
Picture1.Circle (x1, y1), Sqr((x - x1) ^ 2 + (y - y1) ^ 2)
Case 2
Picture1.Line (x1, y1)-(x, y), , B
Case 3
duobianxing x1, y1, x, y, 3, 60
Case 4
duobianxing x1, y1, x, y, 5, 36
End Select
End If
End Sub
'duobianxing函数参数:
'zhongxinX-多边形中心的横坐标
'zhongxinY-多边形中心的纵坐标
'dingdianX-多边形一个顶点的横坐标
'dingdianY-多边形一个顶点的纵坐标
'bianhuoxing-正多边形的边数或者星形的星角数,例如biaohuoxing=5,dingjiao=72则为正五边形,若dingjiao=36则为五角星(该函数将正多边形按相邻顶角点间的折点成直线的特殊星形绘制)
'dingjiao-多边形的顶角的角度(角度制°)
Function duobianxing(ByVal zhongxinX As Single, ByVal zhongxinY As Single, ByVal dingdianX As Single, ByVal dingdianY As Single, ByVal bianhuoxing As Integer, ByVal dingjiao As Single)
If bianhuoxing = 0 Then Exit Function
l = Sqr((zhongxinX - dingdianX) ^ 2 + (zhongxinY - dingdianY) ^ 2) '星形中心到顶角距离
t1 = Abs(Tan((dingjiao / 2) * pi / 180)) '星形顶角的1/2求正切
t2 = Abs(Tan((360 / (2 * bianhuoxing)) * pi / 180)) '星形每条边所对应的中心角的1/2求正切
r = l * t2 / (t1 + t2) / Cos((dingjiao / 2) * pi / 180) '星形边长
If zhongxinX = dingdianX Then '求星形中心到顶角这条线的角度j
j = IIf(dingdianY < zhongxinY, 90, -90)
Else
j = Atn((zhongxinY - dingdianY) / (dingdianX - zhongxinX)) * 180 / pi
If dingdianX < zhongxinX Then
If dingdianY > zhongxinY Then
j = j - 180
Else
j = j + 180
End If
End If
End If
j1 = j - dingjiao / 2 '边偏离初始角1
j2 = 360 / bianhuoxing + dingjiao + j - dingjiao / 2 '边偏离初始角2(如果是正多边形j1=j2)
px1 = dingdianX: py1 = dingdianY '指定星形的第一个顶点
For i = 1 To bianhuoxing * 2
If i Mod 2 = 0 Then
px2 = px1 + r * Cos(j2 * pi / 180): py2 = py1 - r * Sin(j2 * pi / 180) '指定星形下一个顶点
j2 = j2 + 360 / bianhuoxing '边偏角+2个边长对应的中心角
Else
px2 = px1 - r * Cos(j1 * pi / 180): py2 = py1 + r * Sin(j1 * pi / 180)
j1 = j1 + 360 / bianhuoxing
End If
Picture1.Line (px1, py1)-(px2, py2) '画线
px1 = px2: py1 = py2
Next
End Function
追问
您好,您没有看清我的提问,但您也很棒。
1048726239
2011-09-30 · 超过11用户采纳过TA的回答
知道答主
回答量:26
采纳率:0%
帮助的人:29.8万
展开全部
很简单的:
窗体上添加一个picture1,四个按钮
在picture1里画一个shape1
代码:
Private CutData() As Long '复制数据
Private CutWidth As Long '数据宽高
Private CutHeight As Long

Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3
Shape1.Visible = False
Shape1.BorderStyle = 3
ReDim CutData(0)
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Shape1.Left = X
Shape1.Top = Y
Shape1.Visible = True
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If X >= Shape1.Left Then Shape1.Width = X - Shape1.Left
If Y >= Shape1.Top Then Shape1.Height = Y - Shape1.Top
End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Shape1.Visible = False
End Sub

Private Sub Command1_Click() '剪掉
OptionColor 1
Picture1.Refresh
End Sub

Private Sub Command2_Click() '复制
OptionColor 3
Picture1.Refresh
End Sub

Private Sub Command3_Click() '粘贴
OptionColor 4
Picture1.Refresh
End Sub

Private Sub Command4_Click() '填充
For i = 1 To 100
For j = 1 To 100
Picture1.PSet (i, j), RGB(200, 200, 200)
Next
Next
End Sub

Private Sub OptionColor(ByVal OpCode As Integer)
Dim i As Long, j As Long, Idx As Long
Idx = -1
If OpCode = 4 Then Shape1.Width = CutWidth: Shape1.Height = CutHeight
For i = Shape1.Left To Shape1.Left + Shape1.Width
For j = Shape1.Top To Shape1.Top + Shape1.Height
Idx = Idx + 1
Select Case OpCode
Case 1 '删除
Picture1.PSet (i, j), Picture1.BackColor
Case 2 '剪切
ReDim Preserve CutData(Idx)
CutData(Idx) = Picture1.Point(i, j)
Picture1.PSet (i, j), Picture1.BackColor
CutWidth = i - Shape1.Left
CutHeight = j - Shape1.Top
Case 3 '复制
ReDim Preserve CutData(Idx)
CutData(Idx) = Picture1.Point(i, j)
CutWidth = i - Shape1.Left
CutHeight = j - Shape1.Top
Case 4 '粘贴
If Idx > UBound(CutData) Then Exit Sub
Picture1.PSet (i, j), CutData(Idx)
End Select
Next
Next
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式