473,499 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net to c# conversion help please

Hi everyone, i have a vb.net program ive converted most of the code but
i know events dont translate well, the original vb.net code uses
withevents and .handles and i can't get the events in c# to work 100%
they seem to hook up ok but when the eventhandler is called from the
method its null and fails.
or maybe im reading it wrong?
public abstract class Page : IDisposable
{
protected ListControl mainList;
public virtual void DisplayPage(ref frmMain myForm)
{
this.mainList.LeaveControl += new
dmControls.ListControl.LeaveControlEventHandler(ma inList_LeaveControl);

this.mainList.Selected += new
dmControls.ListControl.SelectedEventHandler(mainLi st_Selected);
this.mainList.SelectionChanged += new
dmControls.ListControl.SelectionChangedEventHandle r(mainList_SelectionChang***ed);


}
protected delegate void
MainListLeaveControlEventHandler(dmControls.Direct ion direction);
private MainListLeaveControlEventHandler MainListLeaveControlEvent;
protected event MainListLeaveControlEventHandler MainListLeaveControl
{
add { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate. Combine(MainListLeaveCont***rolEvent,
value); }
remove { MainListLeaveControlEvent =
(MainListLeaveControlEventHandler)System.Delegate. Remove(MainListLeaveContr***olEvent,

value); }

}
protected delegate void MainListSelectedEventHandler(string sSelected,
object Data);
protected MainListSelectedEventHandler MainListSelectedEvent;
protected event MainListSelectedEventHandler MainListSelected
{
add { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Comb ine(MainListSelectedEvent***,
value); }
remove { MainListSelectedEvent =
(MainListSelectedEventHandler)System.Delegate.Remo ve(MainListSelectedEvent,

value); }

}
protected delegate void MainListSelectionChangedEventHandler(string
sSelected, object Item);
private MainListSelectionChangedEventHandler
MainListSelectionChangedEvent;
protected event MainListSelectionChangedEventHandler
MainListSelectionChanged
{
add { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Deleg ate.Combine(MainListSelec***tionChangedEvent,
value); }
remove { MainListSelectionChangedEvent =
(MainListSelectionChangedEventHandler)System.Deleg ate.Remove(MainListSelect***ionChangedEvent,

value); }

}
private void mainList_LeaveControl(Direction direction)
{
..........................
}
private void mainList_Selected(string sSelected, object Data)
{
if (MainListSelectedEvent != null)
MainListSelectedEvent(sSelected, Data);
}
}
DisplayPage is then overridden and called from different type of pages
that inherit from page.

its the MainListSelectedEvent thats null when i try and call it.
any help really appreciated!
thanks.
bryan

Mar 16 '06 #1
1 1011
<ht*******@hotmail.com> wrote:
Hi everyone, i have a vb.net program ive converted most of the code but

i know events dont translate well, the original vb.net code uses
withevents and .handles and i can't get the events in c# to work 100%


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(The code you posted is neither short, nor complete.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 16 '06 #2

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

Similar topics

8
1978
by: weasel | last post by:
Why is the Farenheit to Celsius part not working properly? Instead of showing a similar range of what the farenheit is listing, the celsius portion is showing half the range of farenheit. print...
30
4985
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
31
6575
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
4
6465
by: Nikhil Patel | last post by:
Hi all, I am a VB6 programmer and learning C#. I am currently reading a chapter on types. I have question regarding enums. Why do we need to convert enum members to the value that they represent?...
11
7589
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
8
4324
by: Duncan Winn | last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that requires an LPTSTR. I have defined this as a: char * data_name; I am then trying to convert this to an LPOLESTR and I...
11
2678
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h>...
3
4595
by: utab | last post by:
Dear all, I was trying to write a more complex program, and while searching for sth in my reference C++ primer, by Lippman. I had a question in the mind, see the code below #include <string>...
1
4276
by: v4vijayakumar | last post by:
Can "c++ conversion operator" be considered as an example for Prototype design pattern? Following example explains, C++ conversion operator. #include <iostream> #include <string> using...
6
2615
by: Rahul | last post by:
Hi Everyone, I have the following code, class B; class A { public : operator B();
0
7007
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
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
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
5468
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,...
1
4918
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...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.