translation needed: C to VB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EricW

    translation needed: C to VB

    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; }
    }
    }


  • Mr. Arnold

    #2
    Re: translation needed: C to VB


    "EricW" <iemand@home.co mwrote in message
    news:48a5415b$0 $6000$9a622dc7@ news.kpnplanet. nl...
    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.
    >


    Comment

    • =?Utf-8?B?RGF2aWQgQW50b24=?=

      #3
      RE: translation needed: C to VB

      (Instant VB)
      Public Class TextAndImageCol umn
      Inherits DataGridViewTex tBoxColumn
      Private imageValue As Image
      Private imageSize_Renam ed As Size

      Public Sub New()
      Me.CellTemplate = New TextAndImageCel l()
      End Sub

      Public Overrides Function Clone() As Object
      Dim c As TextAndImageCol umn = TryCast(MyBase. Clone(), TextAndImageCol umn)
      c.imageValue = Me.imageValue
      c.imageSize = Me.imageSize_Re named
      Return c
      End Function

      Public Property Image() As Image
      Get
      Return Me.imageValue
      End Get
      Set(ByVal value As Image)
      If Me.Image IsNot value Then
      Me.imageValue = value
      Me.imageSize_Re named = value.Size

      If Me.InheritedSty le IsNot Nothing Then
      Dim inheritedPaddin g As Padding = Me.InheritedSty le.Padding
      Me.DefaultCellS tyle.Padding = New Padding(imageSi ze_Renamed.Widt h,
      inheritedPaddin g.Top, inheritedPaddin g.Right, inheritedPaddin g.Bottom)
      End If
      End If
      End Set
      End Property
      Private ReadOnly Property TextAndImageCel lTemplate() As TextAndImageCel l
      Get
      Return TryCast(Me.Cell Template, TextAndImageCel l)
      End Get
      End Property
      Friend ReadOnly Property ImageSize() As Size
      Get
      Return imageSize_Renam ed
      End Get
      End Property
      End Class

      Public Class TextAndImageCel l
      Inherits DataGridViewTex tBoxCell
      Private imageValue As Image
      Private imageSize As Size

      Public Overrides Function Clone() As Object
      Dim c As TextAndImageCel l = TryCast(MyBase. Clone(), TextAndImageCel l)
      c.imageValue= Me.imageValue
      c.imageSize = Me.imageSize
      Return c
      End Function

      Public Property Image() As Image
      Get
      If Me.OwningColumn Is Nothing OrElse Me.OwningTextAn dImageColumn Is
      Nothing Then

      Return imageValue
      ElseIf Me.imageValue IsNot Nothing Then
      Return Me.imageValue
      Else
      Return Me.OwningTextAn dImageColumn.Im age
      End If
      End Get
      Set(ByVal value As Image)
      If Me.imageValue IsNot value Then
      Me.imageValue = value
      Me.imageSize = value.Size

      Dim inheritedPaddin g As Padding = Me.InheritedSty le.Padding
      Me.Style.Paddin g = New Padding(imageSi ze.Width, inheritedPaddin g.Top,
      inheritedPaddin g.Right, inheritedPaddin g.Bottom)
      End If
      End Set
      End Property
      Protected Overrides Sub Paint(ByVal graphics As Graphics, ByVal clipBounds
      As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex As Integer, ByVal
      cellState As DataGridViewEle mentStates, ByVal value As Object, ByVal
      formattedValue As Object, ByVal errorText As String, ByVal cellStyle As
      DataGridViewCel lStyle, ByVal advancedBorderS tyle As
      DataGridViewAdv ancedBorderStyl e, ByVal paintParts As DataGridViewPai ntParts)
      ' Paint the base content
      MyBase.Paint(gr aphics, clipBounds, cellBounds, rowIndex, cellState,
      value, formattedValue, errorText, cellStyle, advancedBorderS tyle, paintParts)

      If Me.Image IsNot Nothing Then
      ' Draw the image clipped to the cell.
      Dim container As System.Drawing. Drawing2D.Graph icsContainer =
      graphics.BeginC ontainer()

      graphics.SetCli p(cellBounds)
      graphics.DrawIm ageUnscaled(Me. Image, cellBounds.Loca tion)

      graphics.EndCon tainer(containe r)
      End If
      End Sub

      Private ReadOnly Property OwningTextAndIm ageColumn() As TextAndImageCol umn
      Get
      Return TryCast(Me.Owni ngColumn, TextAndImageCol umn)
      End Get
      End Property
      End Class

      --
      Source code converters: Convert between C#, C++, Java, VB, and Python with the most accurate and reliable source code converters

      C++ to C#
      C++ to VB
      C++ to Java
      VB & C# to Java
      Java to VB & C#
      Instant C#: VB to C#
      Instant VB: C# to VB
      Instant C++: VB, C#, or Java to C++/CLI


      "EricW" wrote:
      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; }
      }
      }
      >
      >
      >

      Comment

      Working...