// Create an ImageList Object, populate it, and display // the images it contains. private void Button1_Click(System.Object sender, System.EventArgs e) { // Construct the ImageList. ImageList1 = new ImageList(); // Set the ImageSize property to a larger size // (the default is 16 x 16). ImageList1.ImageSize = new Size(112, 112); // Add two images to the list. ImageList1.Images.Add( Image.FromFile("c:\\windows\\FeatherTexture.bmp")); ImageList1.Images.Add( Image.FromFile("C:\\windows\\Gone Fishing.bmp")); // Get a Graphics object from the form's handle. Graphics theGraphics = Graphics.FromHwnd(this.Handle); // Loop through the images in the list, drawing each image. for (int count = 0; count < ImageList1.Images.Count; count++) { ImageList1.Draw(theGraphics, new Point(85, 85), count); // Call Application.DoEvents to force a repaint of the form. Application.DoEvents(); // Call the Sleep method to allow the user to see the image. System.Threading.Thread.Sleep(1000); } }
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { int i, ks = 0; SolidBrush b = new SolidBrush(Color.White); for (i = 0; i <= satirsayisi * sutunsayisi - 1; i++) { float x, y; x = 60 * (i % sutunsayisi); y = 20 * (int)(i / sutunsayisi); if (kutu[i] != 100) { //Kutu varsa rasgele renkle boya Random r = new Random((int)(System.DateTime.Now.Ticks % System.Int32.MaxValue)); b.Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255)); ks++; e.Graphics.FillRectangle(b, x, y, 60, 20); e.Graphics.DrawRectangle(new Pen(this.BackColor), x, y, 60, 20); if (kutu[i] != 200) //bomba varsa resim koyma { ýmageList2.Draw(e.Graphics, (int)x + 22, (int)y + 2, kutu[i] - 1); } } else { //Kutu yoksa zemin rengine boya b.Color = this.BackColor; e.Graphics.FillRectangle(b, x, y, 60, 20); } } kutusayisi = ks; label2.Text = kutusayisi.ToString(); }
/// <summary> /// Repaint an image cell with an image in an image /// list. Run this method in the CellPainting event /// of the DataGridView. /// /// This method ignores invalid parameters. Provide /// it with empty or invalid indices to cause it to /// abort. /// </summary> public static void PaintImageCell(this DataGridView dataGridView, DataGridViewCellPaintingEventArgs e, ImageList imageList, String imageKey) { //Abort if any parameter is null or if the image does not exist if (e == null || imageList == null || imageKey.IsNullOrEmpty()) return; if (!imageList.Images.ContainsKey(imageKey)) return; //Paint the image e.PaintBackground(e.ClipBounds, false); var pt = e.CellBounds.Location; pt.X += (e.CellBounds.Width - imageList.ImageSize.Width) / 2; pt.Y += 4; imageList.Draw(e.Graphics, pt, imageList.Images.IndexOfKey(imageKey)); e.Handled = true; }
protected virtual int DrawImage(Graphics g, Rectangle r, object imageSelector) { if ((imageSelector != null) && (imageSelector != DBNull.Value)) { System.Windows.Forms.ImageList baseSmallImageList = this.ListView.BaseSmallImageList; if (baseSmallImageList != null) { int index = -1; if (imageSelector is int) { index = (int)imageSelector; } else { string key = imageSelector as string; if (key != null) { index = baseSmallImageList.Images.IndexOfKey(key); } } if (index >= 0) { if (!this.IsPrinting) { Rectangle rectangle = new Rectangle(r.X - this.Bounds.X, r.Y - this.Bounds.Y, r.Width, r.Height); baseSmallImageList.Draw(g, rectangle.Location, index); return(baseSmallImageList.ImageSize.Width); } imageSelector = baseSmallImageList.Images[index]; } } Image image = imageSelector as Image; if (image != null) { int y = r.Y; if (image.Size.Height < r.Height) { y += (r.Height - image.Size.Height) / 2; } g.DrawImageUnscaled(image, r.X, y); return(image.Width); } } return(0); }
private void drawItem(System.Windows.Forms.DrawItemEventArgs e) { if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); if (this.Focused) { e.DrawFocusRectangle(); } } else { e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds); } ilsIcons.Draw(e.Graphics, e.Bounds.Left + 2, e.Bounds.Top + 2, ilsIcons.ImageSize.Width, ilsIcons.ImageSize.Height, (int)this.Items[e.Index]); }
private void button1_Click(object sender, EventArgs e) { // Construct the ImageList. ImageList1 = new ImageList(); // Set the ImageSize property to a larger size // (the default is 16 x 16). ImageList1.ImageSize = new Size(112, 112); // Add two images to the list. ImageList1.Images.Add( Image.FromFile("d:\\smile\\1.jpg")); ImageList1.Images.Add( Image.FromFile("d:\\smile\\2.jpg")); ImageList1.Images.Add( Image.FromFile("d:\\smile\\3.jpg")); ImageList1.Images.Add( Image.FromFile("d:\\smile\\4.jpg")); // Get a Graphics object from the form's handle. Graphics theGraphics = Graphics.FromHwnd(this.Handle); // Loop through the images in the list, drawing each image. for (int count = 0; count < ImageList1.Images.Count; count++) { ImageList1.Draw(theGraphics, new Point(count*55+85, 85), count); // Call Application.DoEvents to force a repaint of the form. Application.DoEvents(); // Call the Sleep method to allow the user to see the image. System.Threading.Thread.Sleep(1000); } }
// Display the image. private void button1_Click(object sender, System.EventArgs e) { if (imageList1.Images.Empty != true) { if (imageList1.Images.Count - 1 > currentImage) { currentImage++; } else { currentImage = 0; } panel1.Refresh(); // Draw the image in the panel. imageList1.Draw(myGraphics, 10, 10, currentImage); // Show the image in the PictureBox. pictureBox1.Image = imageList1.Images[currentImage]; label3.Text = "Current image is " + currentImage; listBox1.SelectedIndex = currentImage; label5.Text = "Image is " + listBox1.Text; } }
Image CreateIcon(ImageList imgList, int index) { Bitmap bmp = new Bitmap(16, 16, System.Drawing.Imaging.PixelFormat.Format32bppRgb); using (Graphics g = Graphics.FromImage(bmp)) using( SolidBrush sb = new SolidBrush(BackColor)) { g.FillRectangle(sb, 0, 0, 16, 16); imgList.Draw(g, 0, 0, 16, 16, index); } return bmp; }
public bool Init(ImageList imageList, int nHSpace, int nVSpace, int nColumns, int defaultImage) { int nRows; Brush bgBrush = new SolidBrush(BackgroundColor); var vPen = new Pen(VLinesColor); var hPen = new Pen(HLinesColor); var borderPen = new Pen(BorderColor); _imageList = imageList; _nColumns = nColumns; _defaultImage = defaultImage; if (_defaultImage > _imageList.Images.Count) _defaultImage = _imageList.Images.Count; if (_defaultImage < 0) _defaultImage = -1; nRows = imageList.Images.Count/_nColumns; if (imageList.Images.Count%_nColumns > 0) nRows++; _nRows = nRows; _nHSpace = nHSpace; _nVSpace = nVSpace; _nItemWidth = _imageList.ImageSize.Width + nHSpace; _nItemHeight = _imageList.ImageSize.Height + nVSpace; _nBitmapWidth = _nColumns*_nItemWidth + 1; _nBitmapHeight = _nRows*_nItemHeight + 1; Width = _nBitmapWidth; Height = _nBitmapHeight; _Bitmap = new Bitmap(_nBitmapWidth, _nBitmapHeight); Graphics grfx = Graphics.FromImage(_Bitmap); grfx.FillRectangle(bgBrush, 0, 0, _nBitmapWidth, _nBitmapHeight); for (int i = 0; i < _nColumns; i++) grfx.DrawLine(vPen, i*_nItemWidth, 0, i*_nItemWidth, _nBitmapHeight - 1); for (int i = 0; i < _nRows; i++) grfx.DrawLine(hPen, 0, i*_nItemHeight, _nBitmapWidth - 1, i*_nItemHeight); grfx.DrawRectangle(borderPen, 0, 0, _nBitmapWidth - 1, _nBitmapHeight - 1); for (int i = 0; i < _nColumns; i++) for (int j = 0; j < _nRows; j++) { if ((j*_nColumns + i) < imageList.Images.Count) imageList.Draw(grfx, i*_nItemWidth + _nHSpace/2, j*_nItemHeight + nVSpace/2, imageList.ImageSize.Width, imageList.ImageSize.Height, j*_nColumns + i); } /* int a = (_defaultImage / _nColumns); // rad int b = (_defaultImage % _nColumns); // kolumn; _nCoordX = b*(_nItemWidth+_nHSpace/2)-1; _nCoordY = a*(_nItemHeight+nVSpace/2)-1; */ // Clean up bgBrush.Dispose(); vPen.Dispose(); hPen.Dispose(); borderPen.Dispose(); Invalidate(); return true; }
protected override void OnDrawItem(DrawItemEventArgs e) { e.DrawBackground(); e.DrawFocusRectangle(); ParseMessageEventArgs item; Rectangle bounds = e.Bounds; Color TextColor = System.Drawing.SystemColors.ControlText; item = (ParseMessageEventArgs)Items[e.Index]; //draw selected item background if (e.State == DrawItemState.Selected) { using (Brush b = new SolidBrush(System.Drawing.SystemColors.Highlight)) { // Fill background; e.Graphics.FillRectangle(b, e.Bounds); } TextColor = System.Drawing.SystemColors.HighlightText; } //draw image if (item.MessageType != ParseMessageType.None) { IconList.Draw( e.Graphics, bounds.Left + 1, bounds.Top + 2, (int)item.MessageType); } using (SolidBrush TextBrush = new SolidBrush(TextColor)) { //draw Headline e.Graphics.DrawString( item.LineHeader, m_HeadingFont, TextBrush, bounds.Left + IconList.ImageSize.Width + 5, bounds.Top + IconList.ImageSize.Height - m_HeadingFont.Height); //draw main text int LinesFilled = 0, CharsFitted = 0, top; // Draw layout, 2 times the offset (left & right) Size oneLine = new Size(this.Width - m_MainTextOffset * 2, this.Font.Height); StringBuilder sbTextToDraw = new StringBuilder(item.MessageText); string strLineToDraw; int index1 = 0, index2, index2New; top = bounds.Top + IconList.ImageSize.Height + 2; while (sbTextToDraw.Length > 0) { // Break string into more lines when an end-of-line character is found if ((index2 = sbTextToDraw.ToString().IndexOf('\n')) > 0) { strLineToDraw = sbTextToDraw.ToString(index1, index2 - index1); index2New = index2 + 1; } else { index2 = sbTextToDraw.Length; index2New = index2; strLineToDraw = sbTextToDraw.ToString(); } e.Graphics.MeasureString( strLineToDraw, this.Font, oneLine, StringFormat.GenericDefault, out CharsFitted, out LinesFilled); // There's no knowledge about words, so just don't split words up if possible if (CharsFitted < index2) { int index = strLineToDraw.LastIndexOf(' ', CharsFitted - 1, CharsFitted); if (index != -1) { index2New = index + 1; } else { index2New = CharsFitted; } strLineToDraw = sbTextToDraw.ToString(index1, index2New - index1); } // Draw the text e.Graphics.DrawString( strLineToDraw, this.Font, TextBrush, bounds.Left + m_MainTextOffset, top); // Adjust top top += this.Font.Height; // Next line sbTextToDraw = sbTextToDraw.Remove(index1, index2New); } sbTextToDraw = null; strLineToDraw = null; } }
public static void ImageListDraw(ImageList il, int index, Graphics graphics, int x, int y, int dx, int dy) { #if _DOTNET2 il.Draw(graphics, x, y, dx, dy, index); #else // In .Net 1.1, ImageList.Draw does not draw PNG images correctly IntPtr hdc = graphics.GetHdc(); ImageList_DrawEx(il.Handle, index, hdc, x, y, dx, dy, 0xFFFFFFFF, 0xFF000000, 0); graphics.ReleaseHdc(hdc); #endif }
public bool Init(ImageList imageList, int horizontal, int vertical, int columns, int defaultImage) { int nRows; if (imageList!=null) { Brush bgBrush = new SolidBrush(BackgroundColor); Pen vPen = new Pen(VLinesColor); Pen hPen = new Pen(HLinesColor); Pen borderPen = new Pen(BorderColor); _imageList = imageList; _nColumns = columns; _defaultImage = defaultImage; if (_defaultImage > _imageList.Images.Count) _defaultImage = _imageList.Images.Count; if (_defaultImage < 0) _defaultImage = -1; nRows = imageList.Images.Count / _nColumns; if (imageList.Images.Count % _nColumns > 0) nRows++; _nRows = nRows; _nHSpace = horizontal; _nVSpace = vertical; _nItemWidth = _imageList.ImageSize.Width + horizontal; _nItemHeight = _imageList.ImageSize.Height + vertical; _nBitmapWidth = _nColumns * _nItemWidth + 1; _nBitmapHeight = _nRows * _nItemHeight + 1; this.Width = _nBitmapWidth; this.Height = _nBitmapHeight; _Bitmap = new Bitmap(_nBitmapWidth,_nBitmapHeight); Graphics grfx = Graphics.FromImage(_Bitmap); grfx.FillRectangle(bgBrush, 0, 0, _nBitmapWidth, _nBitmapHeight); for (int i=0;i<_nColumns;i++) grfx.DrawLine(vPen, i*_nItemWidth, 0, i*_nItemWidth, _nBitmapHeight-1); for (int i=0;i<_nRows;i++) grfx.DrawLine(hPen, 0, i*_nItemHeight, _nBitmapWidth-1, i*_nItemHeight); grfx.DrawRectangle(borderPen, 0 ,0 , _nBitmapWidth-1, _nBitmapHeight-1); for (int i=0;i<_nColumns;i++) for (int j=0;j<_nRows ;j++) { if ((j*_nColumns+i) < imageList.Images.Count) imageList.Draw(grfx, i*_nItemWidth+_nHSpace/2, j*_nItemHeight+vertical/2, imageList.ImageSize.Width, imageList.ImageSize.Height, j*_nColumns+i); } /* int a = (_defaultImage / _nColumns); // rad int b = (_defaultImage % _nColumns); // kolumn; _nCoordX = b*(_nItemWidth+_nHSpace/2)-1; _nCoordY = a*(_nItemHeight+nVSpace/2)-1; */ // Clean up bgBrush.Dispose(); vPen.Dispose(); hPen.Dispose(); borderPen.Dispose(); Invalidate(); return true; } else throw new System.ArgumentNullException("imageList"); }
private void DrawIcon(Graphics gfx, Rectangle rect, bool isSelected, bool isChecked, bool isRadioChecked, bool isEnabled) { System.Windows.Forms.ImageList iconImageList = null; IconMainMenu m = (IconMainMenu)this.GetMainMenu(); if (m != null) { iconImageList = m.IconImageList; } else { IconContextMenu c = (IconContextMenu)this.GetContextMenu(); if (c != null) { iconImageList = c.IconImageList; } } bool hasIcon = false; if (iconImageList != null) { if ((m_iconIndex >= 0) && (m_iconIndex < iconImageList.Images.Count)) { hasIcon = true; int x = rect.Left + (iconWidth - iconImageList.ImageSize.Width) / 2; int y = rect.Top + (rect.Height - iconImageList.ImageSize.Height) / 2; if ((isSelected) && (isEnabled)) { // draw icon as a shadow here ControlPaint.DrawImageDisabled(gfx, iconImageList.Images[m_iconIndex], x, y, Color.FromKnownColor(KnownColor.Control)); x -= 1; y -= 1; } if (isEnabled) { iconImageList.Draw(gfx, x, y, iconImageList.ImageSize.Width, iconImageList.ImageSize.Height, m_iconIndex); } else { ControlPaint.DrawImageDisabled(gfx, iconImageList.Images[m_iconIndex], x, y, Color.FromKnownColor(KnownColor.Control)); } } } if (isChecked) { Rectangle checkRect = rect; checkRect.Width = iconWidth; checkRect.Inflate(-1, -1); checkRect.Height -= 1; Pen pen = SystemPens.Highlight; gfx.DrawRectangle(pen, checkRect); if (!hasIcon) { int x = rect.Left + (iconWidth - SystemInformation.MenuCheckSize.Width) / 2; int y = rect.Top + (rect.Height - SystemInformation.MenuCheckSize.Width) / 2; // Fill the background of the check item with an alpha-blended // highlight colour: int alpha = 24; if (isSelected) { alpha = 128; } Brush br = new SolidBrush(Color.FromArgb(alpha, Color.FromKnownColor(KnownColor.Highlight))); gfx.FillRectangle(br, checkRect); br.Dispose(); // create a new bitmap to draw the menu glyph onto: Bitmap bm = new Bitmap(SystemInformation.MenuCheckSize.Width, SystemInformation.MenuCheckSize.Height); Graphics gr = Graphics.FromImage(bm); if (isRadioChecked) { // draw radio option ControlPaint.DrawMenuGlyph(gr, 0, 0, bm.Width, bm.Height, MenuGlyph.Bullet); } else { // draw check mark ControlPaint.DrawMenuGlyph(gr, 0, 0, bm.Width, bm.Height, MenuGlyph.Checkmark); } Rectangle outRect = new Rectangle(x, y, bm.Width, bm.Height); // Draw the menu glyph transparently: ImageAttributes imgAttr = new ImageAttributes(); imgAttr.SetColorKey(bm.GetPixel(0, 0), bm.GetPixel(0, 0), ColorAdjustType.Default); gfx.DrawImage(bm, outRect, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, imgAttr); imgAttr.Dispose(); bm.Dispose(); gr.Dispose(); } } }
/// <summary> /// バッファに装備アイテム画像を描画する /// </summary> /// <param name="iconImageList"></param> /// <param name="canvas"></param> /// <param name="backBrush"></param> /// <param name="itemIndex"></param> void DrawSlotItemImage(ImageList iconImageList, Image canvas, Brush backBrush,int itemIndex) { using (Graphics g = Graphics.FromImage(canvas)) { g.FillRectangle(backBrush, new Rectangle(new Point(0, 0), canvas.Size)); //装着されてるスロット かつ 装備情報読み込み済み if (itemIndex < iconImageList.Images.Count) iconImageList.Draw(g, new Point(1, 0), itemIndex); else iconImageList.Draw(g, new Point(1, 0), 0); } }
public void Draw(Graphics g, ImageList imgList) { imgList.Draw(g, new Point(x, y), cell_id - 1); }
public void Paint( Graphics g, Rectangle r, ImageList list, Color bg ) { if( style == FlatButtonType.Control ) { return; } if( style == FlatButtonType.Line ) g.DrawLine( Pens.DarkGray, r.X + 2, r.Top, r.X + 2, r.Bottom - 1 ); else { if( style == FlatButtonType.RadioDown ) { g.FillRectangle( Brushes.Lavender, r.X, r.Y, r.Width - 1, r.Height - 1 ); bg = Color.Lavender; } else if( state != FlatButtonState.Basic ) { g.FillRectangle( state == FlatButtonState.Hover ? Brushes.LightSteelBlue : Brushes.SteelBlue, r.X, r.Y, r.Width - 1, r.Height - 1 ); bg = state == FlatButtonState.Hover ? Color.LightSteelBlue : Color.SteelBlue; } if( style == FlatButtonType.RadioDown || state != FlatButtonState.Basic ) g.DrawRectangle( Pens.DarkBlue, r.Left, r.Top, r.Width - 1, r.Height - 1 ); int hover = state == FlatButtonState.Hover ? 1 : 0; if( disabled ) ControlPaint.DrawImageDisabled( g, list.Images[image_index], r.X + 3 - hover, r.Y + 3 - hover, bg ); else list.Draw( g, r.X + 3 - hover, r.Y + 3 - hover, 16, 16, image_index ); } }
public bool Init(ImageList imageList, int nHSpace, int nVSpace, int nColumns, int nRows) { _imageList = imageList; _nColumns = nColumns; _nRows = nRows; _nHSpace = nHSpace; _nVSpace = nVSpace; _nItemWidth = _imageList.ImageSize.Width + nHSpace; _nItemHeight = _imageList.ImageSize.Height + nVSpace; _nBitmapWidth = _nColumns * _nItemWidth + 1; _nBitmapHeight = _nRows * _nItemHeight + 1; this.Width = _nBitmapWidth; this.Height = _nBitmapHeight; _Bitmap = new Bitmap(_nBitmapWidth, _nBitmapHeight); Graphics grfx = Graphics.FromImage(_Bitmap); grfx.FillRectangle(new SolidBrush(BackgroundColor), 0, 0, _nBitmapWidth, _nBitmapHeight); for (int i = 0; i < _nColumns; i++) grfx.DrawLine(new Pen(VLinesColor), i * _nItemWidth, 0, i * _nItemWidth, _nBitmapHeight - 1); for (int i = 0; i < _nRows; i++) grfx.DrawLine(new Pen(HLinesColor), 0, i * _nItemHeight, _nBitmapWidth - 1, i * _nItemHeight); grfx.DrawRectangle(new Pen(BorderColor), 0, 0, _nBitmapWidth - 1, _nBitmapHeight - 1); for (int i = 0; i < _nColumns; i++) for (int j = 0; j < _nRows; j++) if ((j * _nColumns + i) < imageList.Images.Count) imageList.Draw(grfx, i * _nItemWidth + _nHSpace / 2, j * _nItemHeight + nVSpace / 2, imageList.ImageSize.Width, imageList.ImageSize.Height, j * _nColumns + i); return true; }
public void RecreateHandleEvenTest () { Form myform = new Form (); myform.ShowInTaskbar = false; Graphics mygraphics = null; ImageList myimagelist = new ImageList (); Image myImage = Image.FromFile("M.gif"); myimagelist.Images.Add (myImage); myimagelist.ColorDepth = ColorDepth.Depth8Bit; myimagelist.ImageSize = new Size (50,50); myimagelist.RecreateHandle += new EventHandler (RecreateHandle_EventHandler); mygraphics = Graphics.FromHwnd(myform.Handle); myimagelist.Draw(mygraphics, new Point(5, 5), 0); myimagelist.ImageSize = new Size (100,100); Assert.AreEqual (true, eventhandled, "#1"); eventhandled = false; myimagelist.Images.Add (myImage); myimagelist.ColorDepth = ColorDepth.Depth32Bit; Assert.AreEqual (true, eventhandled, "#2"); myform.Dispose (); }