如何使一个控件在运行时也能如Microsoft Project中甘特图的任务时间条那样拉伸? OK啦,http://expert.csdn.net/Expert/topic/2235/2235675.xml?temp=.2538721请rouser(我是一棵秋天的树) 来领分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WindowsApplication1{ public class Form1 : System.Windows.Forms.Form { private int ox; private int oy; private Control control; private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(130, 115); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(278, 65); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove); this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 15); this.ClientSize = new System.Drawing.Size(536, 350); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; this.Text = "Form1"; this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(this.control == null) return; if(e.Button == MouseButtons.Left) { this.control.Width += (e.X - ox); this.control.Height += (e.Y - oy); } } private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { ox = e.X; oy = e.Y; this.Capture = true; } } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) this.Capture = false; } private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { this.control = (Control)sender; if(e.X > (this.control.ClientSize.Width - 4)) { this.Cursor = Cursors.SizeWE; if(e.Y > (this.control.ClientSize.Height - 4)) this.Cursor = Cursors.SizeNWSE; } else if(e.Y > (this.control.ClientSize.Height - 4)) this.Cursor = Cursors.SizeNS; else this.Cursor = Cursors.Default; } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.control = null; } }} 調試完了,這段代碼是對的 :)using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Diagnostics;using System.Data;namespace WindowsApplication1{ public class Form1 : System.Windows.Forms.Form { private int ox; private int oy; private Control control; private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.BackColor = System.Drawing.SystemColors.ControlDark; this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(130, 115); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(278, 104); this.button1.TabIndex = 0; this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove); this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 15); this.ClientSize = new System.Drawing.Size(536, 350); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; this.Text = "Form1"; this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(this.control == null) return; if(e.Button == MouseButtons.Left) { if(this.Cursor == Cursors.SizeWE) // <----> { this.control.Width += (e.X - ox); //Debug.WriteLine(this.control.Width.ToString()); ox = e.X; return; } if(this.Cursor == Cursors.SizeNS) { this.control.Height += (e.Y - oy); //Debug.WriteLine(this.control.Height.ToString()); oy = e.Y; return; } if(this.Cursor == Cursors.SizeNWSE) { this.control.Width += (e.X - ox); this.control.Height += (e.Y - oy); //Debug.WriteLine(this.control.Width.ToString()); //Debug.WriteLine(this.control.Height.ToString()); ox = e.X; oy = e.Y; return; } } } private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { ox = e.X + ((Control)sender).Left; oy = e.Y + ((Control)sender).Top; this.Capture = true; } } private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { this.control = (Control)sender; if(e.X > (this.control.ClientSize.Width - 4)) { this.Cursor = Cursors.SizeWE; // <----> if(e.Y > (this.control.ClientSize.Height - 4)) this.Cursor = Cursors.SizeNWSE; } else if(e.Y > (this.control.ClientSize.Height - 4)) this.Cursor = Cursors.SizeNS; else this.Cursor = Cursors.Default; } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { this.control = null; } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { this.Capture = false; this.Cursor = Cursors.Default; } } }} 我改了一下:private void Form3_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.X > (this.ClientSize.Width - 4)) { this.Cursor = Cursors.SizeWE; if(e.Y > (this.ClientSize.Height - 4)) { this.Cursor = Cursors.SizeNWSE; } } else if(e.Y > (this.ClientSize.Height - 4)) { this.Cursor = Cursors.SizeNS; } else this.Cursor = Cursors.Default; } private void Form3_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { ox = e.X; oy = e.Y; this.Capture = true; } } private void Form3_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if(ox > (this.ClientSize.Width - 4)) { this.Cursor = Cursors.SizeWE; if(e.Button == MouseButtons.Left) this.Width += (e.X - ox); if(oy > (this.ClientSize.Height - 4)) { this.Cursor = Cursors.SizeNWSE; if(e.Button == MouseButtons.Left) this.Height += (e.Y - oy); } } else if(oy > (this.ClientSize.Height - 4)) { this.Cursor = Cursors.SizeNS; if(e.Button == MouseButtons.Left) this.Height += (e.Y - oy); } else this.Cursor = Cursors.Default; } 这 幅图像 怎么打开 ? 怎么让Repeater的前三项显示的样式与其它项不一样 point运算符重载问题 如何设置控件默认工具箱选项卡? 正在使用.net2.0和VS2005的请进! 时间显示问题! WPF,Blend中的这个东西是什么意思? 怎么学习C#对于一个菜鸟 简单问题,求助,答着有分! 如何动态添加用户控件?例: 100万签名抗日活动还有几天就结束了,可因网站仿问太慢了,谁能提供空间?为国家而战!!! ASP.NET问题求救,各位大虾帮帮忙啊
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private int ox;
private int oy;
private Control control; private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(130, 115);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(278, 65);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(536, 350);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.control == null)
return; if(e.Button == MouseButtons.Left)
{
this.control.Width += (e.X - ox);
this.control.Height += (e.Y - oy);
}
} private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
ox = e.X;
oy = e.Y;
this.Capture = true;
}
} private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
this.Capture = false;
} private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.control = (Control)sender;
if(e.X > (this.control.ClientSize.Width - 4))
{
this.Cursor = Cursors.SizeWE;
if(e.Y > (this.control.ClientSize.Height - 4))
this.Cursor = Cursors.SizeNWSE;
}
else if(e.Y > (this.control.ClientSize.Height - 4))
this.Cursor = Cursors.SizeNS;
else
this.Cursor = Cursors.Default;
} private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.control = null;
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.Data;namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private int ox;
private int oy;
private Control control; private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ControlDark;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(130, 115);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(278, 104);
this.button1.TabIndex = 0;
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Control_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(536, 350);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "Form1";
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.control == null)
return; if(e.Button == MouseButtons.Left)
{
if(this.Cursor == Cursors.SizeWE) // <---->
{
this.control.Width += (e.X - ox);
//Debug.WriteLine(this.control.Width.ToString());
ox = e.X;
return;
} if(this.Cursor == Cursors.SizeNS)
{
this.control.Height += (e.Y - oy);
//Debug.WriteLine(this.control.Height.ToString());
oy = e.Y;
return;
} if(this.Cursor == Cursors.SizeNWSE)
{
this.control.Width += (e.X - ox);
this.control.Height += (e.Y - oy);
//Debug.WriteLine(this.control.Width.ToString());
//Debug.WriteLine(this.control.Height.ToString());
ox = e.X;
oy = e.Y;
return;
}
}
} private void Control_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
ox = e.X + ((Control)sender).Left;
oy = e.Y + ((Control)sender).Top;
this.Capture = true;
}
} private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.control = (Control)sender;
if(e.X > (this.control.ClientSize.Width - 4))
{
this.Cursor = Cursors.SizeWE; // <---->
if(e.Y > (this.control.ClientSize.Height - 4))
this.Cursor = Cursors.SizeNWSE;
}
else if(e.Y > (this.control.ClientSize.Height - 4))
this.Cursor = Cursors.SizeNS;
else
this.Cursor = Cursors.Default;
} private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.control = null;
} private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
this.Capture = false;
this.Cursor = Cursors.Default;
}
}
}
}
private void Form3_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.X > (this.ClientSize.Width - 4))
{
this.Cursor = Cursors.SizeWE;
if(e.Y > (this.ClientSize.Height - 4))
{
this.Cursor = Cursors.SizeNWSE;
}
}
else if(e.Y > (this.ClientSize.Height - 4))
{
this.Cursor = Cursors.SizeNS;
}
else
this.Cursor = Cursors.Default;
} private void Form3_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
ox = e.X;
oy = e.Y;
this.Capture = true;
}
} private void Form3_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(ox > (this.ClientSize.Width - 4))
{
this.Cursor = Cursors.SizeWE;
if(e.Button == MouseButtons.Left)
this.Width += (e.X - ox);
if(oy > (this.ClientSize.Height - 4))
{
this.Cursor = Cursors.SizeNWSE;
if(e.Button == MouseButtons.Left)
this.Height += (e.Y - oy);
}
}
else if(oy > (this.ClientSize.Height - 4))
{
this.Cursor = Cursors.SizeNS;
if(e.Button == MouseButtons.Left)
this.Height += (e.Y - oy);
}
else
this.Cursor = Cursors.Default;
}