|
Well, for the simple one line of text in a file you won't need to parse anything. You can simply do just the opposite of what I have above. Check if the file exists but don't delete it. Instead of using File.CreateText you will use File.OpenText. Instead of using System.IO.TextWriter use a System.IO.TextReader. Instead of using WriteLine() use ReadLine(). It's all pretty simple. However, if you're putting multiple lines in the file for multiple objects/properties it does get a little more complex. A more simple way to do this would be to just serialize the label (or whatever other oject you have) into a file and deserialize it back from the file to an object in the code whenever you need it. A good example exists right here on code project:
http://www.codeproject.com/csharp/objserial.asp[^]
|
|
|
|
|
Hi
Is it possible to set values to a property of a structure in the structure's constructor. For eg.
<br />
struct MyStruct<br />
{<br />
int fieldx;<br />
public int Propertyx<br />
{<br />
get { return fieldx; }<br />
set { fieldx = value; }<br />
}<br />
public MyStruct(int i)<br />
{ Propertyx = i; }<br />
}<br /> This is not compiling whats wrong and why ? But i am able to directly assign the value to the field.
Regards
Deepak
-- modified at 12:26 Tuesday 11th October, 2005
|
|
|
|
|
Try this:
<code>
struct MyStruct
{
int fieldx;
public int Propertyx
{
get
{
return fieldx;
}
set
{
fieldx = value;
}
}
public MyStruct(int i)
{
fieldx = i;
}
}
</code>
|
|
|
|
|
He did say that he was able to assign directly to the field. He just wanted to know why he couldn't assign to the property.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Ahhh.. I read right over that... Well, you can assign the property as long as you assign the field also. When building a struct constructor, the constructor must not exit until all fields have been assigned. Of course, you're thinking to yourself, "It does get assigned when the property is assigned"... unfortunately the compiler doesn't see that
|
|
|
|
|
Right. And that's how I answered him.
I can see the logic behind the compiler not looking through the property to see that the field gets initialized. For instance, what if your property setter utilized another field in the struct that hadn't been initialized yet? If you just make it a hard and fast rule of structs that they must have all their fields initialized before you use any of them, then it simplifies the work that the compiler has to do.
There's always reference types.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Yessir
|
|
|
|
|
It looks like, from reading the specification, you're not allowed to utilize any instance members of the type until after it's been fully initialized (viz. all of its consituent fields have been initialized). And since Propertyx is an instance member and fieldx hasn't been set yet, you can't use Propertyx. I could be wrong through. Try setting fieldx and then using Propertyx...see what that gives you.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
How can we set the values on the cells for the new row before the RowAdded event gets fired.
For eg if a DataTable has 5 rows, then at this point the CurrencyManager shows a count of 6.
So how can I get a reference of the DataRow that will be added to the DataTable when the currencyManager.EndEdit() gets called.
|
|
|
|
|
I figured it out.
currencyManager.Current is the one I was looking for.
|
|
|
|
|
I want to draw a dashed line
If I call g.DrawLine(....
Is there a way to get the dashes to all be equal length? In other words, sometimes I will draw a line and it will have say, 20.5 dashes instead of
a complete integer number of dashes?
ps- I would like to see code or pseudocode not -- "oh, just use line caps..."
That tells me nothing...
Thanks very much....
|
|
|
|
|
I'm a little confused... doesn't g.DrawLine take x1, y1, x2, y2?? These coordinates allow you to draw lines to any size you're trying?? What are you having troubles with?
|
|
|
|
|
Thanks. My problem is when I want to draw a dashed line. What sometimes happens (depending on the length of the line) is that the last dash is cutoff.
So a line has x number of dashes, but then only part of a dash for the last one. It doesn't look very professional....
|
|
|
|
|
I'm using VS.NET 2005 Beta 2 and SQL Server 2005 Express to store personal information. The problem i'm facing is the MinDate value of a DateTimePicker cannot be set to below '1/1/2296'. My regional setting on my pc is set to Thailand (Thai year system is +543 from formal year format e.g. year 2005 in formal format is 2548 in Thai format). Also my SQL Server Collation is set to Thai. When i add a date info into the database via my app, it always adds 543 to the year value from DateTimePicker (2548 --> 3091). So the value in the database will always be 543 years over. Could anyone please help me out on this issue?
KiT
|
|
|
|
|
One quick and easy way (cheating a bit) to fix this is to simple subtract 543 years from the final date BEFORE you enter it into SQL
|
|
|
|
|
I've tried that before but it didn't work. It seems like it adds 543 just before storing into the db. But when processing, it uses the displayed value. For example, if i try to store a year of 2520, it store 1977. But if i try -543, it says "Out of Range". What a headache... Don't know how to fix it.
KiT
|
|
|
|
|
Unfortunately I don't know of a fix, perhaps though you can band-aid it on the other side? When you retrieve the data back out, add 543 to it.
|
|
|
|
|
Hi,
is there a simple way to scroll the image that is larger than the screen size in a simple way?please help
Best regards,
E.A.
|
|
|
|
|
Do you mean scrolling a PictureBox?
Read this ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemWindowsFormsScrollBarClassTopic.htm
Basically you attach a ScrollBar component to the picturebox.
In the link there is a full sample.
Eduardo Diaz
site | english blog | spanish blog
|
|
|
|
|
Hi
I have a number of options which i want to when clicked open up a panel below with another dropdown list relating to the origional choice. Each option from the first drop down list would open a new panel with a new dropdown list and remove the previous.
Any ideas how to code something like this, im guessing its easier than I am trying to work it out! This is for c# asp.net
Thanks
Adam
|
|
|
|
|
If you're trying to make a static form that doesn't change then what you're doing is easy as pie:
Create your form with all of the drop downs in their own seperate "Panel" controls. (Use a Table for the proper line ups of drop downs). Then simply change the Visible property of all of the drop downs to false (except for the original one). Now make sure the "AutoPostBack" is set to true on the first dropdownlist. Then in the "OnSelectionChanged" (or something like that) event, simple check the value of the new dropdownlist selected item and make the corresponding panel control visible according to the selection.
Now if you're using BOUND data, this is all a different story that I'm not going to type up unless this is the case
|
|
|
|
|
Thanks for the quick reply.
The options in the drop downs are manually put in, not taken from a database due to them maybe changing quite regularly. However there may be 3 options selected which will cause a other funtion to run, but i think i know how to get round that one.....
I have the panels ready etc, the first drop down needs to be a required option which i dont have a problem with, but its where i need to add the other code im having the problem with?
Thanks
Adam
|
|
|
|
|
By "the other code" I assume you mean the code to make the other panels visible?
If so:
In the GUI, select the main dropdownlist. In the "events" section of the properties list doulbe click the empty space to the right of the event: "SelectedIndexChanged"
You code will go in here. If you'll paste the code you currently have, I can show you what I mean.
Or hit me up on MSN @ xraheemx@hotmail.com
|
|
|
|
|
Unfotunatley we cant use msn at work So ill have to put it here. What ive got is the first part so that if it is anything but the initial value it will do the panel viewing:
private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (Speciality.SelectedItem.Value!="Select a speciality")
{
}
}
So as an example of the options:
Select a speciality
Option 1
Option 2
Option 3
Option 4
Option 5
Thanks again for your help.
Adam
|
|
|
|
|
OK, so lets say that the other dropdowns are named option1, option2, option3 etc. The following code will work for you:
<code>
private void Speciality_SelectedIndexChanged(object sender, System.EventArgs e)
{
select(Speciality.SelectedItem.Value.ToLower())
{
case "option 1":
option1.Visible = true;
break;
case "option 2":
option2.Visible = true;
break;
case "option 3":
option3.Visible = true;
break;
case "option 4":
option4.Visible = true;
break;
case "option 5":
option5.Visible = true;
break;
default:
break;
}
}
</code>
|
|
|
|