zoukankan      html  css  js  c++  java
  • 窗体界面设计01

     01.飘动动画窗体

     SystemInformation.PrimaryMonitorMaximizedWindowSize.Width获取屏幕宽度

     SystemInformation.PrimaryMonitorMaximizedWindowSize.Height获取屏幕高度

     DesktopLocation获取Windows桌面上窗体的位置

     02.透明动画窗体

     窗体Opacity属性

     03.利用API函数实现动画窗体

     API函数AnimateWindow()实现窗体左右、上下、扩展、淡入滑动或滚动动画效果

    代码
            public const Int32 AW_HOR_POSITIVE = 0x00000001;        //自左向右显示窗体
            public const Int32 AW_HOR_NEGATIVE = 0x00000002;        //自右向左显示窗体
            public const Int32 AW_VER_POSITIVE = 0x00000004;        //自上向下显示窗体
            public const Int32 AW_VER_NEGATIVE = 0x00000008;        //自下向上显示窗体
            public const Int32 AW_CENTER = 0x00000010;              //窗体向外扩展
            public const Int32 AW_HIDE = 0x00010000;                //隐藏窗体
            public const Int32 AW_ACTIVATE = 0x00020000;            //激活窗体
            public const Int32 AW_SLIDE = 0x00040000;               //使用滚动动画类型
            public const Int32 AW_BLEND = 0x00080000;               //使用淡入效果

            eg:AnimateWindow(this.Handle,2000,AW_HOR_POSITIVE)

     

     04.闪烁动画窗体

     API函数FlashWindow的应用

     窗体的TransparencyKey、Dock属性

     05.滚动字幕动画窗体

     WindowState属性

     TransparencyKey属性

     06.超女卡通窗体

     封装GDI+位图的Bitmap类的应用

     Bitmap类的Bitmap()、MakeTransparent()方法应用

     窗体StartPosition、FormBorderStyle属性应用

     重写窗体OnPaint事件的应用

    代码
            public Bitmap mybit;

            
    private void Form3_Load(object sender, EventArgs e)
            {
                mybit 
    = new Bitmap(Application.StartupPath + "/jay.bmp");                        //绘制位图
                mybit.MakeTransparent(Color.Yellow);
                
    this.StartPosition = FormStartPosition.CenterScreen;        //设置窗体的位置
                this.WindowState = FormWindowState.Normal;                  //设置窗体的状态
            }
            
    protected override void OnPaint(PaintEventArgs e)
            {
                e.Graphics.DrawImage((Image)mybit, 
    new Point(10,10));        //将图像画出
            }

     07.总在最前的登录窗体

     窗体的TopMost属性

     消息对话框MessageBox的Show方法

    代码
    private void Form4_Load(object sender, EventArgs e)
            {
                
    this.TopMost = true;                                    //窗体总在最前
                this.StartPosition = FormStartPosition.CenterScreen  ;    //设置窗体的位置
            }

            
    private void button1_Click(object sender, EventArgs e)
            {
                
    if (textBox1.Text == "" || textBox2.Text == "")
                {
                    MessageBox.Show(
    this"输入的登录信息不完整,请重新输入!""提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                
    else
                {
                    
    if (textBox1.Text == "张亮")
                    {
                        
    if (textBox2.Text == "8888888")
                        {
                            MessageBox.Show(
    this"恭喜您,用户名和密码都正确,可以成功登录!""提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        
    else
                        {
                            MessageBox.Show(
    this"密码不正确,请重新输入!""提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    
    else
                    {
                        MessageBox.Show(
    this"用户名不正确,请重新输入!""提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }

            
    private void button2_Click(object sender, EventArgs e)
            {
                
    this.textBox1.Text = "";    //清空文本框
                this.textBox2.Text = "";
            }

            
    private void button3_Click(object sender, EventArgs e)
            {
                
    this.Close();
                Application.Exit();             
    //退出程序
            }
    代码
    public static System.Windows.MessageBoxResult Show(
    System.Windows.Window owner,
    string messageBoxTex,
    string caption,
    System.Windows.MessageBoxButton button,
    System.Windows.MessageBoxImage icon,
    System.Windows.MessageBoxResult DefaultResult,
    System.Windows.MessageBoxOptions options);

    owner:一个System.Windows.Window,表示消息框所有者窗体
    messageBoxText:一个System.String,用于指定要显示的文本
    caption:一个System.String,用于指定要显示的标题栏标题
    button:一个System.Windows.MessageBoxButton值,用于指定要显示哪个按钮或哪些按钮
    icon:一个System.Windows.MessageBoxImage值,用于指定要显示的图标。
    defaultResult:一个System.Windows.MessageBoxResult值,用于指定消息框的默认结果。
    options:一个System.Windows.MessageBoxOptions值对象,用于指定选项

     08.在屏幕中央的圆形窗体

     System.Drawing.Drawing2D命名空间

     GraphicsPath对象的AddEllipse方法

    代码
    private void Form5_Load(object sender, EventArgs e)
            {
                
    this.Left = (SystemInformation.PrimaryMonitorMaximizedWindowSize.Width - this.Width) / 2;
                
    this.Top = (SystemInformation.PrimaryMonitorMaximizedWindowSize.Height - this.Height) / 2;
            }

            
    private void Form5_Paint(object sender, PaintEventArgs e)
            {
                GraphicsPath Myformpath 
    = new GraphicsPath();       //创建一个路径对象
                Myformpath.AddEllipse(5050this.Width - 100this.Height - 100);
                
    this.Region = new Region(Myformpath);

            }

            
    private void Form5_DoubleClick(object sender, EventArgs e)
            {
                Application.Exit();
            }

     09.半透明的T形窗体

     Point点数据的应用

     GraphicsPath对象的AddPolygon方法(可绘制多边形)

    代码
            private void Form1_Load(object sender, EventArgs e)
            {
                
    this.Left = (SystemInformation.PrimaryMonitorMaximizedWindowSize.Width - this.Width) / 2;
                
    this.Top = (SystemInformation.PrimaryMonitorMaximizedWindowSize.Height - this.Height) / 2;
                
    this.Opacity = 0.5;     //设置窗体的透明度
            }

            
    private void button1_Click(object sender, EventArgs e)
            {
                GraphicsPath Mypform1 
    = new GraphicsPath();         //案例化GraphicsPath
                Point[] Myarray ={                                   //定义点数组
                                    new Point(0,0),
                                    
    new Point(this.Width,0),
                                    
    new Point(this.Width,this.Height/2),
                                    
    new Point(this.Width-(this.Width/3),this.Height/2),
                                    
    new Point(this.Width-(this.Width/3),this.Height),
                                    
    new Point(this.Width/3,this.Height),
                                    
    new Point(this.Width/3,this.Height/2),
                                    
    new Point(0,this.Height/2),
                                };
                Mypform1.AddPolygon(Myarray);                       
    //利用数组绘制T形窗体
                this.Region = new Region(Mypform1);
             }
                

     10.多文档MDI窗体

     窗体的IsMdiContainer属性

     下拉菜单MenuStrip控件的应用

     状态栏StatusStrip控件的应用

     打开对话框OpenFileDialog和保存对话框SaveFileDialog的应用

     页面设置对话框PageSetupDialog和页面打印控件PrintDocument的应用

     打印预览对话框PrintPreviewDialog的应用

     字体对话框FontDialog的应用

     日期时间对象DateTime的应用

     RichTextBox控件的应用

     剪贴板对象Clipboard的应用

     字符串流对象StringReader的应用

    代码
            Form1_1 myf = new Form1_1();                //新建Form2对象实例
            public StringReader MySReader;              //字符串流对象,一行一行读取文本
            public int x = 1;                           //记录新建子窗体个数


            
    private void Form2_Load(object sender, EventArgs e)
            {
                toolStripStatusLabel1.Text 
    = " 当前日期:" + DateTime.Now.ToString();       //显示当前日期与时间
            }

            
    private void 打印预览ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                printPreviewDialog1.Document 
    = printDocument1;
                MySReader 
    = new StringReader(myf.richTextBox1.Text);                //打印预览内容
                try
                {
                    printPreviewDialog1.ShowDialog();                               
    //打印预览对话框
                }
                
    catch
                {
                    printDocument1.PrintController.OnEndPrint(printDocument1, 
    new System.Drawing.Printing.PrintEventArgs());
                }
            }

            
    private void toolStripStatusLabel1_Click(object sender, EventArgs e)
            {

            }

            
    private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Form1_1 myf 
    = new Form1_1();
                myf.MdiParent 
    = this;                       //设置为子窗体
                myf.Text = "新建文件" + x.ToString();       //设置子窗体的标题
                toolStripStatusLabel1.Text = "状态: 新建文档";//状态栏提示信息
                x=x+1;
                myf.Show();                                 
    //显示子窗体
            }

            
    private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter 
    = "*.txt|*.txt";                         //设置打开对话框的文件类型
                openFileDialog1.Title = "打开";                                 //设置打开对话框的标题
                if(openFileDialog1.ShowDialog()==DialogResult.OK)
                {
                    
    string strname=openFileDialog1.FileName;                    //提取打开文件的文件名
                    myf.Text=openFileDialog1.FileName;                          //设置子窗体文件名
                    myf.richTextBox1.Clear();                                   //打开文件
                    myf.richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
                    myf.MdiParent
    =this;                                         //设置窗体为子窗体
                    myf.Show();                                                //显示子窗体
                    toolStripStatusLabel1.Text=toolStripStatusLabel1.Text+"打开文件";
                }

            }

            
    private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                saveFileDialog1.Filter 
    = "文本文件(*.txt)|*.txt";           //设置保存对话框类型
                saveFileDialog1.FilterIndex = 2;
                
    if (saveFileDialog1.ShowDialog() == DialogResult.OK)           //保存文件
                {
                    myf.richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                }
            }

            
    private void 页面设置ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                pageSetupDialog1.Document 
    = this.printDocument1;        //页面设置的内容
                pageSetupDialog1.ShowDialog();                          //页面设置对话框

            }

            
    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                Graphics frmGraphics 
    = e.Graphics;
                Font frmFont 
    = myf.richTextBox1.Font;           //设置字体类型
                float intpage = e.MarginBounds.Height;          //每一页的行数
                frmFont.GetHeight(frmGraphics);
                
    int intPratn = 0;                               //打印的行数计算
                float fYposition = 0;                           //打印时的纵坐标
                float fLeft = e.MarginBounds.Left;
                
    float fTop = e.MarginBounds.Top;
                
    string strfrmling = "";
                
    while ((intPratn < intpage) && (strfrmling = MySReader.ReadLine()) != null)
                {
                    fYposition 
    = fTop + intPratn * frmFont.GetHeight(frmGraphics);
                    frmGraphics.DrawString(strfrmling, frmFont, 
    new SolidBrush(Color.Black), fLeft, fYposition, new StringFormat());
                    intPratn
    ++;
                }
                
    if (strfrmling != null)
                {
                    e.HasMorePages 
    = true;                        //没有打印完发出下一面打印事件
                }
                
    else
                {
                    e.HasMorePages 
    = false;
                }

            }

            
    private void 退出QToolStripMenuItem_Click(object sender, EventArgs e)
            {
                
    this.Close();
                Application.Exit();
            }

            
    private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
            {
                
    int CutInt = myf.richTextBox1.SelectionRightIndent;
                Clipboard.SetDataObject(myf.richTextBox1.SelectedText);
                myf.richTextBox1.Text 
    = myf.richTextBox1.Text.Substring(0, CutInt) + myf.richTextBox1.Text.Substring(CutInt, myf.richTextBox1.SelectedText.Length);
                myf.richTextBox1.SelectionStart 
    = CutInt;
            }

            
    private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Clipboard.SetDataObject(myf.richTextBox1.SelectedText);     
    //复制选择文本
            }

            
    private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
            {
                IDataObject idat 
    = Clipboard.GetDataObject();
                
    if(idat.GetDataPresent(DataFormats.Text))
                {
                    
    string PasteStr=(string)idat.GetData(DataFormats.Text);
                    
    int pasteid=myf.richTextBox1.SelectionStart;
                    myf.richTextBox1.Text
    =myf.richTextBox1.Text.Substring(0,pasteid)+PasteStr+myf.richTextBox1.Text.Substring(pasteid);
                    myf.richTextBox1.SelectionStart
    =pasteid+PasteStr.Length;
                }

            }

            
    private void 全选AToolStripMenuItem_Click(object sender, EventArgs e)
            {
                myf.richTextBox1.SelectAll();               
    //全选文本
            }

            
    private void 字体FToolStripMenuItem_Click(object sender, EventArgs e)
            {
                fontDialog1.ShowDialog();                       
    //字体对话框
                fontDialog1.AllowVerticalFonts = true;
                fontDialog1.FixedPitchOnly 
    = true;
                fontDialog1.ShowApply 
    = true;
                fontDialog1.ShowEffects 
    = true;
                
    if (myf.richTextBox1.SelectedText == "")
                {
                    myf.richTextBox1.Font 
    = fontDialog1.Font;           //设置所有文本字体属性
                }
                
    else
                {
                    myf.richTextBox1.SelectionFont 
    = fontDialog1.Font;  //设置选择文本字体属性
                }
            }

            
    private void 层叠AToolStripMenuItem_Click(object sender, EventArgs e)
            {
                
    this.LayoutMdi(MdiLayout.Cascade);
            }

            
    private void 横向平铺FToolStripMenuItem_Click(object sender, EventArgs e)
            {
                
    this.LayoutMdi(MdiLayout.TileHorizontal);
            }

            
    private void 竖向平铺HToolStripMenuItem_Click(object sender, EventArgs e)
            {
                
    this.LayoutMdi(MdiLayout.TileVertical);
            }

            
    private void 图标排列TToolStripMenuItem_Click(object sender, EventArgs e)
            {
                
    this.LayoutMdi(MdiLayout.ArrangeIcons);
            }

  • 相关阅读:
    perl中的反勾号(``),system和exec
    经典的JavaScript效果
    关于Asp.net ajax下的异常处理
    史上最酷的IIS一键安装,你想要吗? 博客园全球首发
    下载最新的AjaxControlToolkit控件包
    Asp.net开发中不可靠的编码习惯
    用Ajax保持会话
    对ViewState的一点思考
    对微软Asp.net Ajax 1.0的AutoComplete控件的几处修正和增强
    还为安装IIS发愁吗?全系列IIS自动安装程序倾囊奉送!--技术原理介绍及成品下载
  • 原文地址:https://www.cnblogs.com/yongfeng/p/1680398.html
Copyright © 2011-2022 走看看