473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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 TextAndImageColumn:DataGridViewTextBoxColumn
{
private Image imageValue;
private Size imageSize;

public TextAndImageColumn()
{
this.CellTemplate = new TextAndImageCell();
}

public override object Clone()
{
TextAndImageColumn c = base.Clone() as TextAndImageColumn;
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.InheritedStyle != null) {
Padding inheritedPadding =
this.InheritedStyle.Padding;
this.DefaultCellStyle.Padding = new
Padding(imageSize.Width,
inheritedPadding.Top, inheritedPadding.Right,
inheritedPadding.Bottom);
}
}
}
}
private TextAndImageCell TextAndImageCellTemplate
{
get { return this.CellTemplate as TextAndImageCell; }
}
internal Size ImageSize
{
get { return imageSize; }
}
}

public class TextAndImageCell : DataGridViewTextBoxCell
{
private Image imageValue;
private Size imageSize;

public override object Clone()
{
TextAndImageCell c = base.Clone() as TextAndImageCell;
c.imageValue= this.imageValue;
c.imageSize = this.imageSize;
return c;
}

public Image Image
{
get {
if (this.OwningColumn == null ||
this.OwningTextAndImageColumn == null) {

return imageValue;
}
else if (this.imageValue != null) {
return this.imageValue;
}
else {
return this.OwningTextAndImageColumn.Image;
}
}
set {
if (this.imageValue != value) {
this.imageValue = value;
this.imageSize = value.Size;

Padding inheritedPadding = this.InheritedStyle.Padding;
this.Style.Padding = new Padding(imageSize.Width,
inheritedPadding.Top, inheritedPadding.Right,
inheritedPadding.Bottom);
}
}
}
protected override void Paint(Graphics graphics, Rectangle
clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewElementStates
cellState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
// Paint the base content
base.Paint(graphics, clipBounds, cellBounds, rowIndex,
cellState,
value, formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);

if (this.Image != null) {
// Draw the image clipped to the cell.
System.Drawing.Drawing2D.GraphicsContainer container =
graphics.BeginContainer();

graphics.SetClip(cellBounds);
graphics.DrawImageUnscaled(this.Image, cellBounds.Location);

graphics.EndContainer(container);
}
}

private TextAndImageColumn OwningTextAndImageColumn
{
get { return this.OwningColumn as TextAndImageColumn; }
}
}
Aug 15 '08 #1
4 1099
EricW wrote:
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.
The code you provided is in C#, not C.

You can use the following service to translate the code to VB.NET:

http://labs.developerfusion.co.uk/co...arp-to-vb.aspx

HTH,

--

(O)enone

Aug 15 '08 #2
Thanks!
"(O)enone" <oe****@nowhere.comschreef in bericht
news:g8**********@aioe.org...
EricW wrote:
>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.

The code you provided is in C#, not C.

You can use the following service to translate the code to VB.NET:

http://labs.developerfusion.co.uk/co...arp-to-vb.aspx

HTH,

--

(O)enone

Aug 15 '08 #3
(Instant VB)
Public Class TextAndImageColumn
Inherits DataGridViewTextBoxColumn
Private imageValue As Image
Private imageSize_Renamed As Size

Public Sub New()
Me.CellTemplate = New TextAndImageCell()
End Sub

Public Overrides Function Clone() As Object
Dim c As TextAndImageColumn = TryCast(MyBase.Clone(), TextAndImageColumn)
c.imageValue = Me.imageValue
c.imageSize = Me.imageSize_Renamed
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_Renamed = value.Size

If Me.InheritedStyle IsNot Nothing Then
Dim inheritedPadding As Padding = Me.InheritedStyle.Padding
Me.DefaultCellStyle.Padding = New Padding(imageSize_Renamed.Width,
inheritedPadding.Top, inheritedPadding.Right, inheritedPadding.Bottom)
End If
End If
End Set
End Property
Private ReadOnly Property TextAndImageCellTemplate() As TextAndImageCell
Get
Return TryCast(Me.CellTemplate, TextAndImageCell)
End Get
End Property
Friend ReadOnly Property ImageSize() As Size
Get
Return imageSize_Renamed
End Get
End Property
End Class

Public Class TextAndImageCell
Inherits DataGridViewTextBoxCell
Private imageValue As Image
Private imageSize As Size

Public Overrides Function Clone() As Object
Dim c As TextAndImageCell = TryCast(MyBase.Clone(), TextAndImageCell)
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.OwningTextAndImageColumn Is
Nothing Then

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

