|
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
|
|
|
|
|
I've created a DataGridViewComboBoxColumn named "cbx". Added 0->"male",1->"female" to it's items;
I've added the "cbx" to my GridView as "sexA" column and for each row I "sexA".value = "sex".value;
i used this line:
gridview.Rows[0].Cells["sexA"].value = gridview.Rows[0].Cells["sex"].value;
Just as a remainder, "sex" is int type and also the "cbx" value is int type.
thought the results should be to show the displaymember on "sexA" by the value of "sex" it doesn't show anything on "sexA". Although later on I can edit and select a new value to "sexA" but can't do that using code!
it's seems like it doesn't update the gridview.
I tried GridView.Refresh().
Any ideas?
tnx
|
|
|
|
|
Iam making a calculator and have this aproximation errors, when I use the Pi constant and make Sin(pi) the answers I got is 3,23108510433268E-15 when it should be zero. ¿Someone knows how to fix this?
|
|
|
|
|
Hi,
floating-point numbers and calculations have a finite precision, and they must balance between speed and accuracy. Transcendental numbers such as pi cannot be represented exactly. And the result of floating-point operations can also depend on the hardware used. I am getting 1.2E-16 for
double x=Math.PI;
double y=Math.Sin(x);
output("sin(pi)="+y);
on an Intel T8300.
If you are not satisfied by some function, you can try and improve it by:
- using a smaller range of it
- replacing it completely.
For periodic functions, reducing the range is the obvious first attempt;
you could rely on identities such as sin(pi-x)=sin(x) and sin(pi/2-x)=cos(x) to reduce all values of x to the interval [0, pi/4] for which one could hope the Math class gives the most accurate results.
|
|
|
|
|
As Luc said, floating point is not exact due to computers storing numbers in binary. You do realize that 3,23108510433268E-15 is pretty darn close to zero, right?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|