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

解决方案 »

  1.   

    这是因为VB6.0的Lable对象并不是继承于Control类,而是调用GDI直接向容器绘画的(所以VB6.0的Label在界面上是无法覆盖其它控件),这有点类似于VB6.0中的Line控件.而.NET中的所有控件都是继承于Control,有完整的hwnd和独立的hdc(这你可以从spy中检查得到),所以对于VB6.0中的轻量级的Lable来说,.NET中的Lable太庞大了,外理也复杂得多.所以要现实vb6.0中的高性能,你可以用gdi+来绘画实现.
      

  2.   

    我也是用GDI+画的,请问要画在什么上?
    我都是先建一个Control,然后在上面画
    按楼上的说话,这样画是不起作用的
      

  3.   

    如xfyxq(小小旗) (抵制日货) 同志所说,.net框架不支持所谓“轻量级”控件 ̄我遇到类似问题的解决方法是用一个DataGridView代替很多Label,仔细调整下外观,比如边框色底色什么的,可以做到与用Label的效果完全一样
      

  4.   

    我只是拿Lable打个比方
    我的控件是这样的:
      控件本身代表着一个港口,港口中停了很多船,每艘船都是一个Control(根据数据生成)
    船可以随意拖动,拖动的时候船本身的信息也根着变(如停泊位置、时间等),
    拖动的时候会有残影,经过其它船的时候也会有残影愁啊,如果.net实现不了,准备换个方案啦
      

  5.   

    using System;
    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事件好像有问题
    如果鼠标在上面不动 也会触发事件还有图形设计一般不会用到多少控件
      

  6.   

    楼上的兄弟
    你的代码试过没有?
    我有了不到10个Lable
    只有前几个Lable能正常显示
    其它的都反应迟顿........
      

  7.   

    测过 
    反映不是很慢
    1-0.4秒左右 全部刷新一遍
    VS 2005 sp1
    vista 下验证
      

  8.   

    .Left = .Left + e.X - x
                    Label1.Text = .Left & ""
                            |
                    Label4.Text = .Left & ""
    ----------------------------------------------------
    这几行代码是 CPU 用100的直接原因
    严重影响速度