曾花了一些时间研究如果实现水晶报表设计器里那种所见即所得的效果,后由于时间问题,只实现了线段、文本框、矩形的实现,包括可画,可选择,可拖动,可删除,可任意改变大小(线段两个点,矩形八个点),用到了c1控件,大家想看效果的话需要安装一下,或者email我,我会把文件发给大家。
Email:alldj@vnet.citiz.net
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace AlldjReport
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.ComponentModel.IContainer components;
private ATextBox ATB=new ATextBox();
private bool enter=false;
private Point leftpoint;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private Point rightpoint;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.Panel panel3;
private int num=-1;
private int panel3scrollx=0;
private System.Windows.Forms.MenuItem menuItem16;
private int panel3scrolly=0;
private C1.Win.C1Command.C1OutBar c1OutBar1;
private C1.Win.C1Command.C1OutPage c1OutPage1;
private C1.Win.C1Command.C1ToolBar c1ToolBar1;
private C1.Win.C1Command.C1CommandHolder c1CommandHolder1;
private System.Windows.Forms.ImageList imageList1;
private C1.Win.C1Command.C1CommandLink c1CommandLink1;
private C1.Win.C1Command.C1CommandLink c1CommandLink2;
private C1.Win.C1Command.C1CommandLink c1CommandLink3;
private C1.Win.C1Command.C1Command c1Command1;
private C1.Win.C1Command.C1Command c1Command2;
private C1.Win.C1Command.C1Command c1Command3;
private C1.Win.C1Command.C1OutPage c1OutPage2;
private C1.Win.C1Command.C1ToolBar c1ToolBar2;
private C1.Win.C1Command.C1CommandLink c1CommandLink4;
private C1.Win.C1Command.C1CommandLink c1CommandLink5;
private C1.Win.C1Command.C1Command c1Command4;
private C1.Win.C1Command.C1Command c1Command5;
private C1.Win.C1Command.C1CommandLink c1CommandLink6;
private C1.Win.C1Command.C1Command c1Command6;
private const int _LEFT=50;
private System.Windows.Forms.MenuItem menuItem17;
private System.Windows.Forms.MenuItem menuItem18;
private System.Windows.Forms.RichTextBox richTextBox1;
private const int _TOP=20;
private bool write=false;
private int writebind=-1;
private BoxType bt;
private int movenum=-1;
private bool newenter=false;
private Drag dg;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.panel1 = new System.Windows.Forms.Panel();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.panel2 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem16 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.menuItem17 = new System.Windows.Forms.MenuItem();
this.menuItem18 = new System.Windows.Forms.MenuItem();
this.c1OutBar1 = new C1.Win.C1Command.C1OutBar();
this.c1OutPage1 = new C1.Win.C1Command.C1OutPage();
this.c1ToolBar1 = new C1.Win.C1Command.C1ToolBar();
this.c1CommandHolder1 = new C1.Win.C1Command.C1CommandHolder();
this.c1Command1 = new C1.Win.C1Command.C1Command();
this.c1Command2 = new C1.Win.C1Command.C1Command();
this.c1Command3 = new C1.Win.C1Command.C1Command();
this.c1Command4 = new C1.Win.C1Command.C1Command();
this.c1Command5 = new C1.Win.C1Command.C1Command();
this.c1Command6 = new C1.Win.C1Command.C1Command();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.c1CommandLink6 = new C1.Win.C1Command.C1CommandLink();
this.c1CommandLink1 = new C1.Win.C1Command.C1CommandLink();
this.c1CommandLink2 = new C1.Win.C1Command.C1CommandLink();
this.c1CommandLink3 = new C1.Win.C1Command.C1CommandLink();
this.c1OutPage2 = new C1.Win.C1Command.C1OutPage();
this.c1ToolBar2 = new C1.Win.C1Command.C1ToolBar();
this.c1CommandLink4 = new C1.Win.C1Command.C1CommandLink();
this.c1CommandLink5 = new C1.Win.C1Command.C1CommandLink();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.c1OutBar1)).BeginInit();
this.c1OutBar1.SuspendLayout();
this.c1OutPage1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.c1CommandHolder1)).BeginInit();
this.c1OutPage2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.AutoScroll = true;
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.richTextBox1);
this.panel1.Cursor = System.Windows.Forms.Cursors.Default;
this.panel1.Location = new System.Drawing.Point(2, 2);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(420, 594);
this.panel1.TabIndex = 0;
this.panel1.Click += new System.EventHandler(this.panel1_Click);
this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
this.panel1.DoubleClick += new System.EventHandler(this.panel1_DoubleClick);
this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
this.panel1.MouseLeave += new System.EventHandler(this.panel1_MouseLeave);
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
//
// richTextBox1
//
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.richTextBox1.Font = new System.Drawing.Font("宋体", 12F);
this.richTextBox1.Location = new System.Drawing.Point(280, 508);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(130, 78);
this.richTextBox1.TabIndex = 7;
this.richTextBox1.Text = "";
this.richTextBox1.Visible = false;
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Text = "删除";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// panel2
//
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel2.Controls.Add(this.panel3);
this.panel2.Location = new System.Drawing.Point(190, 6);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(484, 626);
this.panel2.TabIndex = 2;
//
// panel3
//
this.panel3.AutoScroll = true;
this.panel3.Controls.Add(this.panel1);
this.panel3.Location = new System.Drawing.Point(48, 18);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(424, 598);
this.panel3.TabIndex = 4;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem17});
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5,
this.menuItem6,
this.menuItem7,
this.menuItem8,
this.menuItem9,
this.menuItem11});
this.menuItem2.Text = "文件";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Text = "新建报表";
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Text = "打开报表";
//
// menuItem7
//
this.menuItem7.Index = 2;
this.menuItem7.Text = "保存";
//
// menuItem8
//
this.menuItem8.Index = 3;
this.menuItem8.Text = "保存为...";
//
// menuItem9
//
this.menuItem9.Index = 4;
this.menuItem9.Text = "打印";
//
// menuItem11
//
this.menuItem11.Index = 5;
this.menuItem11.Text = "退出";
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem10,
this.menuItem16});
this.menuItem3.Text = "设置";
//
// menuItem10
//
this.menuItem10.Index = 0;
this.menuItem10.Text = "打印机设置";
//
// menuItem16
//
this.menuItem16.Index = 1;
this.menuItem16.Text = "数据集绑定";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem12,
this.menuItem13,
this.menuItem14,
this.menuItem15});
this.menuItem4.Text = "编辑";
//
// menuItem12
//
this.menuItem12.Index = 0;
this.menuItem12.Text = "剪切";
//
// menuItem13
//
this.menuItem13.Index = 1;
this.menuItem13.Text = "复制";
//
// menuItem14
//
this.menuItem14.Index = 2;
this.menuItem14.Text = "粘贴";
//
// menuItem15
//
this.menuItem15.Index = 3;
this.menuItem15.Text = "删除";
//
// menuItem17
//
this.menuItem17.Index = 3;
this.menuItem17.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem18});
this.menuItem17.Text = "帮助";
//
// menuItem18
//
this.menuItem18.Index = 0;
this.menuItem18.Text = "版本";
this.menuItem18.Click += new System.EventHandler(this.menuItem18_Click);
//
// c1OutBar1
//
this.c1OutBar1.Controls.Add(this.c1OutPage1);
this.c1OutBar1.Controls.Add(this.c1OutPage2);
this.c1OutBar1.Location = new System.Drawing.Point(6, 8);
this.c1OutBar1.LookAndFeel = C1.Win.C1Command.LookAndFeelEnum.WindowsXP;
this.c1OutBar1.Name = "c1OutBar1";
this.c1OutBar1.SelectedIndex = 0;
this.c1OutBar1.Size = new System.Drawing.Size(98, 228);
this.c1OutBar1.Text = "c1OutBar1";
//
// c1OutPage1
//
this.c1OutPage1.Controls.Add(this.c1ToolBar1);
this.c1OutPage1.ImageIndex = -1;
this.c1OutPage1.Location = new System.Drawing.Point(0, 18);
this.c1OutPage1.Name = "c1OutPage1";
this.c1OutPage1.Size = new System.Drawing.Size(98, 192);
this.c1OutPage1.TabIndex = 0;
this.c1OutPage1.Text = "设计";
//
// c1ToolBar1
//
this.c1ToolBar1.AutoSize = false;
this.c1ToolBar1.ButtonLayoutVert = C1.Win.C1Command.ButtonLayoutEnum.TextOnRight;
this.c1ToolBar1.ButtonLookVert = C1.Win.C1Command.ButtonLookFlags.TextAndImage;
this.c1ToolBar1.CommandHolder = this.c1CommandHolder1;
this.c1ToolBar1.CommandLinks.Add(this.c1CommandLink6);
this.c1ToolBar1.CommandLinks.Add(this.c1CommandLink1);
this.c1ToolBar1.CommandLinks.Add(this.c1CommandLink2);
this.c1ToolBar1.CommandLinks.Add(this.c1CommandLink3);
this.c1ToolBar1.Dock = System.Windows.Forms.DockStyle.Fill;
this.c1ToolBar1.Horizontal = false;
this.c1ToolBar1.Location = new System.Drawing.Point(0, 0);
this.c1ToolBar1.Movable = false;
this.c1ToolBar1.Name = "c1ToolBar1";
this.c1ToolBar1.Size = new System.Drawing.Size(98, 192);
this.c1ToolBar1.Text = "Page1";
//
// c1CommandHolder1
//
this.c1CommandHolder1.Commands.Add(this.c1Command1);
this.c1CommandHolder1.Commands.Add(this.c1Command2);
this.c1CommandHolder1.Commands.Add(this.c1Command3);
this.c1CommandHolder1.Commands.Add(this.c1Command4);
this.c1CommandHolder1.Commands.Add(this.c1Command5);
this.c1CommandHolder1.Commands.Add(this.c1Command6);
this.c1CommandHolder1.ImageList = this.imageList1;
this.c1CommandHolder1.Owner = this;
//
// c1Command1
//
this.c1Command1.ImageIndex = 2;
this.c1Command1.Name = "c1Command1";
this.c1Command1.Text = "文本";
this.c1Command1.Click += new C1.Win.C1Command.ClickEventHandler(this.c1Command1_Click);
//
// c1Command2
//
this.c1Command2.ImageIndex = 1;
this.c1Command2.Name = "c1Command2";
this.c1Command2.Text = "New Command";
this.c1Command2.Click += new C1.Win.C1Command.ClickEventHandler(this.c1Command2_Click);
//
// c1Command3
//
this.c1Command3.ImageIndex = 0;
this.c1Command3.Name = "c1Command3";
this.c1Command3.Text = "New Command";
this.c1Command3.Click += new C1.Win.C1Command.ClickEventHandler(this.c1Command3_Click);
//
// c1Command4
//
this.c1Command4.ImageIndex = 4;
this.c1Command4.Name = "c1Command4";
this.c1Command4.Text = "New Command";
this.c1Command4.Click += new C1.Win.C1Command.ClickEventHandler(this.c1Command4_Click);
//
// c1Command5
//
this.c1Command5.ImageIndex = 3;
this.c1Command5.Name = "c1Command5";
this.c1Command5.Text = "New Command";
this.c1Command5.Click += new C1.Win.C1Command.ClickEventHandler(this.c1Command5_Click);
//
// c1Command6
//
this.c1Command6.Checked = true;
this.c1Command6.ImageIndex = 5;
this.c1Command6.Name = "c1Command6";
this.c1Command6.Text = "指针";
this.c1Command6.Click += new C1.Win.C1Command.ClickEventHandler(this.c1Command6_Click);
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// c1CommandLink6
//
this.c1CommandLink6.Command = this.c1Command6;
this.c1CommandLink6.Text = "指针";
//
// c1CommandLink1
//
this.c1CommandLink1.ButtonLook = C1.Win.C1Command.ButtonLookFlags.TextAndImage;
this.c1CommandLink1.Command = this.c1Command1;
this.c1CommandLink1.Text = "文本";
//
// c1CommandLink2
//
this.c1CommandLink2.ButtonLook = C1.Win.C1Command.ButtonLookFlags.TextAndImage;
this.c1CommandLink2.Command = this.c1Command2;
this.c1CommandLink2.Text = "线段";
//
// c1CommandLink3
//
this.c1CommandLink3.ButtonLook = C1.Win.C1Command.ButtonLookFlags.TextAndImage;
this.c1CommandLink3.Command = this.c1Command3;
this.c1CommandLink3.Text = "线框";
//
// c1OutPage2
//
this.c1OutPage2.Controls.Add(this.c1ToolBar2);
this.c1OutPage2.ImageIndex = -1;
this.c1OutPage2.Location = new System.Drawing.Point(0, 36);
this.c1OutPage2.Name = "c1OutPage2";
this.c1OutPage2.Size = new System.Drawing.Size(98, 174);
this.c1OutPage2.TabIndex = 1;
this.c1OutPage2.Text = "设置";
//
// c1ToolBar2
//
this.c1ToolBar2.AutoSize = false;
this.c1ToolBar2.ButtonLayoutVert = C1.Win.C1Command.ButtonLayoutEnum.TextOnRight;
this.c1ToolBar2.ButtonLookVert = C1.Win.C1Command.ButtonLookFlags.TextAndImage;
this.c1ToolBar2.CommandHolder = this.c1CommandHolder1;
this.c1ToolBar2.CommandLinks.Add(this.c1CommandLink4);
this.c1ToolBar2.CommandLinks.Add(this.c1CommandLink5);
this.c1ToolBar2.Dock = System.Windows.Forms.DockStyle.Fill;
this.c1ToolBar2.Horizontal = false;
this.c1ToolBar2.Location = new System.Drawing.Point(0, 0);
this.c1ToolBar2.Movable = false;
this.c1ToolBar2.Name = "c1ToolBar2";
this.c1ToolBar2.Size = new System.Drawing.Size(98, 174);
this.c1ToolBar2.Text = "Page2";
//
// c1CommandLink4
//
this.c1CommandLink4.Command = this.c1Command5;
this.c1CommandLink4.Text = "打印机设置";
//
// c1CommandLink5
//
this.c1CommandLink5.Command = this.c1Command4;
this.c1CommandLink5.Text = "数据集绑定";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(682, 637);
this.Controls.Add(this.c1OutBar1);
this.Controls.Add(this.panel2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "报表配置打印系统";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.c1OutBar1)).EndInit();
this.c1OutBar1.ResumeLayout(false);
this.c1OutPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.c1CommandHolder1)).EndInit();
this.c1OutPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
panel2.Paint +=new PaintEventHandler(panel2_Paint);
}
private void panel2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
RectangleF Rect;
SolidBrush B = new SolidBrush(Color.Green);
StringFormat Ll=new StringFormat();
Ll.Alignment=System.Drawing.StringAlignment.Near;
System.Drawing.Pen insideLine=new Pen(Color.Black,0.1F);
System.Drawing.Pen p2Line=new Pen(Color.Orange,0.1F);
int j=0;
for (int i=_LEFT;i<=_LEFT+this.panel3.Width+2;)
{
j=2-panel1.Left+_LEFT;
if(Math.Abs((i-j))%10>0)
{
i++;
continue;
}
else if((Math.Abs((i-j))%10==0)&&(Math.Abs((i-j))%20>0))
{
e.Graphics.DrawLine(insideLine,new Point(i,0),new Point(i,3));
i=i+10;
}
else
{
e.Graphics.DrawLine(insideLine,new Point(i,0),new Point(i,6));
Rect=new RectangleF((float)i,6f,20f,20f);
if (j-_LEFT==0)
{
e.Graphics.DrawString(Convert.ToString((int)Math.Abs((i-_LEFT))/(int)20+(int)(Math.Abs((j-_LEFT))/20)),new Font("Arial",7),B,Rect,Ll);
}
else
{
e.Graphics.DrawString(Convert.ToString((int)Math.Abs((i-_LEFT))/(int)20+1+(int)(Math.Abs((j-_LEFT))/20)),new Font("Arial",7),B,Rect,Ll);
}
i=i+10;
}
}
for (int i=_TOP;i<=_TOP+panel3.Height+2;)
{
j=2-panel1.Top+_TOP;
if(Math.Abs((i-j))%10>0)
{
i++;
continue;
}
else if((Math.Abs((i-j))%10==0)&&(Math.Abs((i-j))%20>0))
{
e.Graphics.DrawLine(insideLine,new Point(0,i),new Point(3,i));
i=i+10;
}
else
{
e.Graphics.DrawLine(insideLine,new Point(0,i),new Point(6,i));
Rect=new RectangleF(6f,(float)i,20f,20f);
if (j-_TOP==0)
{
e.Graphics.DrawString(Convert.ToString((int)(Math.Abs(i-_TOP))/(int)20+(int)((j-_TOP)/20)),new Font("Arial",7),B,Rect,Ll);
}
else
{
e.Graphics.DrawString(Convert.ToString((int)(Math.Abs(i-_TOP))/(int)20+1+(int)((j-_TOP)/20)),new Font("Arial",7),B,Rect,Ll);
}
i=i+10;
}
}
}
private void draw_box(object sender,System.Windows.Forms.PaintEventArgs e,System.Drawing.Pen pen,Point p1,Point p2)
{
e.Graphics.DrawLine(pen,p1,new Point(p2.X,p1.Y));
e.Graphics.DrawLine(pen,new Point(p2.X,p1.Y),p2);
e.Graphics.DrawLine(pen,new Point(p1.X,p2.Y),p2);
e.Graphics.DrawLine(pen,p1,new Point(p1.X,p2.Y));
}
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if ((panel3scrollx!=this.panel3.AutoScrollPosition.X)||(panel3scrolly!=this.panel3.AutoScrollPosition.Y))
{
panel3scrollx=this.panel3.AutoScrollPosition.X;
panel3scrolly=this.panel3.AutoScrollPosition.Y;
panel2.Refresh();
}
RectangleF Rect;
SolidBrush B = new SolidBrush(Color.Black);
StringFormat Ll=new StringFormat();
Ll.Alignment=System.Drawing.StringAlignment.Near;
System.Drawing.Pen insideLine=new Pen(Color.Orange,1F);
System.Drawing.Pen trueLine=new Pen(Color.Black,1F);
System.Drawing.Pen selectedLine=new Pen(Color.Green,1F);
System.Drawing.Pen moveLine=new Pen(Color.Blue,0.2F);
for (int i=0;i<ATB.Count;i++)
{
if (ATB[i].Type==BoxType.TextBox)
{
if (ATB[i].Selected)
{
draw_box(sender,e,selectedLine,ATB[i].First,ATB[i].Second);
for (int m=1;m<=8;m++)
{
draw_box(sender,e,moveLine,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m));
}
}
else
{
draw_box(sender,e,insideLine,ATB[i].First,ATB[i].Second);
}
Rect=new RectangleF((float)ATB[i].First.X,(float)ATB[i].First.Y,(float)(ATB[i].Second.X-ATB[i].First.X),(float)(ATB[i].Second.Y-ATB[i].First.Y));
e.Graphics.DrawString(ATB[i].Text,new Font("Arial",12),B,Rect,Ll);
}
else if (ATB[i].Type==BoxType.Line)
{
if (ATB[i].Selected)
{
e.Graphics.DrawLine(selectedLine,ATB[i].First,ATB[i].Second);
for (int m=1;m<=2;m++)
{
draw_box(sender,e,moveLine,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m));
}
}
else
{
e.Graphics.DrawLine(trueLine,ATB[i].First,ATB[i].Second);
}
}
else if (ATB[i].Type==BoxType.LineBox)
{
if (ATB[i].Selected)
{
draw_box(sender,e,selectedLine,ATB[i].First,ATB[i].Second);
for (int m=1;m<=8;m++)
{
draw_box(sender,e,moveLine,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m));
}
}
else
{
draw_box(sender,e,trueLine,ATB[i].First,ATB[i].Second);
}
}
}
}
public int GetNum(object sender,System.Windows.Forms.MouseEventArgs e)
{
for (int i=0;i<ATB.Count;i++)
{
if (ATB[i].Type==BoxType.Line)
{
for (int m=1;m<=2;m++)
{
if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox))
{
return i;
}
}
}
else if (ATB[i].Type==BoxType.Line||ATB[i].Type==BoxType.TextBox)
{
for (int m=1;m<=8;m++)
{
if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox))
{
return i;
}
}
}
}
return -1;
}
private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button!=System.Windows.Forms.MouseButtons.Left)
{
return;
}
if (bt!=BoxType.None)
{
leftpoint=new Point(e.X,e.Y);
newenter=true;
num=-1;
return;
}
if (num!=-1)
{
enter=true;
movenum=num;
}
else if (panel1.Cursor==System.Windows.Forms.Cursors.SizeNESW||panel1.Cursor==System.Windows.Forms.Cursors.SizeNS||panel1.Cursor==System.Windows.Forms.Cursors.SizeNWSE||panel1.Cursor==System.Windows.Forms.Cursors.SizeWE)
{
enter=true;
movenum=GetNum(sender,e);
}
}
private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button!=System.Windows.Forms.MouseButtons.Left)
{
return;
}
rightpoint=new Point(e.X,e.Y);
ATB.AddTextBox(leftpoint,rightpoint,bt);
if(bt==BoxType.TextBox)
{
write=true;
writebind=ATB.Count-1;
this.richTextBox1.Text="";
this.richTextBox1.Left=ATB[writebind].First.X;
this.richTextBox1.Top=ATB[writebind].First.Y;
this.richTextBox1.Width=ATB[writebind].Width+2;
this.richTextBox1.Height=ATB[writebind].Height+2;
this.richTextBox1.Visible=true;
this.richTextBox1.Focus();
}
if(bt!=BoxType.None)
{
newenter=false;
bt=BoxType.None;
c1Command6_Click(null,null);
this.panel1.Refresh();
}
if(enter)
{
enter=false;
panel1.Cursor=System.Windows.Forms.Cursors.Default;
movenum=-1;
}
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
ATB.RemoveTextBox(num);
panel1.Refresh();
num=-1;
this.panel1.Cursor=System.Windows.Forms.Cursors.Default;
}
private void panel1_MouseLeave(object sender, System.EventArgs e)
{
this.panel1.ContextMenu=null;
}
private bool isInclude(object sender,System.Windows.Forms.MouseEventArgs e,Point First,Point Second,BoxType type)
{
if (((type==BoxType.TextBox)||(type==BoxType.LineBox)))
{
if (Math.Min(First.X,Second.X) <= e.X && e.X<= Math.Max(First.X,Second.X) && Math.Min(First.Y,Second.Y) <= e.Y && e.Y<= Math.Max(First.Y,Second.Y))
{
return true;
}
else
{
return false;
}
}
else if (type==BoxType.Line)
{
if (new Point(e.X,e.Y)==First||new Point(e.X,e.Y)==Second)
{
return true;
}
else if ((e.X!=First.X && e.X!=Second.X && Math.Min(First.X,Second.X)<=e.X && Math.Max(First.X,Second.X)>=e.X && Math.Min(First.Y,Second.Y)<=e.Y && Math.Max(First.Y,Second.Y)>=e.Y && Math.Abs((e.Y-First.Y)/(e.X-First.X)-(e.Y-Second.Y)/(e.X-Second.X))<=0.1))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
#region 绑定菜单
for (int i=0;i<ATB.Count;i++)
{
if ((ATB[i].Type==BoxType.TextBox)||(ATB[i].Type==BoxType.LineBox))
{
if (Math.Min(ATB[i].First.X,ATB[i].Second.X) <= e.X && e.X<= Math.Max(ATB[i].First.X,ATB[i].Second.X) && Math.Min(ATB[i].First.Y,ATB[i].Second.Y) <= e.Y && e.Y<= Math.Max(ATB[i].First.Y,ATB[i].Second.Y))
{
num=i;
this.panel1.ContextMenu=this.contextMenu1;
break;
}
else
{
num=-1;
this.panel1.ContextMenu=null;
}
}
else if (ATB[i].Type==BoxType.Line)
{
if (new Point(e.X,e.Y)==ATB[i].First||new Point(e.X,e.Y)==ATB[i].Second)
{
num=i;
this.panel1.ContextMenu=this.contextMenu1;
break;
}
else if(e.X!=ATB[i].First.X && e.X!=ATB[i].Second.X && Math.Min(ATB[i].First.X,ATB[i].Second.X)<=e.X && Math.Max(ATB[i].First.X,ATB[i].Second.X)>=e.X && Math.Min(ATB[i].First.Y,ATB[i].Second.Y)<=e.Y && Math.Max(ATB[i].First.Y,ATB[i].Second.Y)>=e.Y && Math.Abs((e.Y-ATB[i].First.Y)/(e.X-ATB[i].First.X)-(e.Y-ATB[i].Second.Y)/(e.X-ATB[i].Second.X))<=0.2)
{
num=i;
this.panel1.ContextMenu=this.contextMenu1;
break;
}
else
{
num=-1;
this.panel1.ContextMenu=null;
}
}
}
#endregion
#region 改变鼠标状态
if (enter)
goto MouseDrag;
if (num>=0&&ATB[num].Selected)
panel1.Cursor=System.Windows.Forms.Cursors.SizeAll;
else
panel1.Cursor=System.Windows.Forms.Cursors.Default;
for (int i=0;i<ATB.Count;i++)
{
if (ATB[i].Selected&&ATB[i].Type==BoxType.Line)
{
for (int m=1;m<=2;m++)
{
if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox))
{
panel1.Cursor=System.Windows.Forms.Cursors.SizeWE;
if (m==1)
dg=Drag.First;
else
dg=Drag.Second;
break;
}
}
}
else if (ATB[i].Selected&&(ATB[i].Type==BoxType.LineBox || ATB[i].Type==BoxType.TextBox))
{
for (int m=1;m<=8;m++)
{
if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox)==true && (m==1 || m==5))
{
panel1.Cursor=System.Windows.Forms.Cursors.SizeNWSE;
if (m==1)
dg=Drag.First;
else
dg=Drag.Second;
break;
}
else if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox)==true && (m==2 || m==6))
{
panel1.Cursor=System.Windows.Forms.Cursors.SizeNS;
if (m==2)
dg=Drag.First;
else
dg=Drag.Second;
break;
}
else if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox)==true && (m==3 || m==7))
{
panel1.Cursor=System.Windows.Forms.Cursors.SizeNESW;
if (m==3)
dg=Drag.First;
else
dg=Drag.Second;
break;
}
else if (isInclude(sender,e,ATB[i].MovePoint1(m),ATB[i].MovePoint2(m),BoxType.LineBox)==true && (m==4 || m==8))
{
panel1.Cursor=System.Windows.Forms.Cursors.SizeWE;
if (m==4)
dg=Drag.First;
else
dg=Drag.Second;
break;
}
}
}
}
#endregion
#region 对象移动
MouseDrag:
if (enter&&movenum!=-1&&ATB[movenum].Selected && (ATB[movenum].Type==BoxType.LineBox || ATB[movenum].Type==BoxType.TextBox))
{
if (panel1.Cursor==System.Windows.Forms.Cursors.SizeAll)
{
int x=ATB[movenum].Second.X-ATB[movenum].First.X;
int y=ATB[movenum].Second.Y-ATB[movenum].First.Y;
ATB[movenum].FirstSet(e.X-x/2,e.Y-y/2);
ATB[movenum].SecondSet(ATB[movenum].First.X+x,ATB[movenum].First.Y+y);
panel1.Refresh();
}
else if (panel1.Cursor==System.Windows.Forms.Cursors.SizeNWSE)
{
if (dg==Drag.First)
{
ATB[movenum].FirstSet(e.X,e.Y);
panel1.Refresh();
}
else
{
ATB[movenum].SecondSet(e.X,e.Y);
panel1.Refresh();
}
}
else if (panel1.Cursor==System.Windows.Forms.Cursors.SizeNS)
{
if (dg==Drag.First)
{
ATB[movenum].FirstSet(ATB[movenum].First.X,e.Y);
panel1.Refresh();
}
else
{
ATB[movenum].SecondSet(ATB[movenum].Second.X,e.Y);
panel1.Refresh();
}
}
else if (panel1.Cursor==System.Windows.Forms.Cursors.SizeNESW)
{
if (dg==Drag.First)
{
ATB[movenum].FirstSet(ATB[movenum].First.X,e.Y);
ATB[movenum].SecondSet(e.X,ATB[movenum].Second.Y);
panel1.Refresh();
}
else
{
ATB[movenum].FirstSet(e.X,ATB[movenum].First.Y);
ATB[movenum].SecondSet(ATB[movenum].Second.X,e.Y);
panel1.Refresh();
}
}
else if (panel1.Cursor==System.Windows.Forms.Cursors.SizeWE)
{
if (dg==Drag.First)
{
ATB[movenum].SecondSet(e.X,ATB[movenum].Second.Y);
panel1.Refresh();
}
else
{
ATB[movenum].FirstSet(e.X,ATB[movenum].First.Y);
panel1.Refresh();
}
}
}
else if (enter&&ATB[movenum].Selected && ATB[movenum].Type==BoxType.Line)
{
if (panel1.Cursor==System.Windows.Forms.Cursors.SizeWE)
{
if (dg==Drag.First)
{
ATB[movenum].FirstSet(e.X,e.Y);
panel1.Refresh();
}
else
{
ATB[movenum].SecondSet(e.X,e.Y);
panel1.Refresh();
}
}
else if (panel1.Cursor==System.Windows.Forms.Cursors.SizeAll)
{
int x=ATB[movenum].Second.X-ATB[movenum].First.X;
int y=ATB[movenum].Second.Y-ATB[movenum].First.Y;
ATB[movenum].FirstSet(e.X-x/2,e.Y-y/2);
ATB[movenum].SecondSet(ATB[movenum].First.X+x,ATB[movenum].First.Y+y);
panel1.Refresh();
}
}
#endregion
}
catch(Exception eee)
{
return;
}
}
private void c1Command1_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
bt=BoxType.TextBox;
this.c1Command1.Checked=true;
this.c1Command2.Checked=false;
this.c1Command3.Checked=false;
this.c1Command6.Checked=false;
}
private void c1Command2_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
bt=BoxType.Line;
this.c1Command2.Checked=true;
this.c1Command3.Checked=false;
this.c1Command6.Checked=false;
this.c1Command1.Checked=false;
}
private void c1Command3_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
bt=BoxType.LineBox;
this.c1Command2.Checked=false;
this.c1Command3.Checked=true;
this.c1Command6.Checked=false;
this.c1Command1.Checked=false;
}
private void c1Command4_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
}
private void c1Command5_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
}
private void c1Command6_Click(object sender, C1.Win.C1Command.ClickEventArgs e)
{
bt=BoxType.None;
this.c1Command1.Checked=false;
this.c1Command2.Checked=false;
this.c1Command3.Checked=false;
this.c1Command6.Checked=true;
}
private void menuItem18_Click(object sender, System.EventArgs e)
{
VerFrm frm=new VerFrm();
frm.ShowDialog();
}
private void writeOver()
{
this.richTextBox1.Left=0;
this.richTextBox1.Top=0;
this.richTextBox1.Width=1;
this.richTextBox1.Height=1;
this.richTextBox1.Visible=false;
}
private void panel1_Click(object sender, System.EventArgs e)
{
if (writebind==-1)
{
writeOver();
for (int i=0;i<ATB.Count;i++)
{
ATB[i].Selected=false;
if (i==num)
{
ATB[num].Selected=true;
}
}
panel1.Refresh();
}
else if (write&&writebind>=0)
{
ATB[writebind].Text=this.richTextBox1.Text;
writeOver();
writebind=-1;
panel1.Refresh();
}
}
private void panel1_DoubleClick(object sender, System.EventArgs e)
{
if (num>=0 && ATB[num].Type==BoxType.TextBox)
{
writebind=num;
write=true;
this.richTextBox1.Text=ATB[writebind].Text;
this.richTextBox1.Left=ATB[writebind].First.X;
this.richTextBox1.Top=ATB[writebind].First.Y;
this.richTextBox1.Width=ATB[writebind].Width+2;
this.richTextBox1.Height=ATB[writebind].Height+2;
this.richTextBox1.Visible=true;
this.richTextBox1.Focus();
this.richTextBox1.Select(this.richTextBox1.Text.Length,0);
}
}
}
public class pTextBox
{
private Point pointfirst;
private Point pointsecond;
private Point[] movepoint1 = new Point[9];
private Point[] movepoint2 = new Point[9];
private int width=0;
private int height=0;
private string textdetail="";
private BoxType type;
private bool;
public pTextBox(Point first,Point second,BoxType ptype)
{
if (ptype==BoxType.Line)
{
if (first.X==second.X)
{
if (first.Y>second.Y)
{
pointfirst=second;
pointsecond=first;
}
else
{
pointsecond=first;
pointfirst=second;
}
}
else
{
if (first.X>second.X)
{
pointfirst=second;
pointsecond=first;
}
else
{
pointsecond=first;
pointfirst=second;
}
}
width=second.X-first.X;
height=0;
}
else
{
pointfirst=new Point(Math.Min(first.X,second.X),Math.Min(first.Y,second.Y));
pointsecond=new Point(Math.Max(first.X,second.X),Math.Max(first.Y,second.Y));
width=second.X-first.X;
height=second.Y-first.Y;
}
type=ptype;
MoveSet(pointfirst,pointsecond,type);
}
private void MoveSet(Point first,Point second,BoxType ptype)
{
int tempwidth=second.X-first.X;
int tempheight=second.Y-first.Y;
int line=3;
if (ptype==BoxType.Line)
{
movepoint1[1]=new Point(first.X-line,first.Y-line);
movepoint2[1]=new Point(first.X+line,first.Y+line);
movepoint1[2]=new Point(second.X-line,second.Y-line);
movepoint2[2]=new Point(second.X+line,second.Y+line);
}
else
{
//左上角
movepoint1[1]=new Point(first.X-line,first.Y-line);
movepoint2[1]=new Point(first.X+line,first.Y+line);
//上方
movepoint1[2]=new Point(second.X-tempwidth/2-line,first.Y-line);
movepoint2[2]=new Point(second.X-tempwidth/2+line,first.Y+line);
//右上角
movepoint1[3]=new Point(second.X-line,first.Y-line);
movepoint2[3]=new Point(second.X+line,first.Y+line);
//右方
movepoint1[4]=new Point(second.X-line,second.Y-tempheight/2-line);
movepoint2[4]=new Point(second.X+line,second.Y-tempheight/2+line);
//右下角
movepoint1[5]=new Point(second.X-line,second.Y-line);
movepoint2[5]=new Point(second.X+line,second.Y+line);
//下方
movepoint1[6]=new Point(second.X-tempwidth/2-line,second.Y-line);
movepoint2[6]=new Point(second.X-tempwidth/2+line,second.Y+line);
//左下角
movepoint1[7]=new Point(first.X-line,second.Y-line);
movepoint2[7]=new Point(first.X+line,second.Y+line);
//左方
movepoint1[8]=new Point(first.X-line,second.Y-tempheight/2-line);
movepoint2[8]=new Point(first.X+line,second.Y-tempheight/2+line);
}
}
public Point MovePoint1(int pnum)
{
return movepoint1[pnum];
}
public Point MovePoint2(int pnum)
{
return movepoint2[pnum];
}
public void FirstSet(int x,int y)
{
pointfirst=new Point(x,y);
width=Second.X-First.X;
height=Second.Y-First.Y;
MoveSet(pointfirst,pointsecond,type);
}
public void SecondSet(int x,int y)
{
pointsecond=new Point(x,y);
width=Second.X-First.X;
height=Second.Y-First.Y;
MoveSet(pointfirst,pointsecond,type);
}
public bool Selected
{
get
{
return selected;
}
set
{
selected=value;
}
}
public BoxType Type
{
get
{
return type;
}
}
public int Width
{
get
{
return width;
}
// set
// {
// width=value;
// SecondSet(First.X+value,Second.Y);
// }
}
public int Height
{
get
{
return height;
}
// set
// {
// if (type!=BoxType.Line)
// {
// height=value;
// SecondSet(Second.X,First.Y+value);
// }
// }
}
public Point First
{
get
{
return pointfirst;
}
}
public Point Second
{
get
{
return pointsecond;
}
}
public string Text
{
get
{
return textdetail;
}
set
{
if (type==BoxType.TextBox)
textdetail=value;
}
}
}
public enum BoxType
{
TextBox,
Line,
LineBox,
None
}
public enum Drag
{
First,
Second
}
public class ATextBox: System.Collections.CollectionBase
{
public ATextBox()
{}
public void AddTextBox(Point FirstPoint,Point SecondPoint,BoxType type)
{
List.Add(new pTextBox(FirstPoint,SecondPoint,type));
}
public void RemoveTextBox(int index)
{
if (index > Count - 1 || index < 0)
{
MessageBox.Show("Index not valid!");
}
else
{
List.RemoveAt(index);
}
}
public ATextBox Item
{
get
{
return this;
}
}
[System.Runtime.CompilerServices.IndexerName("item")]
public pTextBox this[int index]
{
get
{
return (pTextBox) List[index];
}
}
}
}