zoukankan      html  css  js  c++  java
  • 在主窗体的Mouse_Down中添加如下事件,实现窗体随意拖动

    ---

    ---

    --

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;
    
    namespace CSocket
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport("user32.dll")]
            public static extern bool ReleaseCapture();
            [DllImport("user32.dll")]
            public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
            public const int WM_SYSCOMMAND = 0x0112;
            public const int SC_MOVE = 0xF010;
            public const int HTCAPTION = 0x0002;
            private void Form1_Load(object sender, EventArgs e)
            {
                this.button1.FlatStyle = FlatStyle.Popup;
                this.MouseDown+=Form1_MouseDown;
                panel1.MouseDown += Form1_MouseDown;
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;//窗体无边框
            }
            /// <summary>
            /// 为了是主界面能够移动
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>        
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
            } 
        }
    }

    -----

    首页添加选卡的方法:

            /// <summary>
            /// 添加选卡的方法
            /// </summary>
            /// <param name="tabName">选卡或者窗体Name属性</param>
            /// <param name="tabText">选卡或者窗体标题</param>
            /// <param name="flag"></param>
            /// <param name="ctl">子窗体对象</param>
            public void tabControlAdd(string tabName, string tabText, object flag, Form ctl)
            {
                bool bl = true;
                foreach (XtraTabPage tbl in xtraTabControl1.TabPages)
                {
                    if (tbl.Name == "tab_" + tabName + flag.ToString())
                    {
                        xtraTabControl1.SelectedTabPage = tbl;
                        bl = false;
                        break;
                    }
                }
                if (bl == true)
                {
                    ctl.Name = tabName + flag.ToString();
                    ctl.Text = tabText;
                    ctl.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //设置窗体为非边框样式           
                    ctl.Dock = System.Windows.Forms.DockStyle.Fill; //设置样式是否填充整个panel               
                    ctl.Tag = flag; 
                    //-------------------------------------
                    XtraTabPage tb = new XtraTabPage();
                    tb.Name = "tab_" + tabName + flag.ToString();
                    tb.Text = tabText;
                    tb.Dock = System.Windows.Forms.DockStyle.Fill; //设置样式是否填充整个panel                    
                    //--------------------------------------------------------               
                    xtraTabControl1.TabPages.Add(tb);
                    xtraTabControl1.SelectedTabPage = tb;//显示该页
                    //-------------------------------------------                   
                    ctl.TopLevel = false;      //设置为非顶级窗体  
                    tb.Controls.Add(ctl); //页面添加 容器
                    ctl.Show();                
                }
            }

    ProgressBar美化

     class MyProgressBar:ProgressBar //新建一个MyProgressBar类,它继承了ProgressBar的所有属性与方法
        {
            public MyProgressBar()
            {
                base.SetStyle(ControlStyles.UserPaint, true);//使控件可由用户自由重绘
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                SolidBrush brush = null;
                Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
                e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);//此处完成背景重绘,并且按照属性中的BackColor设置背景色
                bounds.Height -= 4;
                bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;//是的进度条跟着ProgressBar.Value值变化
                brush = new SolidBrush(this.ForeColor);
                e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);//此处完成前景重绘,依旧按照Progressbar的属性设置前景色
            }
        }

     完成以上步骤之后,我们如何在界面中插入自己的进度条呢?``我们可以先插入一个winform自带的ProgressBar,调整好位置,ForeColor,BackColor属性,然后进入窗体的Designer程序中做如下修改:

    //private System.Windows.Forms.ProgressBar progressBar1;//注释此句
    private MyProgressBar progressBar1; //新添此句,添加新的控件MyProgressBar
    private void InitializeComponent()
    {
        //this.progressBar1 = new System.Windows.Forms.ProgressBar();//注释此句
        this.progressBar1 = new 界面美化.MyProgressBar();//新添此句,此处对MyPorgressBar实例化
        this.SuspendLayout();
        this.progressBar1.Location = new System.Drawing.Point(137, 68);
        this.progressBar1.Name = "progressBar1";
        this.progressBar1.Size = new System.Drawing.Size(100, 23);
        this.progressBar1.TabIndex = 0;
    }
  • 相关阅读:
    基因数据分析主流软件与基因预测方法步骤-搬运工
    调用约定__cdecl __fastcall与__stdcall
    const用法体会
    NS3系列——eclipse + NS3环境搭建
    小div在大div里面水平垂直都居中的实现方法
    template.js插件和ajax一起使用的例子
    js获取时间的函数集
    ajax获取json数据及实现跨域请求
    JavaScript里的Date 对象属性及对象方法--实现简单的日历
    css单行文本及多行文本溢出显示省略号
  • 原文地址:https://www.cnblogs.com/lanyubaicl/p/11064787.html
Copyright © 2011-2022 走看看