vb event in c#?

G

Guest

i'm trying to convert some code from VB to C#, i know i can use both in .net,
but we know C# better and want to be able to change some things around for
our own needs. i have all of it converted except for the "public event..."
of the following code. is there anyone that can help me convert this to C#
please?

thank you in advance,

Public Class ColumnInformation
Private m_Field As String
Private m_Width As Single
Private m_HeaderText As String
Private m_HeaderFont As Font
Private m_DetailFont As Font
Private m_Alignment As StringAlignment

Public Event FormatColumn(ByVal sender As Object, ByRef e As
FormatColumnEventArgs)

Public Function GetString(ByVal Value As Object)
Dim e As New FormatColumnEventArgs()
e.OriginalValue = Value
If Not IsDBNull(Value) Then
e.StringValue = CStr(Value)
Else
e.StringValue = "<NULL>"
End If

RaiseEvent FormatColumn(CObj(Me), e)
Return e.StringValue
End Function

Public Sub New(ByVal Field As String, _
ByVal Width As Single, _
ByVal Alignment As StringAlignment)
m_Field = Field
m_Width = Width
m_Alignment = Alignment
End Sub

Public Property Field() As String
Get
Return m_Field
End Get
Set(ByVal Value As String)
m_Field = Value
End Set
End Property

Public Property Width() As Single
Get
Return m_Width
End Get
Set(ByVal Value As Single)
m_Width = Value
End Set
End Property

Public Property Alignment() As StringAlignment
Get
Return m_Alignment
End Get
Set(ByVal Value As StringAlignment)
m_Alignment = Value
End Set
End Property

Public Property HeaderFont() As Font
Get
Return m_HeaderFont
End Get
Set(ByVal Value As Font)
m_HeaderFont = Value
End Set
End Property

Public Property HeaderText() As String
Get
Return m_HeaderText
End Get
Set(ByVal Value As String)
m_HeaderText = Value
End Set
End Property

Public Property DetailFont() As Font
Get
Return m_DetailFont
End Get
Set(ByVal Value As Font)
m_DetailFont = Value
End Set
End Property
End Class
 
G

Guest

Hi Oscar,
Public Event FormatColumn(ByVal sender As Object, ByRef e As
FormatColumnEventArgs)

in c#

public delegate void FormatColumnEventHandler(object sender, ref
FormatColumnsEventArgs e)

public event FormatColumnEventHandler FormatColumn


Roland
 
G

Guest

thanx for the help, that's what i needed, but now i have a new questions...

in order to call the event handler from another function the VB code looks
like :

Dim orderID As New ColumnInformation("OrderID", 1,
StringAlignment.Near)
Dim orderDate As New ColumnInformation("OrderDate", 1,
StringAlignment.Center)
AddHandler orderDate.FormatColumn, AddressOf FormatDateColumn


i thought it should look like the following, but i can not seem to put the
right information into the EventHandler.
ColumnInformation orderID = new ColumnInformation("OrderID", 1,
StringAlignment.Near);
ColumnInformation orderDate = new ColumnInformation("OrderDate", 1,
StringAlignment.Center);
orderDate.FormatColumn += new EventHandler(FormatDateColumn);

i also tried using :
orderDate.FormatColumn += new FormatColumnEventHandler(FormateDateColumn);

but that told me it doesn't exist

thanks again for the help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top