We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem with image push button vertical alignment

I have a pushbutton cell with an image. Even though the vertical alignment is set to middle, the image floats to the top of the cell when the rowheight grows.

Here are the properties i am setting to create the cell:
----------
cellStyle.Themed = false;
cellStyle.BackColor = System.Drawing.Color.FromArgb(242, 247, 253);
cellStyle.CellType = CELLTYPE_PUSHBUTTON;
cellStyle.Tag = imageIndex;
cellStyle.ImageList = this.imageList1;
cellStyle.ImageIndex = imageIndex;
cellStyle.HorizontalAlignment = GridHorizontalAlignment.Center;
cellStyle.VerticalAlignment = GridVerticalAlignment.Middle;
cellStyle.Clickable = true;
cellStyle.CellAppearance = GridCellAppearance.Flat;
cellStyle.CellTipText = tooltipText;
-----------

Is there something i'm missing?
We are using version 5.2.0.25. I've attached a screenshot displaying the problem (it's the X at the end of the row).

Thanks,
Julie



gridImageVertical_8bfe764e.zip

9 Replies

JJ Jisha Joy Syncfusion Team November 5, 2009 09:54 AM UTC

Hi Julie,

The sample \Essential Studio\5.2.0.25\Windows\Grid.Windows\Samples\CustomCelltype\CellButtons shows how you can have a butten that displays a bitmap. See the ellipsis cell type used there.

Another way you can do this is to set the CellType to "PushButton" and subscribe to the grid's DrawCellButton event. There you can use e.Graphics.DrawImage to draw the bitmap and then set e.Cancel = true to indicate you have handled the drawing.

Please let me know if you have any specific questions.

Regards,
Jisha


JL Julie Levy November 5, 2009 05:26 PM UTC

Sorry, i am using the DrawCellButton event. Do you have an example of how to center in the cell for this approach.

here's the code i'm using right now:
Rectangle rctButton = new Rectangle(e.Button.Bounds.X, e.Button.Bounds.Y,14, 14);

e.Graphics.DrawImage(imageList1.Images[iImageIndex], rctButton);
e.Cancel = true;

Thanks,
Julie


JJ Jisha Joy Syncfusion Team November 6, 2009 10:50 AM UTC

Hi Julie,

Please refer the following code snippets draw the image over the pushbutton. Image will not float if we resize the rows.

void gridControl1_DrawCell(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
if (e.Style.CellType == "PushButton")
{
e.Cancel = true;

// //Draw the Image in a cell.
string sButtonText = e.Style.Description;
e.Style.Description = string.Empty;
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);

Rectangle irect = new Rectangle(new Point(e.Bounds.X + 3, e.Bounds.Y + 3), new Size(e.Bounds.Size.Width - 6, e.Bounds.Size.Height - 6));
e.Graphics.DrawImage(this.imageList1.Images[e.RowIndex % this.imageList1.Images.Count], irect);

}

}


Regards,
Jisha


JL Julie Levy November 6, 2009 07:36 PM UTC

This actually produces a stretched out image and a loss of our button style.

If there is no way to do this in DrawCell or DrawCellButton, i guess i'll have to try the custom cell approach.



imagebutton_9607c3ab.zip


JJ Jisha Joy Syncfusion Team November 9, 2009 07:29 AM UTC

Hi Julie,

Please try using the following attached sample that implements pushbutton with image using Custom celltypes.

Please let me know if this helps.
Regards,
Jisha



Sample1_a80f0489.zip


JL Julie Levy November 9, 2009 05:32 PM UTC

Thanks. My biggest challenge with using this sample is that i need a generic image button which can be used for any image (to be provided in an imagelist, not an embedded resource. Can i still use the iconpainter approach somehow? I'm assuming not and that i have to use the Image.Draw approach like in my previous attempts. I'm hoping that i don't have similar issues here. I'll give it a try and let you know.

If you have any samples of this using the Image.Draw approach, I would appreciate it if you could attach it here.

Thanks again,
Julie


JL Julie Levy November 9, 2009 10:56 PM UTC

One more thing: since your sample ellipses cell is based on a textbox, users can enter text. I definitely don't want this and also really just need a cell with an image button in it, no text box.

Thanks,
Julie


JL Julie Levy November 9, 2009 11:45 PM UTC

Actually the ellipses cell approach doesn't work for me at all.. i just want the image to show up and the cell to raise a recognizeable click,but no button visible.

I'm going to abandon the whole button cell approach and just try it with a static cell.

Thanks for your help,
Julie


JJ Jisha Joy Syncfusion Team November 10, 2009 11:24 AM UTC

Hi Julie,

COuld you please let me know if you have any specific questions?.

Regards,
Jisha

Loader.
Live Chat Icon For mobile
Up arrow icon