发新话题
打印

[转载]vc++.net鼠标事件处理

[转载]vc++.net鼠标事件处理

文章作者:sunnlo
原始连接:http://hi.baidu.com/sunnlo/blog/ ... 9dd309b2de0538.html

代码如下:
复制内容到剪贴板
代码:
//Form1.h
//省略vc自动生成的代码

private:static bool shouldpaint=false;

private: System::Void Form1_MouseDown(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
   {
    shouldpaint=true;
   }

private: System::Void Form1_MouseUp(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
   {
    shouldpaint=false;
   }

private: System::Void Form1_MouseMove(System::Object *  sender, System::Windows::Forms::MouseEventArgs *  e)
   {
    if(shouldpaint){
    Graphics *graphics=CreateGraphics();
    graphics->FillEllipse(new SolidBrush(
     Color::BlueViolet),e->X,e->Y,4,4);
    }
   }

private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
   {
    MessageBox::Show(S"用鼠标在窗体上按下左键挪动就会画画\n我的qq是29899004");
   }
编译好的应用程序请到http://sunnlo.phpnet.us/mouse.exe下载

TOP

发新话题