#眉標=Windows Mobile、PictureBox、.NET CF #副標=Windows Mobile開發系列(14) #大標=行動裝置圖形介面開發技巧 #作者=文/圖 沈炳宏 ==========程式========= 程式1 using System.Drawing; ... protected override void OnPaint(PaintEventArgs e) { using (Image backgroundImage = new Bitmap( System.Reflection.Assembly.GetExecutingAssembly() .GetManifestResourceStream("runpc.JPG"))) { e.Graphics.DrawImage(backgroundImage, 0, 0); } } ==========程式========= ==========程式========= 程式2 protected override void OnPaint(PaintEventArgs e) { int penSize = 4; int fontSize = 10; using (Pen pen = new Pen(Color.Yellow, penSize)) {using (Font font = new Font( "Arial", fontSize, FontStyle.Regular)) {using (SolidBrush brush = new SolidBrush(Color.White)) {SizeF textSize = e.Graphics.MeasureString(s, font); int rectWidth = Convert.ToInt32((textSize.Width) + 10); int rectHeight = Convert.ToInt32((textSize.Height) + 10); Rectangle r = new Rectangle( (e.ClipRectangle.Width - rectWidth) / 2, e.ClipRectangle.Height - rectHeight - 15, rectWidthrectHeight); e.Graphics.DrawRectangle(pen, r); e.Graphics.DrawString(s, font, brush, r.Left + 5, r.Top + 5); ==========程式========= ==========程式========= 程式3 protected override void OnPaint(PaintEventArgs e) { using (Pen redPen = new Pen(Color.Red, 3)) { int length = e.ClipRectangle.Width - 20; int x1 = 10; int y1 = 10; int x2 = length + 10; int y2 = 10; e.Graphics.DrawLine(redPen, x1, y1, x2, y2); ==========程式========= ==========程式========= 程式4 System.Drawing.Imaging.ImageAttributes attrib = new System.Drawing.Imaging.ImageAttributes (); attrib.SetColorKey (Color.Black, Color.Black); e.Graphics.DrawImage ( backgroundIm, DestRect, 0, 0, backgroundIm.Width, backgroundIm.Height, GraphicsUnit.Pixel, attrib); ==========程式========= ==========程式========= 程式5 public class PlatformAPIs { [DllImport("coredll.dll")] extern public static Int32 AlphaBlend(IntPtr hdcDest, Int32 xDest, Int32 yDest, Int32 cxDest, Int32 cyDest, IntPtr hdcSrc, Int32 xSrc, Int32 ySrc, Int32 cxSrc, Int32 cySrc, BlendFunction blendFunction); } ==========程式========= ==========程式========= 程式6 [ComImport, Guid( "327ABDA9-072B-11D3-9D7B-0000F81EF32E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [ComVisible(true)] public interface IImage { uint GetPhysicalDimension(out Size size); uint GetImageInfo(out ImageInfo info); uint SetImageFlags(uint flags); uint Draw(IntPtr hdc, ref Rectangle dstRect, IntPtr NULL); uint PushIntoSink(); uint GetThumbnail(uint thumbWidth, uint thumbHeight, out IImage thumbImage); } ==========程式=========