Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
- {
- e.DrawBackground();
- if (e.Index > -1)
- {
- String itemText = String.Format("{0}", this.Items.Count > 0 ? this.Items[e.Index] : this.Name);
- //Snip
- System.Windows.Forms.ControlPaint.DrawButton(e.Graphics, e.Bounds, ButtonState.Normal);
- e.Graphics.DrawString(itemText, this.Font, SystemBrushes.ControlText, e.Bounds);
- }
- }
- public delegate void OnPaintDelegate( PaintEventArgs e );
- private void panel1_Paint( object sender, PaintEventArgs e ) {
- OnPaintDelegate paintDelegate = (OnPaintDelegate)Delegate.CreateDelegate(
- typeof( OnPaintDelegate )
- , this.button1
- , "OnPaint" );
- paintDelegate( e );
- }
- [DllImport("gdi32.dll")]
- private static extern bool BitBlt(
- IntPtr hdcDest,
- int nXDest,
- int nYDest,
- int nWidth,
- int nHeight,
- IntPtr hdcSrc,
- int nXSrc,
- int nYSrc,
- int dwRop
- );
- private const Int32 SRCCOPY = 0xCC0020;
- ....
- Graphics sourceGraphics = sourceControl.CreateGraphics();
- Graphics targetGraphics = targetControl.CreateGraphics();
- Size controlSize = sourceControl.Size;
- IntPtr sourceDc = sourceGraphics.GetHdc();
- IntPtr targerDc = targetGraphics.GetHdc();
- BitBlt(targerDc, 0, 0, controlSize.Width, controlSize.Height, sourceDc, 0, 0, SRCCOPY);
- sourceGraphics.ReleaseHdc(sourceDc);
- targetGraphics.ReleaseHdc(targerDc);
- class MyPanel : System.Windows.Forms.Panel
- {
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- }
- }
- Button btn = new Button();
- btn.Text = "Hey!";
- Bitmap bmp = new Bitmap(btn.Width, btn.Height);
- btn.DrawToBitmap(bmp, new Rectangle(0, 0, btn.Width, btn.Height));
- PictureBox pb = new PictureBox();
- pb.Size = btn.Size;
- pb.Image = bmp;
- e.Graphics.DrawImage(bmp, 0, 0);
- bmp.Dispose();
Add Comment
Please, Sign In to add comment