1.重繪文字
#多行文字
a.先定義一個矩形
Rectangle p1 = new Rectangle(10, 0, 200, this.Height); Rectangle p2 = new Rectangle(210, 0, 200, this.Height); Rectangle p3 = new Rectangle(410, 0, 100, this.Height);
b.在矩形中寫入文字
TextRenderer.DrawText(g,name,Font,p1,ForeColor,TextFormatFlags.HorizontalCenter|TextFormatFlags.VerticalCenter); TextRenderer.DrawText(g, time, Font, p2, ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); TextRenderer.DrawText(g, content, Font, p3, ForeColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
#單行文字
a.先定義一個點
Point P1 = new Point(this.Width - 100, this.Height - 100);
b.在點後寫入文字
TextRenderer.DrawText(g, "dsadhskldhashdalks", Font, P1, Color.YellowGreen);
#TextFormatFlags.HorizontalCenter將邊框內的文本水平居中對齊 TextFormatFlags.VerticalCenter在邊框內部垂直居中對齊文本
2.畫線
#畫橫線
g.DrawLine(new Pen(Color.Brown), 0, this.Height-1, this.Width, this.Height-1);//畫橫線鋪滿,對於高度不變,橫坐標從0到當前寬度,當前高度從-1到-1,就是畫出一像素的高度
#畫豎線
g.DrawLine(new Pen(Color.Purple), this.Width - 15, 0, this.Width - 15, this.Height - 14);//從(-15,0)到(-15,-14)繪制一條豎線,this.Width - 15-----當前寬度從右邊減去15像素處開始,this.Height - 14------當前高度從下邊減去14像素處開始
#畫虛線
private void panel1_Paint(object sender, PaintEventArgs e) { Control P = (Control)sender; Pen pen = new Pen(Color.FromArgb(255, 0, 0), 5); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;//虛線的樣式 pen.DashPattern = new float[] { 2, 2 };//設置虛線中實點和空白區域之間的間隔 Graphics g = e.Graphics; g.DrawLine(pen, 0, 0, 0, P.Height - 1); }
#對panel1重繪,this:當前頁面為panel1所在的頁面
來源: http://www.cnblogs.com/12jh23/archive/2017/02/24/6439722.html