重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Dim xx As Double, yy As Double
成都创新互联-专业网站定制、快速模板网站建设、高性价比息烽网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式息烽网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖息烽地区。费用合理售后完善,10余年实体公司更值得信赖。
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If xx = 0 And yy = 0 Then
xx = X: yy = Y
Else
Form1.Line (xx, yy)-(X, Y), 1
End If
xx = X: yy = Y
End Sub
我调试成功的例子。
1.在mouse事件中实现
2.调用windows API
实现方式为:
1.在mouse事件中实现
[csharp] view plain copy
Point mouseOff;//鼠标移动位置变量
bool leftFlag;//标签是否为左键
private void groupControl1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
private void groupControl1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
2.调用windows API
调用前需要添加using System.Runtime.InteropServices;
[csharp] view plain copy
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture(); //释放鼠标捕捉
//发送左键点击的消息至该窗体(标题栏)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
Dim
s
As
Boolean,
ci
As
Integer,
xianxing
As
Integer,
xiankuan
As
Integer
Dim
x0
As
Single,
y0
As
Single
Private
Sub
Command1_Click()
s
=
True
Command1.Enabled
=
False
End
Sub
Private
Sub
Form_Load()
Dim
b
b
=
Array("透明",
"实线",
"虚线",
"点线",
"点划线",
"双点划线")
Frame1.Move
100,
100,
1300,
3500
Frame1.Caption
=
"线型"
Frame2.Move
Width
-
1500,
100,
1300,
3500
Frame2.Caption
=
"线宽"
For
i
=
To
5
Option1(i).Move
100,
300
+
i
*
500,
1100,
300
Option1(i).Caption
=
b(i)
Option2(i).Move
100,
500
+
i
*
500,
800,
300
Option2(i).Caption
=
i
+
1
"点宽"
Next
i
Shape1(0).Visible
=
False
Shape1(1).Visible
=
False
s
=
ci
=
-1
Command1.Caption
=
"开始画圆"
Command1.ToolTipText
=
"点击按钮后在窗体内按下鼠标左键处为圆心,拖到半径处松开鼠标左键即可"
End
Sub
Private
Sub
Form_MouseDown(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
If
s
And
Button
=
1
Then
x0
=
X
y0
=
Y
ci
=
ci
+
1
If
ci
1
Then
Load
Shape1(ci)
Shape1(ci).Visible
=
True
Shape1(ci).BorderStyle
=
xianxing
Shape1(ci).Move
x0,
y0,
0,
Shape1(ci).Shape
=
3
Shape1(ci).BorderWidth
=
xiankuan
End
If
End
Sub
Private
Sub
Form_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
If
s
And
Button
=
1
Then
banjing
=
Sqr((x0
-
X)
*
(x0
-
X)
+
(y0
-
Y)
*
(y0
-
Y))
Shape1(ci).Move
x0
-
banjing,
y0
-
banjing,
2
*
banjing,
2
*
banjing
End
If
End
Sub
Private
Sub
Form_MouseUp(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
Command1.Enabled
=
True
s
=
False
End
Sub
Private
Sub
Option1_Click(Index
As
Integer)
For
i
=
To
5
If
Option1(i)
Then
xianxing
=
i
Next
i
If
i
=
1
Then
Frame2.Enabled
=
True
Else
Frame2.Enabled
=
False
xiankuan
=
1
End
If
End
Sub
Private
Sub
Option2_Click(Index
As
Integer)
For
i
=
To
5
If
Option2(i)
Then
xiankuan
=
1
+
i
Next
i
End
Sub
界面稍微复杂了点:
一个按钮,两个框架,第一框架上option1共六个,第二个框架上option2也是六个。