2012年1月12日 星期四

VB.Net-Picturebox執行時直接顯示文字

要在Picturebox上顯示文字
使用方式很簡單
先把Picturebox背景指定給圖像
如此就依照Picturebox的背景進行寫字
之後把這圖像產生畫布
在上面寫字即可
最後用DrawString函式
在畫布寫完字後在指定給PictureBox


Dim bmp1 = New Bitmap(PictureBox1.Width, PictureBox1.Height)   '產生圖像
bmp1 = PictureBox1.BackgroundImage
Dim g1 = Graphics.FromImage(bmp1) '產生畫布
Dim mycolor1 As New SolidBrush(Color.FromArgb(20, 20, 20))   '定義字體顏色
g1.DrawString("機械座標", New Font("Microsoft JhengHei", 16, FontStyle.Regular), mycolor1, 5, 7) '畫布寫上字串
PictureBox1.BackgroundImage = bmp1    'PictureBox1.Image指定該圖像

沒有留言:

張貼留言