VB代码如下:
Private l_PreX As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
l_PreX = X
End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lNp As Long
With Picture1
If Button = 1 Then
lNp = .Left + X - l_PreX
.Left = lNp
Label1.Caption = .Left
|
Label10.Caption = .Left
End If
End With
End Sub
----------------------------------------------------------------------------------------------------
.net代码如下:
Dim x As Integer Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
x = e.X
End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
With PictureBox1
.Left = .Left + e.X - x
Label1.Text = .Left & ""
|
Label4.Text = .Left & ""
End With
End If
End Sub
Private l_PreX As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
l_PreX = X
End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lNp As Long
With Picture1
If Button = 1 Then
lNp = .Left + X - l_PreX
.Left = lNp
Label1.Caption = .Left
|
Label10.Caption = .Left
End If
End With
End Sub
----------------------------------------------------------------------------------------------------
.net代码如下:
Dim x As Integer Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
x = e.X
End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
With PictureBox1
.Left = .Left + e.X - x
Label1.Text = .Left & ""
|
Label4.Text = .Left & ""
End With
End If
End Sub
解决方案 »
- 类似ie8的开发人员工具,或者Firefox的firebug ,这些可视化的html结构查看工具,是怎么实现的啊?
- 新手求解:UserControl控件如何继承?
- 【求救】C#中 SqlConnection ConnectionString 中密码既有 单引号 又有双引号 并且有分号 连接字符串怎么写呢
- 求算法
- C#生成的安装程序无法使用
- C# 清除绘图,显示背景图片
- 请问xp下能开发asp.net2.0吗?
- (Object)Class.forName(t_strServiceClassPath).newInstance()在.net中如何实现?
- c#中连接access数据库时 选择语句的写法问题??????????
- DataGrid中的问题
- XML文件
- 做一个ASP.NET网页
我都是先建一个Control,然后在上面画
按楼上的说话,这样画是不起作用的
我的控件是这样的:
控件本身代表着一个港口,港口中停了很多船,每艘船都是一个Control(根据数据生成)
船可以随意拖动,拖动的时候船本身的信息也根着变(如停泊位置、时间等),
拖动的时候会有残影,经过其它船的时候也会有残影愁啊,如果.net实现不了,准备换个方案啦
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WinformTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int temp = 0;
private void button1_Click(object sender, EventArgs e)
{
label1.Text = temp.ToString();
temp++;
label2.Text = temp.ToString();
temp++;
...........//108个label值改变
label108.Text = temp.ToString();
}
private Point mousePoint;
private bool DragPicture = false;
private bool F = false;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mousePoint = new Point(e.X, e.Y);
DragPicture = true;
} private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
F = true;
if (DragPicture)
{
if (F)
{
//pictureBox1.Location.X = pictureBox1.Location.X + (e.X - mousePoint.X);
//pictureBox1.Location.Y = pictureBox1.Location.Y + (e.Y - mousePoint.Y);
Point pp = new Point(pictureBox1.Location.X + (e.X - mousePoint.X), pictureBox1.Location.Y + (e.Y - mousePoint.Y));
pictureBox1.Location = pp;
Point p = new Point(e.X, e.Y);
if (e.X - mousePoint.X != 0 || e.Y - mousePoint.Y != 0)
{
button1_Click(null, null);
}
// mousePoint = p;
F=false;
}
}
} private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
DragPicture = false;
} private void pictureBox1_MouseHover(object sender, EventArgs e)
{
} }
}
---------------------------------------------------------------------------------
那你看看这个效率咋样
108 个Label
1个图片控件
CPU 大部分不会到100%
MouseMove事件好像有问题
如果鼠标在上面不动 也会触发事件还有图形设计一般不会用到多少控件
你的代码试过没有?
我有了不到10个Lable
只有前几个Lable能正常显示
其它的都反应迟顿........
反映不是很慢
1-0.4秒左右 全部刷新一遍
VS 2005 sp1
vista 下验证
Label1.Text = .Left & ""
|
Label4.Text = .Left & ""
----------------------------------------------------
这几行代码是 CPU 用100的直接原因
严重影响速度