|
using System;
class Circle
{
public int X
{
get
{
return(x);
}
set
{
x = value;
// draw the object here.
}
}
int x;
}
class Test
{
public static void Main()
{
Circle c = new Circle();
c.X = 35;
}
}
In this code, the get or set accessor is called when the property X is referenced.
Vikas Amin
EATON
PUNE
|
|
|
|
|
But whatis better using get & set or using getName();??
Dios creo un equipo perfecto a los demas los lleno de extranjeros
|
|
|
|
|
You don't have to type () with properties :P
|
|
|
|
|
|
I am using Visual Studio 2003 and C# to develop a textbox user control. In the Properties Window of the Visual Studio Editor I have a few of the public properties that the developer can select to change how the user control is going to behave and/or look. Is it possible to have some properties not available on the Properties Window until the developer has selected a value? For example the background color. If I use an enumerator to give the following values for the background color: Default, Custom
In the properties window I would like the developer to be able to choose a color if he has chosen the Custom option, but not if he has chosen the Default option.
All help will be appreciated.
Thanks
Kobus
|
|
|
|
|
Dear Respected Programmers
I need some help, Kindly convert the following code into C# which is written in VB6. because whenever I try to use said method in C# it does not work.
Thank you in Advance
Private Sub Form_Load()
Dim frmViewer As New Form2
Dim ReportObject As New CrystalReport1
objRecordSet.Open ("Select * from EMP"), objConnection, adOpenStatic, adLockReadOnly
ReportObject.Database.SetDataSource objRecordSet, 3
frmViewer.CRViewer1.ReportSource = ReportObject
frmViewer.CRViewer1.ViewReport
frmViewer.Show
End Sub
|
|
|
|
|
I am trying to understand how to hook up some event handlers. Here is an analogy to my situation: I have an object tree that represents all passenger trains in a train station. It looks like this:
<br />
Station<br />
.....Trains<br />
.........Train_0<br />
..............Cars<br />
................Car_0<br />
...................Passengers<br />
..........................Passenger_0 <br />
..........................Passenger_1<br />
.........Train_1 <br />
..............etc...<br />
Each of these objects fire events (like when passengers board a car).
I have a Form where I want to display status of Trains, Cars, Passengers etc.
I need to attach the handlers in the Form, but must be done dynamically, and I have no clue.
For testing I tried this, but I get a runtime error if the collections are empty:
<br />
Station.Trains[1].Cars[5].CarsChanged += new CarsChangedEventHandler(Cars_Changed);<br />
I have spent a good bit of time searching for info. Any suggestions would most helpful. I'm guessing that C# has an elegant solution (in lieu of my duck tape).
Thanks in advance-
|
|
|
|
|
Of course you get an error when the collection is empty, but that has nothing to do with event handlers.
You're trying to access Car number 5 when there is no Car number 5 in the collection if it's empty.
An event is usually bound to an instance of an object (there are static events, too, but they're far less common) and unless you have the instance you can't assign event handlers to it.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hi
Well if you have a tree then you can enumarate it and hook up the event handlers:
Something like this:
<br />
foreach(Train train in this.trains)<br />
foreach(Car car in train.Cars)<br />
car.CarsChanged+=new CarsChangedEventHandler(Cars_Changed);<br />
if you are building the tree dynamically you can add the event handler on the fly for example
<br />
Car car=new Car();<br />
car.CarsChanged+=new CarsChangedEventHandler(Cars_Changed);<br />
this.SelectedTrain.AddCar(car);<br />
or
<br />
public Car AddNewCarToTrain(Train train)<br />
{<br />
Car car=new Car();<br />
train.Cars.Add(car);<br />
return car;<br />
}<br />
AddNewCarToTrain(this.selectedTrain).CarsChanged+=new CarsChangedEventHandler(Cars_Changed);<br />
Regards
|
|
|
|
|
Thanks.
I am building the tree dynamically. I knew there was a way to do this, but you made it very clear.
I think I can make that work.
Squeaker
|
|
|
|
|
Hi,
Try using a index property in your objects (like Tag property for labels). And then set the same event handler for all you Cars ojects (for example) and depending on the index you can do your work. In your event handler you have a sender object. You can use something like this:
<br />
private void Cars_Changed(object sender,EventArgs e)<br />
{<br />
int index = ((Cars)object).index;<br />
}<br />
Hope it helps
Do your best to be the best
|
|
|
|
|
This is what I wanted to do, but I need a little clarification.
It looks like you are saying that all Car objects can fire the same event, and the eventArgs will include an index so I will know which car raised the event.
If that is correct, then how do I declare the same event in each Car??
Thanks
Squeaker
|
|
|
|
|
Hi,
Try using this code:
<br />
private void Start()<br />
{<br />
Cars []myCars = new Cars[10];<br />
for (int i = 0 ; i < myCars.Length ; i++)<br />
{<br />
myCars[i].Index = i;<br />
myCars[i].Click += new EventHandler(Cars_Click);<br />
}<br />
}<br />
<br />
private void Cars_Click(object sender,EventArgs e)<br />
{<br />
int index = ((Cars)sender).Index;<br />
}<br />
Hope this answers to your question
Do your best to be the best
|
|
|
|
|
Hi all,
I am creating a form and in which, the user should have an option to insert symbols in the text box. The symbols include Greek symbols, standard mathematical operators and others stuff. How could i make a user interface such that user selects a symbol from the pop-up window, so the selected symbol value should return into the text box.
Can anyone give me a link where i can find the related stuff or sample code to achieve this task. I googled enough but i did not find the exact stuff.....
|
|
|
|
|
how can i tell how many times axWebBrowser1_TitleChange will b called when im browsing to a site with axWebbroswer?
cause i want 2 retrive the title of the site... and some sites cause the event 2 occur different amounts of times...
or is there other simpler way 2 get the site Title without using axWebBrowser?
|
|
|
|
|
hi,
plz help me
i want some example programs on accessing the xml file in C#.Net2003
thanks for reading ,
GPK
|
|
|
|
|
u can use dataset to read ur xml file
DataSet ds = new DataSet();
ds.ReadXml("complete path of ur xml file");
by this way u will get xml file data in the form of table in dataset.
conditionaly u have defined the tags of ur xml file properly.
rahul
|
|
|
|
|
Hi,
If you want to load xml from an external file, just use the XmlDocument class Load method. Then you can use the XmlNode and all other classes to navigate through the xml content. You can get plenty of examples on msdn about this.
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
|
|
Hi,
The best way to access an XML file is to use XmlDocument. Something like:
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load("file.xml");<br />
XmlNodeList list = doc.DocumentElement.ChildNodes;<br />
foreach(XmlNode node in list)<br />
{<br />
string name = node.Name;<br />
string value = node.InnerText;<br />
bool hasChildNodes = node.HasChildNodes;<br />
}<br />
If an XmlNode has child nodes you can use ChildNodes property to obtain an XmlNodeList of these childs and so on...
Hope it helps
Do your best to be the best
|
|
|
|
|
Hi,
I thought that the following code would allow my application to accept Arabic input.
----
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-IQ");
}
catch (Exception ex)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
}
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
----
But it's not the case, I still see garbage when I enter Arabic text in a textbox. I want my application to behave like notepad does, i.e. just by changing the input language (the language selector in the taskbar), the proper text is displayed in a textbox, no matter the language selected (Arabic, Greek, etc.)
In the world of Visual Studio 6, the way I made this work was to change the character set of every control in my application (e.g. to display arabic, each control's font.charset would be set to 178). I thought C# in Visual Studio 2005 would be smarter and easier than that, am I wrong? What do I need to do?
Thanks.
|
|
|
|
|
Hi,
You do not necessarily have to change the current culture in order to support characters from different datasets. .NET deals with all characters internally as UNICODE (at least that is my understanding). What you do need to do however is ensure that the font you are using in your forms can handle those different characters.
For instance on my local machine the Arial font can display chinese characters, but Times New Roman cannot. If I set the forms font property to Arial I will see the correct chinese symbols, but as soon as I change the forms font property to Times New Roman or some other font that doesn't support the characters, they are displayed as little squares or question marks.
Good luck,
Sean.
|
|
|
|
|
It is a C# app and uses XmlSerialization.
My app gets users input in a html TextBox in a webapp. If user enters a text like "10 < 20" in the TextBox then because of HTML post back, the text is escaped to "10 < 20". So the codebehind receives "10 < 20" as the text from the TExtBox.
I have to futher send this text to a service so this value is set in a class like
class a
{
string userComments;
}
When this class is serialized to send the XML to the service "10 < 20" becomes "10 < 20".
So because of this situation "<" has been double escaped(escaped twice). How can I Avoid second escape during seriaization?
Manoj Gautam
-- modified at 12:29 Wednesday 30th August, 2006
|
|
|
|
|
Hi,
how do I supply my own taskbar toolbars (those like quicklaunch, the iTunes-Toolbar, etc.) in C#. I've already searched Google and some Coding-sites, but I can't find anything on that topic, only on Appbars (behaviour similar to the taskbar, but not integrated into taskbar) or on systray-icons (I already know how to do that, I need more space).
For those who do not exactly know what I mean: There was (and probably still is) a small program for ThinkPad-users which will display a small battery next to your systray which will show the status of your laptop-battery. That is more-or-less the direction into I want to go.
Thanks in advance...
Xperimental
|
|
|
|