HA

C#獲取窗體寬度、獲取兩個日期的時間差

C#獲取窗體寬度、獲取兩個日期的時間差

在窗體改變時改變控件的寬度

        private void FormTemp_Resize(object sender, EventArgs e) {
            Program.log("Width of form is " + this.Width.ToString());
            //this.Bounds.Width
            //下面這個不太清楚得到的是什麼寬度
            //System.Windows.Forms.Screen.FromControl(this).Bounds.Width
        }

獲取兩個日期間的時間差

new DateTime().Subtract(new DateTime().AddDays(1)).TotalMinutes;//-1440

获取字符串的显示宽度

            Program.log("this.Font is " + this.Font.ToString()
                + "\r\n 勉強's width is "
                + System.Windows.Forms.TextRenderer.MeasureText("勉強", this.Font).Width.ToString());
            this.Font = new System.Drawing.Font(
                "Noto Sans CJK JP Bold", 9F
                , System.Drawing.FontStyle.Bold
                , System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            Program.log("this.Font is " + this.Font.ToString()
                + "\r\n 勉強's width is "
                + System.Windows.Forms.TextRenderer.MeasureText("勉強", this.Font).Width.ToString());
/*
this.Font is [Font: Name=宋体, Size=9, Units=3, GdiCharSet=134, GdiVerticalFont=False]
 勉強's width is 29
this.Font is [Font: Name=Noto Sans CJK JP Bold, Size=9, Units=3, GdiCharSet=134, GdiVerticalFont=False]
 勉強's width is 32
*/

ps:vs快捷键 格式化选定内容Ctrl+K,Ctrl+F,格式化文档Ctrl+K,Ctrl+D

自定义快捷键:工具->选项->环境->键盘

reference