|
Guffa wrote: public int Id { get; private set; }
Cool externally read only properties - learn something every day. Thanks
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hallo Guffa,
thank you for your reply.
Unfortunately there is a little problem with:
Guffa wrote: List axisLabelItems = new List();
I get following error for the "new List" (translated):
"The use of type "System.Collections.Generic.List<t>" (generic) makes the 1-type-argument necessary."
Any ideas?
By the way: To prevent the creation of the <br /> tags, I have to use just 1 line for the whole HTML section, because every \r\n in the textbox gets converted to the <br /> tag.
|
|
|
|
|
LightIceStorm wrote: Unfortunately there is a little problem with:
Guffa wrote:
List axisLabelItems = new List();
That's because of the backwards way that this forum handles html in the messages. Instead of encoding everything except the few html tags that makes sense to use, it allows any html code and tries to remove the most dangerous code...
I just forgot to encode some code. This is how it should look:
List<AxisLabel> axisLabelItems = new List<AxisLabel>();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello,
Actually I'm not sure if a Picture Box is the right control for my need, but I'm just guessing it is. I'm new to C#, so haven't got much of an idea. I'm using MS Visual C# 2005.
Here is my problem.
I read data from a file which contains text lines seperated by a return. Then according to the data lines, I need a verticle bar (deciding what this control is upto me, and I'm guessing it is a Picture Box) be filled with different colors.
For example let's say this is the text file.
A
B
C
A
Then, in the C# Form, on whatever that control I need four color lines be displayed according to the text. So, if we assign colors as follows:
A - Red
B - Yellow
C - Green
Then the color lines should be displayed like
Red
Yellow
Green
Red
I think you get the drift.
Please note that there could be any number of text lines in the text file, but the control height I use need to be remained the same. So, according to the number of lines in the text file, height of each color strip in the control should differ.
Please help me with this.
Thanks in advance.
|
|
|
|
|
The big issue that many people have is that they mistake the picture box for a lot of things that it isn't. Your best bet for what you want, is to draw the image yourself in your paint handler, then draw your lines, etc.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks for the reply mate.
Could you please show me how?
|
|
|
|
|
Just to give you an idea, you can create a custom control inherited from System.Windows.Forms.Control and hook to its Paint event, like this:
this.Paint += new PaintEventHandler(CustomComponent_Paint);
Then, draw your stuff in your PaintEventHandler:
void CustomComponent_Paint(object sender, PaintEventArgs e) {
Brush brush = new SolidBrush(Color.Red);
Pen pen = new Pen(brush);
Rectangle rect = new Rectangle(0,0,100,100);
e.Graphics.FillRectangle(brush, rect);
}
You can get the colors you need and create different color brushes for any of you cases
Regards,
Lev
|
|
|
|
|
I recently started looking into C# as I needed a solid language that can use windows COM for iTunes interactions. With C# 2008 I thought that XML would be a breeze, this is not the case. I am loading an xml file from the net and I simply want to retrieve one field(<tx>) from the document but I cannot find a simple way of doing this.
A sample xml document:
<start>
−
<sg>
<cs>dc583ca591</cs>
<id>532800</id>
<ar>Switchfoot</ar>
<tt>The Shadow Proves the Sunshine</tt>
<al>Nothing Is Sound</al>
−
<tx>
Sunshine,[br] free limited API lyricsfly.com temporary weekly access [br] won't she be my mother?[br]
Sunshine, come and help me sing[br]
My heart is darker than these oceans[br]
My heart is frozen underneath[br]
[br]
We are crooked souls trying to stay up straight[br]
Dry eyes in the pouring rain[br]
Where the shadow proves the sunshine[br]
The shadow proves the sunshine[br]
[br]
Two scared little run aways[br]
Hold fast till the break of daylight[br]
Where the shadow proves the sunshine[br]
The shadow proves the sunshine[br]
[br]
O Lord, why did you forsak... *** Your access it restricted to 30% of content. Please get permanent user ID key for 100% at lyricsfly.com/api/ *** [br] Lyrics delivered by lyricsfly.com [br]
</tx>
</sg>
</start>
The code that I have written so far:
String URLString = "http://lyricsfly.com/api/api.php?i=de5abbf415fd84ca6-temporary.API.access&a=" + track.Artist + "&t=" + track.Name;
XmlTextReader reader = new XmlTextReader(URLString);
Thanks in advance, Luke.
|
|
|
|
|
|
If you are using .NET 3.5 then I'd use the new System.Linq.Xml classes.
Also, you need to get the HTTP content - And you have to provide a safe way of generating the URL.
To generate your URL, use something like this as it will ensure that any characters in the Artist and Name properties are correctly encoded for use in a URL.
string url = string.Concat(
"http://lyricsfly.com/api/api.php?i=de5abbf415fd84ca6-temporary.API.access&a=",
HttpUtility.UrlEncode(track.Artist),
"&t=",
HttpUtility.UrlEncode(track.Name));
Now, to get the data you need to get it from the internet. To do this you need to do something like this:
string data;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
data = reader.ReadToEnd();
}
HttpWebRequest and HttpWebResponse are in System.Net namespace.
Now, to convert that data into an XML object graph you can use:
XElement doc = XElement.Parse(data);
From this point onwards you can use LINQ syntax to query the XML, or you can do it yourself.
For example, to get all the Songs (I presume that's what element "sg" is) you can do this:
IEnumerable<XElement> = doc.Elements("sg");
To get the lyrics of the first song, this should work:
string lyrics = doc.Element("sg").Element("tx").Value;
Does this help?
|
|
|
|
|
Yes, thank you so much. I could not find this anywhere.
|
|
|
|
|
I've been working on a project for quite awhile, and recently have noticed that when I run the project either in debug or release mode, one of the forms for the project changes the icon in the Solution Explorer to a component one, instead of the normal Windows Form Icon. Anyone have any ideas what line of code I should be looking for. The class declaration has the normal class Form1 : System.Windows.Forms.Form
--------------------
AC
in order to save the world, one must first save oneself.
|
|
|
|
|
kod3brkr wrote: one of the forms for the project changes the icon in the Solution Explorer to a component one, instead of the normal Windows Form Icon
You mean this just happens in Visual Studio and does not affect the look or functionality of your application? If so then it is probably a minor bug in Visual Studio and nothing to worry about.
|
|
|
|
|
Yeah it’s Visual Studio 2003 Educational version on Vista Home Premium. I don’t think it’s a bug because it doesn’t happen to any other project. I think there’s a line of code missing or added to that form’s .cs file. that form alone has over 5000 lines of code and the whole project is at least 20000 lines. so it’s a lot of searching to try to find the needle in this haystack. Thanks for your answer though.
--------------------
AC
in order to save the world, one must first save oneself.
|
|
|
|
|
kod3brkr wrote: I don’t think it’s a bug because it doesn’t happen to any other project
You never get intermittent bugs in your code then?
kod3brkr wrote: that form alone has over 5000 lines of code and the whole project is at least 20000 lines.
What you are describing is quite small - although 5000 lines in a code file sounds like it is badly in need of some refactoring.
When I was a C++ developer (For reference I used Visual Studio 2.1 to 6.0 in those days) I worked on a project where the project had over a million lines of code spread over hundreds (probably even thousands) files, the largest of which was several thousand lines long. And that was back in 1996 (12 years ago). Just wait until the real world hits you. Then you'll know what a big project is.
|
|
|
|
|
Yeah I work on a project at work that's millions of lines long, I'm merely suggesting that it won't be fun looking for the reason it's turning into a component all the time. It is a personal project and the client is waiting for the end result, I'd like to give them something that's secure enough to use without worrying about what's going on behind the scenes. I did some research and found out that a component form can be manipulated from other CLR languages. Something a hacker, or malicious programmer might want to have happen. let me know if you understand what's going on, and again thanks for answering.
--------------------
AC
in order to save the world, one must first save oneself.
|
|
|
|
|
kod3brkr wrote: I'm merely suggesting that it won't be fun looking for the reason it's turning into a component all the time
As I already said, is it affecting the way your application looks or functions? If not, quit worrying about it because it is just a minor bug in Visual Studio.
kod3brkr wrote: the client is waiting for the end result, I'd like to give them something that's secure enough to use without worrying about what's going on behind the scenes.
So, you have lots of unit tests to ensure the correct functioning of your application? If not, then how do you ensure the quality of your code?
kod3brkr wrote: let me know if you understand what's going on
Well, I understand that the compiler runs in a separate process that visual studio launches, so fretting about some minor display issue in VS (or which there are many more) is a bit pointless. It would be like fretting because Notepad didn't colour your source code if you loaded it in there.
|
|
|
|
|
Hi,
I guess this is not exactly what you want, but adding the following line just above the class statement turns a component into regular code, so double-clicking it in the solution pane opens up the code editor:
[System.ComponentModel.DesignerCategory("Code")]
Using some of it and google may bring you the solution.
|
|
|
|
|
Hi,
If can, Could you please tell me how?
Thanks!
Charith Jayasundara
|
|
|
|
|
You can't. Reflection tells you what is already there, it doesn't allow you to change the shape of the type.
|
|
|
|
|
You can however do that using Mono.Cecil opensource library, the trick is that cecil doesn't load the assembly into AppDomain, so you can make changes.
Here is a code snippet for example:
FieldDefinition field = new FieldDefinition("TestField", sometype, FieldAttributes.Private);
sometype.Fields.Add(field);
This adds a private field of type sometype to sometype.
Unfortunately there is no documentation for cecil, but you can ask questions in the Mono Cecil Google Group[^]
Regards,
Lev
|
|
|
|
|
"the trick is that cecil doesn't load the assembly into AppDomain"
How this will affect the other stuff?
Thanks!
Charith Jayasundara
|
|
|
|
|
What do you mean "other stuff"?
You can edit the assembly using cecil, save it, and then do whatever you want to do with reflection (unless you get charmed by cecil and want to switch to it )
Regards,
Lev
|
|
|
|
|
Hi,
I have dataset that is bound to a DataGridView. In my DataSet I have column "name" (string) and column "sex" (int). So far so good.
My problem is:
Now I need to convert "sex" to a comboBox type with values 0-> male, 1->female.
any ideas?
tnx
|
|
|
|
|
Hi,
If you want to do it the hard way, you could choose to set VirtualMode[^] to true. And use a DataGridViewComboBoxColumn[^]. However then you have to manage your datastore manually and all other related functions (including drawing the datagridview). This offers a great deal of flexibility, but is rather complex (though the msdn does give a very nice example).
You could also try to replace the column from the datagridview with a DataGridViewComboBoxColumn, but I don't know how to link the dataset to your column then.
Greets,
basambora
|
|
|
|