MDICSharp案例总结

4 篇文章 0 订阅
 

MDICSharp案例总结:

1、 MDI窗体IsMdiContainer属性设置为true

2、 MainMenu、toolBarButton、ImageList工具控件等设计

顶级菜单MdiList属性设置为True,则显示所有子窗口及选中当前子窗口

ImageList需准备好图片

toolBar需先选择要用到的ImageList,然后设置Buttons属性,打开Buttons属性对话框,给每个toolBarButton选择ImageIndex

toolBar_Click单击函数:

private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
    {
        switch (toolBar1.Buttons.IndexOf(e.Button))
        {
            case 0 :
                mnuFileNew_Click(null, null);
                break;
            case 1 :
                mnuFileExit_Click(null,null);
                break;
        }
}


3、 文件:打开文件、保存文件,在这个地方是对应的两个操作

public void miOpen_Click(object sender, System.EventArgs e)
{
        OpenFileDialog openFileDialog = new OpenFileDialog();
 
        if (openFileDialog.ShowDialog() == DialogResult.OK)
        {
            filename = openFileDialog.FileName;
            currentFilename = filename;
            Stream openStream = openFileDialog.OpenFile();
            if (openStream != null)
            {
BinaryFormatter formatter = new BinaryFormatter();
            shapesArr = (ArrayList) formatter.Deserialize(openStream);
            openStream.Close();
            // allow shapes to be displayed
            bDrawAllowed = true;
            // reset shape type
            currShape = ShapeType.cursor;
            this.Refresh();
            } // if().
        } // if().
 } // miOpen_Click().

public void miSave_Click(object sender, System.EventArgs e)
{
	SaveFileDialog saveFileDialog = new SaveFileDialog();
	String filename;
     
	if (saveFileDialog.ShowDialog() == DialogResult.OK)
	{
      		filename = saveFileDialog.FileName;
	}
	if (filename == null) return;
        else
        {
            Stream saveStream ;
            saveStream = File.OpenWrite(filename);
            if (saveStream != null)
            {
                BinaryFormatter formatter = new BinaryFormatter();
             
                // serialize shapes
                formatter.Serialize(saveStream, shapesArr);
                saveStream.Close();
            } // if().
	} // else.
}


4对话框:MessageBox对话框、Color对话框

a.

MessageBox.Show(this, "by Shruti (C) 2003","About ...", MessageBoxButtons.OK, MessageBoxIcon.Information);

b.

MessageBox.Show(this,"No changes!", "Error: Empty Canvas",

MessageBoxButtons.OK, MessageBoxIcon.Error);

c.

MessageBox.Show(string question,"Save File?", MessageBoxButtons.YesNo) == DialogResult.Yes

 

ColorDialog:

Color color;

    ColorDialog dlg = new ColorDialog();

    if (dlg.ShowDialog() == DialogResult.OK)

    {

        color = dlg.Color;

        m_pen = new Pen(color);

        m_brush = new SolidBrush(color);

}

 

5、  DrawLine、DrawTriangle、DrawRectangle、DrawEllipse等画图形函数

 

***:
    Rectangle drawArea;
    Size rectSize = new Size((EndPoint.X - StartPoint.X), (EndPoint.Y - StartPoint.Y));
    drawArea = new Rectangle(StartPoint, rectSize);
 
public override void DrawShape(Graphics dc, Pen drawPen, Brush brush)
{
  //***
  //Brush b =  new SolidBrush(Color.Red);
  dc.DrawLine(drawPen, StartPoint, EndPoint);
}
 
public override void DrawShape(Graphics dc, Pen drawPen, Brush brush)
{
  ***
  Brush b =  new SolidBrush(Color.Red);
  dc.DrawRectangle(drawPen, drawArea);
  dc.FillRectangle(brush, drawArea);
}
 
public override void DrawShape(Graphics dc, Pen drawPen, Brush brush)
{
  ***
  dc.DrawEllipse(drawPen, drawArea);
  dc.FillEllipse(brush, drawArea);
}
    
public override void DrawShape(Graphics dc, Pen drawPen, Brush brush)
{
  ***
  Brush b =  new SolidBrush(Color.Red);
  Point[] pt;
  pt = new Point[4];
         
  pt[0].X = pt[3].X = EndPoint.X;
  pt[0].Y = pt[3].Y = EndPoint.Y;
         
  pt[1].X = StartPoint.X + rectSize.Width/2;
  pt[1].Y = StartPoint.Y;
     
  pt[2].X = StartPoint.X;
  pt[2].Y = EndPoint.Y;
 
  dc.DrawPolygon(drawPen, pt);
  dc.FillPolygon(brush, pt);
}


 

6、 C#类库

using system;

using system.Drawing; —— 画图形

using system.IO; —— 流、文件

using system.Collections; —— 集合、Arraylist

using system.Windows.Forms;

using system.Runtime.Serialization.Formatters.Binary;  —— BinaryFormatter

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值