Dim inheritedPadding As Padding = Me.InheritedStyle.Padding
Me.Style.Padding = New Padding(imageSize.Width, inheritedPadding.Top,
inheritedPadding.Right, inheritedPadding.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 DataGridViewElementStates, ByVal value As Object, ByVal
formattedValue As Object, ByVal errorText As String, ByVal cellStyle As
DataGridViewCellStyle, ByVal advancedBorderStyle As
DataGridViewAdvancedBorderStyle, ByVal paintParts As DataGridViewPaintParts)
' Paint the base content
MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)

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

graphics.SetClip(cellBounds)
graphics.DrawImageUnscaled(Me.Image, cellBounds.Location)

graphics.EndContainer(container)
End If
End Sub

Private ReadOnly Property OwningTextAndImageColumn() As TextAndImageColumn
Get
Return TryCast(Me.OwningColumn, TextAndImageColumn)
End Get
End Property
End Class

--
http://www.tangiblesoftwaresolutions.com
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 TextAndImageColumn:DataGridViewTextBoxColumn
{
private Image imageValue;
private Size imageSize;

public TextAndImageColumn()
{
this.CellTemplate = new TextAndImageCell();
}

public override object Clone()
{
TextAndImageColumn c = base.Clone() as TextAndImageColumn;
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.InheritedStyle != null) {
Padding inheritedPadding =
this.InheritedStyle.Padding;
this.DefaultCellStyle.Padding = new
Padding(imageSize.Width,
inheritedPadding.Top, inheritedPadding.Right,
inheritedPadding.Bottom);
}
}
}
}
private TextAndImageCell TextAndImageCellTemplate
{
get { return this.CellTemplate as TextAndImageCell; }
}
internal Size ImageSize
{
get { return imageSize; }
}
}

public class TextAndImageCell : DataGridViewTextBoxCell
{
private Image imageValue;
private Size imageSize;

public override object Clone()
{
TextAndImageCell c = base.Clone() as TextAndImageCell;
c.imageValue= this.imageValue;
c.imageSize = this.imageSize;
return c;
}

public Image Image
{
get {
if (this.OwningColumn == null ||
this.OwningTextAndImageColumn == null) {

return imageValue;
}
else if (this.imageValue != null) {
return this.imageValue;
}
else {
return this.OwningTextAndImageColumn.Image;
}
}
set {
if (this.imageValue != value) {
this.imageValue = value;
this.imageSize = value.Size;

Padding inheritedPadding = this.InheritedStyle.Padding;
this.Style.Padding = new Padding(imageSize.Width,
inheritedPadding.Top, inheritedPadding.Right,
inheritedPadding.Bottom);
}
}
}
protected override void Paint(Graphics graphics, Rectangle
clipBounds,
Rectangle cellBounds, int rowIndex, DataGridViewElementStates
cellState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
// Paint the base content
base.Paint(graphics, clipBounds, cellBounds, rowIndex,
cellState,
value, formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);

if (this.Image != null) {
// Draw the image clipped to the cell.
System.Drawing.Drawing2D.GraphicsContainer container =
graphics.BeginContainer();

graphics.SetClip(cellBounds);
graphics.DrawImageUnscaled(this.Image, cellBounds.Location);

graphics.EndContainer(container);
}
}

private TextAndImageColumn OwningTextAndImageColumn
{
get { return this.OwningColumn as TextAndImageColumn; }
}
}
Aug 15 '08 #4
On Aug 15, 11:58 am, "\(O\)enone" <oen...@nowhere.comwrote:
EricW wrote:
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.

The code you provided is in C#, not C.

You can use the following service to translate the code to VB.NET:

http://labs.developerfusion.co.uk/co...arp-to-vb.aspx

HTH,

--

(O)enone
That's one of my favourite (labs.developerfusion.co.uk), but i don't
rely on online converters so much when some compile-time error happens
due to obsolete methods and framework differences etc.. Try to use
less code when converting these online tools, then continue as long as
current conversion is fine so far. Just my opinion.

Onur Güzel
Aug 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dick Zeeman | last post by:
Hi, I have a problem regarding the perfomance of a stp in combination with character translation. The following happens. We have an automated installation script (nt command file) for...
2
by: John Carson | last post by:
One routinely hears that the order of initialisation of objects with static storage duration in different translation units cannot in general be guaranteed. I have a question about one way to...
7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
4
by: Chris Croughton | last post by:
Does a translation unit have to have at least one externally visible declaration or function definition to be valid? As I read the standard, it doesn't: it must have at least one declaration or...
4
by: Tomás Ó hÉilidhe | last post by:
I have a translation unit which defines a global object: BEGIN "yellow.c" int i = 7; END I want this object to be accessible from other translation units, so I give it external linkage....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.