Hi,
I found the following code in a FAQ about the datagridview.
But I am having a hard time translating it to VB, so I would like to ask via
here for someone more experienced to translate this code to VB.
When I can read it in VB I want to replace everything about the image into a
button.
Thanks in advance!
Eric.
public class TextAndImageCol umn:DataGridVie wTextBoxColumn
{
private Image imageValue;
private Size imageSize;
public TextAndImageCol umn()
{
this.CellTempla te = new TextAndImageCel l();
}
public override object Clone()
{
TextAndImageCol umn c = base.Clone() as TextAndImageCol umn;
c.imageValue = this.imageValue ;
c.imageSize = this.imageSize;
return c;
}
public Image Image
{
get { return this.imageValue ; }
set
{
if (this.Image != value) {
this.imageValue = value;
this.imageSize = value.Size;
if (this.Inherited Style != null) {
Padding inheritedPaddin g =
this.InheritedS tyle.Padding;
this.DefaultCel lStyle.Padding = new
Padding(imageSi ze.Width,
inheritedPaddin g.Top, inheritedPaddin g.Right,
inheritedPaddin g.Bottom);
}
}
}
}
private TextAndImageCel l TextAndImageCel lTemplate
{
get { return this.CellTempla te as TextAndImageCel l; }
}
internal Size ImageSize
{
get { return imageSize; }
}
}
public class TextAndImageCel l : DataGridViewTex tBoxCell
{
private Image imageValue;
private Size imageSize;
public override object Clone()
{
TextAndImageCel l c = base.Clone() as TextAndImageCel l;
c.imageValue= this.imageValue ;
c.imageSize = this.imageSize;
return c;
}
public Image Image
{
get {
if (this.OwningCol umn == null ||
this.OwningText AndImageColumn == null) {
return imageValue;
}
else if (this.imageValu e != null) {
return this.imageValue ;
}
else {
return this.OwningText AndImageColumn. Image;
}
}
set {
if (this.imageValu e != value) {
this.imageValue = value;
this.imageSize = value.Size;
Padding inheritedPaddin g = this.InheritedS tyle.Padding;
this.Style.Padd ing = new Padding(imageSi ze.Width,
inheritedPaddin g.Top, inheritedPaddin g.Right,
inheritedPaddin g.Bottom);
}
}
}
protected override void Paint(Graphics graphics, Rectangle
clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewEle mentStates
cellState,
object value, object formattedValue, string errorText,
DataGridViewCel lStyle cellStyle,
DataGridViewAdv ancedBorderStyl e advancedBorderS tyle,
DataGridViewPai ntParts paintParts)
{
// Paint the base content
base.Paint(grap hics, clipBounds, cellBounds, rowIndex,
cellState,
value, formattedValue, errorText, cellStyle,
advancedBorderS tyle, paintParts);
if (this.Image != null) {
// Draw the image clipped to the cell.
System.Drawing. Drawing2D.Graph icsContainer container =
graphics.BeginC ontainer();
graphics.SetCli p(cellBounds);
graphics.DrawIm ageUnscaled(thi s.Image, cellBounds.Loca tion);
graphics.EndCon tainer(containe r);
}
}
private TextAndImageCol umn OwningTextAndIm ageColumn
{
get { return this.OwningColu mn as TextAndImageCol umn; }
}
}
I found the following code in a FAQ about the datagridview.
But I am having a hard time translating it to VB, so I would like to ask via
here for someone more experienced to translate this code to VB.
When I can read it in VB I want to replace everything about the image into a
button.
Thanks in advance!
Eric.
public class TextAndImageCol umn:DataGridVie wTextBoxColumn
{
private Image imageValue;
private Size imageSize;
public TextAndImageCol umn()
{
this.CellTempla te = new TextAndImageCel l();
}
public override object Clone()
{
TextAndImageCol umn c = base.Clone() as TextAndImageCol umn;
c.imageValue = this.imageValue ;
c.imageSize = this.imageSize;
return c;
}
public Image Image
{
get { return this.imageValue ; }
set
{
if (this.Image != value) {
this.imageValue = value;
this.imageSize = value.Size;
if (this.Inherited Style != null) {
Padding inheritedPaddin g =
this.InheritedS tyle.Padding;
this.DefaultCel lStyle.Padding = new
Padding(imageSi ze.Width,
inheritedPaddin g.Top, inheritedPaddin g.Right,
inheritedPaddin g.Bottom);
}
}
}
}
private TextAndImageCel l TextAndImageCel lTemplate
{
get { return this.CellTempla te as TextAndImageCel l; }
}
internal Size ImageSize
{
get { return imageSize; }
}
}
public class TextAndImageCel l : DataGridViewTex tBoxCell
{
private Image imageValue;
private Size imageSize;
public override object Clone()
{
TextAndImageCel l c = base.Clone() as TextAndImageCel l;
c.imageValue= this.imageValue ;
c.imageSize = this.imageSize;
return c;
}
public Image Image
{
get {
if (this.OwningCol umn == null ||
this.OwningText AndImageColumn == null) {
return imageValue;
}
else if (this.imageValu e != null) {
return this.imageValue ;
}
else {
return this.OwningText AndImageColumn. Image;
}
}
set {
if (this.imageValu e != value) {
this.imageValue = value;
this.imageSize = value.Size;
Padding inheritedPaddin g = this.InheritedS tyle.Padding;
this.Style.Padd ing = new Padding(imageSi ze.Width,
inheritedPaddin g.Top, inheritedPaddin g.Right,
inheritedPaddin g.Bottom);
}
}
}
protected override void Paint(Graphics graphics, Rectangle
clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewEle mentStates
cellState,
object value, object formattedValue, string errorText,
DataGridViewCel lStyle cellStyle,
DataGridViewAdv ancedBorderStyl e advancedBorderS tyle,
DataGridViewPai ntParts paintParts)
{
// Paint the base content
base.Paint(grap hics, clipBounds, cellBounds, rowIndex,
cellState,
value, formattedValue, errorText, cellStyle,
advancedBorderS tyle, paintParts);
if (this.Image != null) {
// Draw the image clipped to the cell.
System.Drawing. Drawing2D.Graph icsContainer container =
graphics.BeginC ontainer();
graphics.SetCli p(cellBounds);
graphics.DrawIm ageUnscaled(thi s.Image, cellBounds.Loca tion);
graphics.EndCon tainer(containe r);
}
}
private TextAndImageCol umn OwningTextAndIm ageColumn
{
get { return this.OwningColu mn as TextAndImageCol umn; }
}
}
Comment