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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problem with image push button vertical alignment

Thread ID:

Created:

Updated:

Platform:

Replies:

91127 Nov 4,2009 11:48 PM UTC Nov 10,2009 11:24 AM UTC WinForms 9
loading
Tags: GridControl
Julie Levy
Asked On November 4, 2009 11:48 PM UTC

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

Jisha Joy [Syncfusion]
Replied On 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

Julie Levy
Replied On 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

Jisha Joy [Syncfusion]
Replied On 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

Julie Levy
Replied On 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

Jisha Joy [Syncfusion]
Replied On 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

Julie Levy
Replied On 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

Julie Levy
Replied On 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

Julie Levy
Replied On 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

Jisha Joy [Syncfusion]
Replied On November 10, 2009 11:24 AM UTC

Hi Julie,

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

Regards,
Jisha

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;