MyEssay主类

FrmBase类,有些Bug.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using HANDLE = System.IntPtr;
using HWND = System.IntPtr;

namespace MyThread
{
 /** <summary>
 /// Form1 µÄժҪ˵Ã÷¡£
 /// </summary>
 public class FormBase : System.Windows.Forms.Form
 {
  private System.ComponentModel.IContainer components=null;
  Point location = new Point(0,0);
  Point p= new Point(0,0);
  Size size = new Size(800,600);
  bool isMax = false;
  private System.Windows.Forms.ContextMenu ControlMenu;
  private System.Windows.Forms.MenuItem menuItem6;
  private System.Windows.Forms.MenuItem menuRestore;
  private System.Windows.Forms.MenuItem menuMove;
  private System.Windows.Forms.MenuItem menuSize;
  private System.Windows.Forms.MenuItem menuMin;
  private System.Windows.Forms.MenuItem menuMax;
  private System.Windows.Forms.MenuItem menuClose;
  bool cursor=false;
  Graphics g = null;
  bool IsDiaLog = false;
  public const int WM_NCPAINT = 0x85;
  Color DeskTop = Color.FromArgb(122,150,223);
  Color Caption = Color.FromArgb(216,228,248);
 
  protected override void WndProc(ref Message m)
  {
  
   RectangleF rectf;
   switch (m.Msg)
   {
    case WM_NCPAINT :
     IntPtr hrgn = m.WParam;
     if ( hrgn != (IntPtr)1 )
     {
      Region rgn = Region.FromHrgn(hrgn);
      g = CreateGraphics();
      rectf = rgn.GetBounds(g);
      PaintNonClientArea(g, rectf);
     }
     else
     {
      g = CreateGraphics();
      rectf = new RectangleF(0,-23, Width, 23);
      PaintNonClientArea(g, rectf);
      g.Dispose();
     }
  
     //base.WndProc(ref m);
     break;
    default :
     base.WndProc (ref m);
     break;
   }
  }
  public bool isDialog
  {
   get
   {
    return IsDiaLog ;
   }
   set
   {
    IsDiaLog =value;
   }
  }
 
  void PaintNonClientArea(Graphics g,RectangleF r)
  {
   //this.PainWindow(g);
  }

  public FormBase()
  {
   //
   // Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ
   //
   InitializeComponent();
   this.MinimumSize = new Size(160,20);
   //int MyMenu = GetSystemMenu(this.Handle,0);
   this.FormBorderStyle=FormBorderStyle.None;
   //LoadMenu((IntPtr)MyMenu,"");
   //MessageBox.Show(MyMenu.ToString());
   //
   // TODO: ÔÚ InitializeComponent µ÷ÓúóÌí¼ÓÈκι¹Ô캯Êý´úÂë
   //
  }
  /** <summary>
  /// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
  protected override void OnPaint(PaintEventArgs e)
  {
   //int handle = Win32.User.GetWindowDC(this.Handle);
   g = this.CreateGraphics();
   //g = Graphics.FromHdc(((IntPtr)handle));
   if (!e.ClipRectangle.IsEmpty)
    this.PainWindow(g);
   //Win32.RECT Rect = new Win32.RECT();
   //Win32.User.GetWindowRect((IntPtr)handle,ref Rect);
   //Win32.User.ReleaseDC(this.Handle,(IntPtr)handle);
  }
  public override string Text
  {
   get
   {
    return base.Text;
   }
   set
   {
    DrawText(this.CreateGraphics());
    base.Text = value;
   }
  }

  protected override void OnMouseMove(MouseEventArgs e)
  {
   //this.Form1_MouseMove(this,e);
   base.OnMouseMove (e);
  }

  void PainWindow(Graphics gx)
  {
   Bitmap bmp = new Bitmap(this.Width,this.Height);
   Graphics g = Graphics.FromImage(bmp);
   Pen pen;
   //×ó±ß¿ò1
   pen = new Pen(Color.FromArgb(133,150,202));
   g.DrawLine(pen,new Point(0,0),new Point(0,this.Height));
   //Éϱ߿ò1
   g.DrawLine(pen,new Point(0,0),new Point(this.Width,0));
   pen = new Pen(Color.White);
   g.DrawLine(pen,new Point(1,1),new Point(1,this.Height-1));
   g.DrawLine(pen,new Point(1,1),new Point(this.Width-1,1));
   //Óұ߿ò1
   pen = new Pen(Color.FromArgb(90,108,162));
   g.DrawLine(pen,new Point(this.Width-1,1),new Point(this.Width-1,this.Height)); 
   //ϱ߿ò1
   g.DrawLine(pen,new Point(1,this.Height-1),new Point(this.Width,this.Height-1));
   pen = new Pen(Color.FromArgb(191,202,235));
   g.DrawLine(pen,new Point(this.Width-2,2),new Point(this.Width-2,this.Height-2));
   g.DrawLine(pen,new Point(2,this.Height-2),new Point(this.Width-2,this.Height-2));
   Brush brush = new SolidBrush(Color.FromArgb(206,216,239));
   g.FillRectangle(brush,2,2,this.Width-4,this.Height-4);
   if(this.BackColor.ToKnownColor()!=KnownColor.Control)
   {
    brush = new SolidBrush(this.BackColor);
    g.FillRectangle(brush,4,4,this.Width-8,this.Height-8);
   }
   else
   {
    this.BackColor = Caption;
    brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(4,4),new Size(this.Width-8,20)),Color.FromArgb(248,248,248),Color.FromArgb(220,226,240),3600,true);
    g.FillRectangle(brush,4,4,this.Width-8,this.Height-8);   
   }
   //»­±êÌâÀ¸
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(4,4),new Size(this.Width-8,20)),Color.FromArgb(192,208,240),Color.FromArgb(248,248,248),120,true);
   g.FillRectangle(brush,4,4,this.Width-8,20);
   //»­Í¼±êºÍ±êÌâ
   DrawIcon(g);
   DrawText(g);
   //»­°´Å¥
   if(!this.isDialog)
   {
    this.DrawMinButton1(g);
    if(this.MaximizeBox)
     this.DrawMaxButton1(g);
   }
   this.DrawCloseButton1(g);
   gx.DrawImage(bmp,0,0);
  }
  void DrawIcon(Graphics g)
  {
   g.DrawIcon(this.Icon,new Rectangle(new Point(6,6),new Size(16,16)));
  }
  void DrawText(Graphics g)
  {
   Brush brush = new SolidBrush(Color.FromArgb(61,77,129));
   g.DrawString(this.Text,new Font("tohoma",9),brush,new Point(26,6),StringFormat.GenericDefault);
  }
  void DrawMinButton1(Graphics g)
  {
   //×îС»¯
   Brush brush = new SolidBrush(Color.FromArgb(128,144,168));
   g.FillRectangle(brush,this.Width-57,6,16,16);
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(6,this.Width-63),new Size(17,17)),Color.FromArgb(199,207,231),Color.FromArgb(248,248,248),System.Drawing.Drawing2D. LinearGradientMode.Vertical);
   g.FillRectangle(brush,this.Width-56,7,14,14);
   Pen pen;
   if(this.MinimizeBox)
    pen = new Pen(Color.FromArgb(48,64,120),3);
   else
    pen = new Pen(Color.Silver,3);
   g.DrawLine(pen,new Point(this.Width-53,17),new Point(this.Width-46,17));
  }
  void DrawMinButton2(Graphics g)
  {
   //×îС»¯
   Brush brush = new SolidBrush(Color.FromArgb(128,144,168));
   g.FillRectangle(brush,this.Width-57,6,16,16);
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(6,this.Width-63),new Size(17,17)),Color.White,Color.Snow,System.Drawing.Drawing2D. LinearGradientMode.Vertical);
   g.FillRectangle(brush,this.Width-56,7,14,14);
   Pen pen;
   if(this.MinimizeBox)
    pen = new Pen(Color.FromArgb(48,64,120),3);
   else
    pen = new Pen(Color.Silver,3);
   g.DrawLine(pen,new Point(this.Width-53,17),new Point(this.Width-46,17));
  }
  void DrawMaxButton1(Graphics g)
  {
   //×î´ó»¯»òÕ߻ָ´
   Brush brush = new SolidBrush(Color.FromArgb(128,144,168));
   g.FillRectangle(brush,this.Width-40,6,16,16);
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(6,this.Width-63),new Size(17,17)),Color.FromArgb(199,207,231),Color.FromArgb(248,248,248),System.Drawing.Drawing2D. LinearGradientMode.Vertical);
   g.FillRectangle(brush,this.Width-39,7,14,14);
   if(!isMax)
   {
    brush = new SolidBrush(Color.FromArgb(48,64,120));
    g.FillRectangle(brush,this.Width-37,9,10,10);
    Pen pen = new Pen(Color.White,6);
    g.DrawLine(pen,new Point(this.Width-36,15),new Point(this.Width-28,15));
   }
   else
   {
    brush = new SolidBrush(Color.FromArgb(48,64,120));
    g.FillRectangle(brush,this.Width-34,9,7,7);
    Pen pen = new Pen(Color.White,4);
    g.DrawLine(pen,new Point(this.Width-33,13),new Point(this.Width-28,13));
    g.FillRectangle(brush,this.Width-37,12,7,7);
    g.DrawLine(pen,new Point(this.Width-36,16),new Point(this.Width-31,16));
   }
  }
  void DrawMaxButton2(Graphics g)
  {
   //×î´ó»¯»òÕ߻ָ´
   Brush brush = new SolidBrush(Color.FromArgb(128,144,168));
   g.FillRectangle(brush,this.Width-40,6,16,16);
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(6,this.Width-63),new Size(17,17)),Color.White,Color.Snow,System.Drawing.Drawing2D. LinearGradientMode.Vertical);
   g.FillRectangle(brush,this.Width-39,7,14,14);
   if(!isMax)
   {
    brush = new SolidBrush(Color.FromArgb(48,64,120));
    g.FillRectangle(brush,this.Width-37,9,10,10);
    Pen pen = new Pen(Color.White,6);
    g.DrawLine(pen,new Point(this.Width-36,15),new Point(this.Width-28,15));
   }
   else
   {
    brush = new SolidBrush(Color.FromArgb(48,64,120));
    g.FillRectangle(brush,this.Width-34,9,7,7);
    Pen pen = new Pen(Color.White,4);
    g.DrawLine(pen,new Point(this.Width-33,13),new Point(this.Width-28,13));
    g.FillRectangle(brush,this.Width-37,12,7,7);
    g.DrawLine(pen,new Point(this.Width-36,16),new Point(this.Width-31,16));
   }
  }
  void DrawCloseButton1(Graphics g)
  {
   //¹Ø±Õ
   Brush brush = new SolidBrush(Color.FromArgb(128,144,168));
   g.FillRectangle(brush,this.Width-23,6,16,16);
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(6,this.Width-63),new Size(17,17)),Color.FromArgb(199,207,231),Color.FromArgb(248,248,248),System.Drawing.Drawing2D. LinearGradientMode.Vertical);
   g.FillRectangle(brush,this.Width-22,7,14,14);
   Pen pen = new Pen(Color.FromArgb(48,64,120),2);
   g.DrawLine(pen,new Point(this.Width-20,9),new Point(this.Width-11,18));
   g.DrawLine(pen,new Point(this.Width-11,9),new Point(this.Width-20,18));
  }
  void DrawCloseButton2(Graphics g)
  {
   //¹Ø±Õ
   Brush brush = new SolidBrush(Color.FromArgb(128,144,168));
   g.FillRectangle(brush,this.Width-23,6,16,16);
   brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(new Point(6,this.Width-63),new Size(17,17)),Color.Red,Color.Snow,System.Drawing.Drawing2D. LinearGradientMode.Vertical);
   g.FillRectangle(brush,this.Width-22,7,14,14);
   Pen pen = new Pen(Color.FromArgb(48,64,120),2);
   g.DrawLine(pen,new Point(this.Width-20,9),new Point(this.Width-11,18));
   g.DrawLine(pen,new Point(this.Width-11,9),new Point(this.Width-20,18));
  }
   //Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
  
  #region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
   /** <summary>
   /// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼­Æ÷ÐÞ¸Ä
   /// ´Ë·½·¨µÄÄÚÈÝ¡£
   /// </summary>
   private void InitializeComponent()
   {
    this.ControlMenu = new System.Windows.Forms.ContextMenu();
    this.menuRestore = new System.Windows.Forms.MenuItem();
    this.menuMove = new System.Windows.Forms.MenuItem();
    this.menuSize = new System.Windows.Forms.MenuItem();
    this.menuMin = new System.Windows.Forms.MenuItem();
    this.menuMax = new System.Windows.Forms.MenuItem();
    this.menuItem6 = new System.Windows.Forms.MenuItem();
    this.menuClose = new System.Windows.Forms.MenuItem();
    //
    // ControlMenu
    //
    this.ControlMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuRestore,
                       this.menuMove,
                       this.menuSize,
                       this.menuMin,
                       this.menuMax,
                       this.menuItem6,
                       this.menuClose});
    //
    // menuRestore
    //
    this.menuRestore.Enabled = false;
    this.menuRestore.Index = 0;
    this.menuRestore.Text = "&Rstore";
    //
    // menuMove
    //
    this.menuMove.Index = 1;
    this.menuMove.Text = "&Move";
    this.menuMove.Click += new System.EventHandler(this.menuMove_Click);
    //
    // menuSize
    //
    this.menuSize.Index = 2;
    this.menuSize.Text = "&Size";
    this.menuSize.Click += new System.EventHandler(this.menuSize_Click);
    //
    // menuMin
    //
    this.menuMin.Index = 3;
    this.menuMin.Text = "Mi&nimize";
    this.menuMin.Click += new System.EventHandler(this.menuMin_Click);
    //
    // menuMax
    //
    this.menuMax.Index = 4;
    this.menuMax.Text = "Ma&ximize";
    this.menuMax.Click += new System.EventHandler(this.menuMax_Click);
    //
    // menuItem6
    //
    this.menuItem6.Index = 5;
    this.menuItem6.Text = "-";
    //
    // menuClose
    //
    this.menuClose.DefaultItem = true;
    this.menuClose.Index = 6;
    this.menuClose.Shortcut = System.Windows.Forms.Shortcut.AltF4;
    this.menuClose.Text = "&Close";
    this.menuClose.Click += new System.EventHandler(this.menuClose_Click);
    //
    // FormBase
    //
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(552, 416);
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    this.Name = "FormBase";
    this.Text = "Form1";
    this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
    this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
    this.Load += new System.EventHandler(this.WuyinMsnForm_Load);
    this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick);
    this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.LocationChanged += new System.EventHandler(this.Form1_LocationChanged);
    this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);

   }
  #endregion
  protected override void OnCreateControl()
  {
   base.OnCreateControl ();
  }
  private void Form1_DoubleClick(object sender, EventArgs e)
  {
   if(!this.isDialog)
   {
    Point p = new Point(0,0);
    GetCursorPos(out p);
    if(p.X - this.Location.X>=this.Width-70 || p.Y - this.Location.Y>=20)
     return;
    if(this.Size.Width >=Screen.AllScreens[0].WorkingArea.Size.Width && this.Size.Height>=Screen.AllScreens[0].WorkingArea.Size.Height)
     Restore();
    else
    {
     Max();
    }
   }
  }
  [DllImport("user32")] public static extern int GetCursorPos(out Point lpPoint);
  [DllImport("user32")] public static extern int GetSystemMenu(HWND hwnd, int bRevert);
  [DllImport("user32")] public static extern int LoadMenu(HANDLE hInstance, string lpString);
  //[DllImport("user32")] public static extern int MoveWindow(HWND hwnd, int x, int y, int nWidth, int nHeight, int bRepaint);
  void Restore()
  {
   //MessageBox.Show(String.Format("W:{0},H:{1}",size.Width,size.Height));
   this.Size=this.size;
   this.Location = this.location;
   this.WindowState=FormWindowState.Normal;
   this.isMax=false;
   this.Invalidate();
   this.menuMax.Enabled=true;
   this.menuRestore.Enabled=false;
   this.menuSize.Enabled=true;
   this.menuMove.Enabled=true;
   //this.PainWindow(g);
  }
  void Max()
  {
   //MessageBox.Show(String.Format("W:{0},H:{1}",size.Width,size.Height));
   //this.location = this.Location;
   //this.size = this.Size;
   this.isMax = true;
   this.Size = Screen.AllScreens[0].WorkingArea.Size;
   this.Location=new Point(0,0);
   this.Invalidate();
   this.menuMax.Enabled=false;
   this.menuRestore.Enabled=true;
   this.menuSize.Enabled=false;
   this.menuMove.Enabled=false;
   //this.PainWindow(g);
  }
  void CgBt(MouseEventArgs e)
  {
   if(e.X>this.Width-23 && e.X<this.Width-7 && e.Y>7 && e.Y<20)
   {
    this.DrawCloseButton2(g);
    return;
   }
   else
   {
    this.DrawCloseButton1(g);
   } 
   if(this.isDialog)
    return;  
   if(e.X>this.Width-57 && e.X<this.Width-41 && e.Y>7 && e.Y<22)
   {
    this.DrawMinButton2(g);
    return;
   }
   else
   {
    this.DrawMinButton1(g);
   }
   if(e.X>this.Width-40 && e.X<this.Width-24 && e.Y>7 && e.Y<22)
   {
    this.DrawMaxButton2(g);
    return;
   }
   else
   {
    this.DrawMaxButton1(g);  
   }
  }
  private void Form1_MouseMove(object sender, MouseEventArgs e)
  { 
   if(e.X>this.Width-70 && e.Y<25)
    CgBt(e); 
   if(isMax)
    return;
   CursorResizeForm(e,this);
   if(e.Button==MouseButtons.Left && e.Y>0 && e.Y<30 && e.X<this.Width-70 && e.Y<=20)
    this.Location=new Point(Control.MousePosition.X-p.X,Control.MousePosition.Y-p.Y);
  }
  private void CursorResizeForm(MouseEventArgs e,Control control)
  {   //Êó±ê¿ØÖÆ´°Ìå´óС
   if(e.Y>control.Height-10 && e.Y<control.Height && e.X>control.Width-10 && e.X<control.Width)
    control.Cursor=System.Windows.Forms.Cursors.SizeNWSE;
   else if(e.X>control.Width-6 && e.X<control.Width && control.Cursor!=System.Windows.Forms.Cursors.SizeNWSE)
    control.Cursor=System.Windows.Forms.Cursors.SizeWE;
   else if(e.Y>control.Height-6 && e.Y<control.Height && control.Cursor!=System.Windows.Forms.Cursors.SizeNWSE)
    control.Cursor=System.Windows.Forms.Cursors.SizeNS;
   else if(e.X>0 && e.X<6 && control.Cursor!=System.Windows.Forms.Cursors.SizeNESW)
    control.Cursor=System.Windows.Forms.Cursors.SizeWE;
   else if(!cursor)
    control.Cursor=Cursors.Default;
   if(e.Button==MouseButtons.Left)
   {
    if(control.Cursor==System.Windows.Forms.Cursors.SizeWE && e.X>16)
     control.Width=Control.MousePosition.X-control.Left+3;
    else if(control.Cursor==Cursors.SizeNWSE)
    {
     control.Width=Control.MousePosition.X-control.Left+3;
     control.Height=Control.MousePosition.Y-control.Top+3;
    }
    else if(control.Cursor==System.Windows.Forms.Cursors.SizeNS)
     control.Height=Control.MousePosition.Y-control.Top+3;
   }
  }
  private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  {
   if(this.isDialog)
    return;
   cursor=true;
   p=new Point(e.X,e.Y);
   //location = this.Location;
   //size = this.Size;
   if(e.Button==MouseButtons.Right && e.X>0 && e.X<this.Width - 70  && e.Y>0 && e.Y<22)
   {
    this.ControlMenu.Show(this,new Point(e.X,e.Y));
    return;
   }
   if(e.Button==MouseButtons.Left  && e.X>0 && e.X<26 && e.Y>0 && e.Y<22)
    this.ControlMenu.Show(this,new Point(0,20));
  }
  private void Form1_MouseUp(object sender, MouseEventArgs e)
  {
   if(e.Button!=MouseButtons.Left)
    return;
   cursor=false;
   //Èý¸ö¿ØÖÆ°´Å¥µÄ
   if(e.X>this.Width-24 && e.X<this.Width-6 && e.Y>7 && e.Y<20)
    Close();
   if(this.isDialog)
    return;
   if(e.X>this.Width-57 && e.X<this.Width-48 && e.Y>7 && e.Y<20)
    this.WindowState=FormWindowState.Minimized;
   if(e.X>this.Width-48 && e.X<this.Width-23 && e.Y>7 && e.Y<20)
   {
    if(isMax)
     Restore();
    else
     Max();    
   }
  }
  private void Form1_SizeChanged(object sender, EventArgs e)
  {
   if(this.Size.Width<=20 || this.Size.Height<=20)
    return;
   if(!isMax)
   {
    this.location = this.Location;
    this.size=this.Size;
   }
   //this.PainWindow(g);
  }
  protected override void DefWndProc(ref Message m)
  {
   //MessageBox.Show(m.ToString());
   base.DefWndProc (ref m);
  }

  private void Form1_KeyDown(object sender, KeyEventArgs e)
  {
   if(e.Alt && e.KeyCode==Keys.Space)
    this.ControlMenu.Show(this,new Point(4,22)); 
  }
  private void menuClose_Click(object sender, System.EventArgs e)
  {
   Close();
  }
  private void menuMax_Click(object sender, System.EventArgs e)
  {
   Max();
  }
  private void menuMin_Click(object sender, System.EventArgs e)
  {
   this.WindowState=FormWindowState.Minimized;
  }
  private void menuSize_Click(object sender, System.EventArgs e)
  {
   Pen pen = new Pen(Color.Black,4);
   g.DrawLine(pen,new Point(0,0),new Point(0,this.Height));
   g.DrawLine(pen,new Point(0,0),new Point(this.Width,0));
   g.DrawLine(pen,new Point(this.Width,0),new Point(this.Width,this.Height));
   g.DrawLine(pen,new Point(0,this.Height),new Point(this.Width,this.Height));
   this.Cursor = Cursors.SizeAll;
  }
  private void menuMove_Click(object sender, System.EventArgs e)
  {
   Pen pen = new Pen(Color.Black,4);
   g.DrawLine(pen,new Point(0,0),new Point(0,this.Height));
   g.DrawLine(pen,new Point(0,0),new Point(this.Width,0));
   g.DrawLine(pen,new Point(this.Width,0),new Point(this.Width,this.Height));
   g.DrawLine(pen,new Point(0,this.Height),new Point(this.Width,this.Height));
   mouse_event(MouseEvents.MOUSEEVENTF_MOVE,this.Location.X + this.Width/2,this.Location.Y + this.Height/2,0,0);
   //MoveWindow(this.Handle,0,0,this.Width,this.Height,0);
   this.Cursor = Cursors.SizeAll;
  }
  /** <summary>
  /// Ä£ÄâÊó±êʼþ
  /// </summary>
  /// <param name="dwFlags">Êó±êʼþµÄEnum</param>
  /// <param name="dx">X×ù±ê</param>
  /// <param name="dy">Y×ù±ê</param>
  /// <param name="cButtons"></param>
  /// <param name="dwExtraInfo"></param>
  [DllImport("user32.dll")]
  public static extern void mouse_event (MouseEvents dwFlags,long dx, long dy,long cButtons,long dwExtraInfo);
  /** <summary>
  /// ¶¨ÒåÄ£ÄâÊó±êµÄ³£Êý
  /// </summary>
  public enum MouseEvents:uint
  {
   MOUSEEVENTF_LEFTDOWN = 0x2,
   MOUSEEVENTF_LEFTUP = 0x4,
   MOUSEEVENTF_MIDDLEDOWN = 0x20,
   MOUSEEVENTF_MIDDLEUP = 0x40,
   MOUSEEVENTF_MOVE = 0x1,
   MOUSEEVENTF_ABSOLUTE = 0x8000,
   MOUSEEVENTF_RIGHTDOWN = 0x8,
   MOUSEEVENTF_RIGHTUP = 0x10,
  }
  private void Form1_LocationChanged(object sender, EventArgs e)
  {
   if(!isMax)
    location=Location;
  }
  protected override void OnControlAdded(ControlEventArgs e)
  {
  
   if(e.Control.Top<24)e.Control.Top += 24;
   if(e.Control.Left<2)e.Control.Left+=2;
  
   /**//*
   if(e.Control.BackColor.ToKnownColor()==KnownColor.Control)
   { 
     //((MyControl)e.Control).DoPaint();
     //Color c = Color.FromArgb(255,220,226,240);
     //e.Control.BackColor=c; 
     int C = (Win32.GDI.GetPixel((IntPtr)Win32.User.GetWindowDC((IntPtr)0),e.Control.Location.X,e.Control.Location.Y));
     Color c = Color.FromName(C.ToString());
     e.Control.BackColor = c;
   }
   base.OnControlAdded (e);
   */
  }
  private void WuyinMsnForm_Load(object sender, System.EventArgs e)
  {
   this.Height+=22;
   this.Width+=2;
  }
 }
}
主要是一个主窗体

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值