|
Hello Coders!
This is quite a general question, I’m just looking for a point in the right direction
Is there any way you can “view” an xml document on a C# Form? By this I mean each element shown on various controls and then a next and previous button to cycle through the XML Nodes?
i have tried various things with XMLDocument, XMLNode and XMLElement but have had no avail, and i was just wondering if there was a set way to do it. The XML file contains Portfolio items that have a name, description and an image link.
Thanks for any help
Kris
|
|
|
|
|
I don't know a lot about XML in C#, but since the XML file is encoded using ASCII you should be able to store the xml file in a string then filter it out. That probably doesn't help, but it might work.
-----
*** Never give me an answer having anything to do with Visual Studio. I don't have this because I have two computers, one being my dad's mac, which is connected to the internet, the other being my pc, which is, sadly, not connected to the internet. The setup for the Visual C# program I think is called a "bootstrap" program, and it needs to connect to the internet to install the program. THEREFORE I cannot install this program onto my pc.***
|
|
|
|
|
I am not very clear with your question. But it seems like you want to populate node values in controls. If i am correct then, you can use Xpath and it is pretty straightforward.
In case you need any source code please let me know...
Thanks
Amit
|
|
|
|
|
One option is to host IE as a control, it displays XML with +/- buttons for the parent nodes.
Otherwise, you need to write your own control, or search the web. The classes you mention are for iterating over XML, and they work just fine, they have nothing to do with displaying it, however.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Cheers for the replies guys!
Sorry, I think i was being a bit vague before. What I’m attempting to do is take an XML file that is structured like so:-
<portfolio>
<Item>
<Title>Title</Title>
<Description>Description</summaryDescription>
<Image>imageURL</Image>
</Item>
<Item>
<Title>Title</Title>
<Description>Description</summaryDescription>
<Image>imageURL</Image>
</Item>
...etc
</portfolio>
and displaying the info in separate controls...to the Title in a Textbox and the Image in an Image etc. Then, using 2 buttons, cycle through (left and right) through the items.
its getting the XML into the program I’m having difficulty with, what I want to do is load each Item into an object instance, then put those instances into an ArrayList or something. I’m very new to the .net framework and have tried different things but getting nowhere.
any further help would be fantasic
Thanks again
Kris
|
|
|
|
|
Okay, now that I am learned in the art of XML in C# , here's some code:
using System;<br />
using System.IO;<br />
using System.Xml;<br />
using System.Collections;<br />
<br />
class Run {<br />
static void Main() {<br />
XmlTextReader reader = new XmlTextReader("file.xml");<br />
<br />
ArrayList titles = new ArrayList();<br />
ArrayList descriptions = new ArrayList();<br />
ArrayList images = new ArrayList();<br />
<br />
reader.MoveToContent();<br />
while (reader.Read()) {<br />
if (reader.NodeType == XmlNodeType.Element) {<br />
switch (reader.Name) {<br />
case "Title":<br />
titles.Add(reader.ReadString());<br />
break;<br />
case "Description":<br />
descriptions.Add(reader.ReadString());<br />
break;<br />
case "Image":<br />
images.Add(reader.ReadString());<br />
break;<br />
}<br />
}<br />
}<br />
<br />
for (int a = 0; a < titles.Count; a++) {<br />
Console.WriteLine("-----" + titles[a] + "-----");<br />
Console.WriteLine(descriptions[a]);<br />
Console.WriteLine("Image: " + images[a]);<br />
Console.WriteLine();<br />
}<br />
}<br />
}
There 'ya go! This code gathers all the data and seperates it into ArrayList s, then writes them to the console. To do what you are speaking of, all you have to do is...
- Create your two textboxes, an imagebox (I think that's what it's called) and two buttons
- Create an index integer (e.g.
int index = 0; )
- For the
Click event of the next button, increase the index field by one and set the properties of the textboxes and imagebox to the data in the ArrayLists. (e.g. titleBox.Text = titles[index]; descriptionBox.Text = descriptions[index]; etc.)
- For the
Click event of the back button, do the same thing, except decrease the index field
- Don't forget - if index is greater than titles.Count, set index to zero, and if index < 0, set index to titles.Count
That should do it.
-----
*** Never give me an answer having anything to do with Visual Studio. I don't have this because I have two computers, one being my dad's mac, which is connected to the internet, the other being my pc, which is, sadly, not connected to the internet. The setup for the Visual C# program I think is called a "bootstrap" program, and it needs to connect to the internet to install the program. THEREFORE I cannot install this program onto my pc.***
|
|
|
|
|
Okay, here's the finished code:
using System;<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
using System.Xml;<br />
using System.Collections;<br />
<br />
class Run : Form {<br />
ArrayList titles;<br />
ArrayList descriptions;<br />
ArrayList images;<br />
int index;<br />
<br />
TextBox titleBox;<br />
TextBox descriptionBox;<br />
PictureBox imageBox;<br />
Button nextButton;<br />
Button prevButton;<br />
<br />
public Run() {<br />
XmlTextReader reader = new XmlTextReader("file.xml");<br />
<br />
index = 0;<br />
titles = new ArrayList();<br />
descriptions = new ArrayList();<br />
images = new ArrayList();<br />
<br />
reader.MoveToContent();<br />
while (reader.Read()) {<br />
if (reader.NodeType == XmlNodeType.Element) {<br />
switch (reader.Name) {<br />
case "Title":<br />
titles.Add(reader.ReadString());<br />
break;<br />
case "Description":<br />
descriptions.Add(reader.ReadString());<br />
break;<br />
case "Image":<br />
images.Add(reader.ReadString());<br />
break;<br />
}<br />
}<br />
}<br />
<br />
reader.Close();<br />
<br />
this.Size = new Size(520, 430);<br />
<br />
titleBox = new TextBox();<br />
titleBox.Text = (string)titles[index];<br />
titleBox.Location = new Point(5, 5);<br />
titleBox.Size = new Size(300, 25);<br />
this.Controls.Add(titleBox);<br />
<br />
descriptionBox = new TextBox();<br />
descriptionBox.Text = (string)descriptions[index];<br />
descriptionBox.Multiline = true;<br />
descriptionBox.Location = new Point(5, 50);<br />
descriptionBox.Size = new Size(300, 300);<br />
this.Controls.Add(descriptionBox);<br />
<br />
imageBox = new PictureBox();<br />
imageBox.Image = Image.FromFile((string)images[index]);<br />
imageBox.Location = new Point(310, 50);<br />
imageBox.Size = new Size(100, 100);<br />
this.Controls.Add(imageBox);<br />
<br />
prevButton = new Button();<br />
prevButton.Text = "<--";<br />
prevButton.Location = new Point(5, 350);<br />
prevButton.Click += new EventHandler(UpdateInfo);<br />
this.Controls.Add(prevButton);<br />
<br />
nextButton = new Button();<br />
nextButton.Text = "-->";<br />
nextButton.Location = new Point(90, 350);<br />
nextButton.Click += new EventHandler(UpdateInfo);<br />
this.Controls.Add(nextButton);<br />
}<br />
<br />
public void UpdateInfo(object sender, EventArgs e) {<br />
if (((Button)sender).Text == "-->") {<br />
index++;<br />
if (index >= titles.Count)<br />
index = 0;<br />
} else {<br />
index--;<br />
if (index < 0)<br />
index = titles.Count-1;<br />
}<br />
<br />
titleBox.Text = (string)titles[index];<br />
descriptionBox.Text = (string)descriptions[index];<br />
imageBox.Image = Image.FromFile((string)images[index]);<br />
}<br />
<br />
static void Main() {<br />
Application.EnableVisualStyles();<br />
Application.Run(new Run());<br />
}<br />
}
I tested it, and it works. Just change the name of the xml file to "file.xml".
-----
*** Never give me an answer having anything to do with Visual Studio. I don't have this because I have two computers, one being my dad's mac, which is connected to the internet, the other being my pc, which is, sadly, not connected to the internet. The setup for the Visual C# program I think is called a "bootstrap" program, and it needs to connect to the internet to install the program. THEREFORE I cannot install this program onto my pc.***
|
|
|
|
|
When you right click on an .exe and go to the Version tab (I think that's what it's called), There are several properties of the application that are visible; they are:
- File Version
- Description
- Copyright
- Assembly Version
- Internal Name
- Language
- Original File Name
- Product Version
Are there options in csc.exe that let you alter these? I couldn't find any when I did csc -? .
Oh yeah, one more thing; When I want to open a file with a program I just created, I right-click the file and press "Open With...". My program is shown in the dialog box that pops up, but all you see is its icon (the default icon) with no text to the right. How do I set the text that is supposed to be there?
-----
*** Never give me an answer having anything to do with Visual Studio. I don't have this because I have two computers, one being my dad's mac, which is connected to the internet, the other being my pc, which is, sadly, not connected to the internet. The setup for the Visual C# program I think is called a "bootstrap" program, and it needs to connect to the internet to install the program. THEREFORE I cannot install this program onto my pc.***
|
|
|
|
|
max29297 wrote: When you right click on an .exe and go to the Version tab (I think that's what it's called), There are several properties of the application that are visible; they are:
* File Version
* Description
* Copyright
* Assembly Version
* Internal Name
* Language
* Original File Name
* Product Version
You can change those values in your AssemblyInfo.cs (or .vb) file. If you look in your solution explorer, expand the "Properties" folder, you should find it there.
|
|
|
|
|
I don't think you read my sig Thanks though, I have some other people's AssemblyInfo.cs files from downloading projects from articles. I can figure it out from there
-----
*** Never give me an answer having anything to do with Visual Studio. I don't have this because I have two computers, one being my dad's mac, which is connected to the internet, the other being my pc, which is, sadly, not connected to the internet. The setup for the Visual C# program I think is called a "bootstrap" program, and it needs to connect to the internet to install the program. THEREFORE I cannot install this program onto my pc.***
|
|
|
|
|
Hi Max,
the AssemblyInfo.cs file gets generated automatically by Visual Studio, but
you can create your own, give it a different name, and/or merge it with other files.
Here is a typical example:
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("TrayIconBuster")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrayIconBuster")]
[assembly: AssemblyCopyright("Copyright © 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("fbd90b31-54df-4581-b476-c5fd53c9d279")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
|
|
|
Hi Max,
to add a file type with description, use Windows Explorer, Tools, Folder Options,
File Types, New, Advanced, and enter the required information.
BTW: you can add/remove/changeorder the fields shown in Windows Explorer through
View, Choose Details. Some of that info is fetched from the file itself, such as
"program version number" for an .EXE, or "date photo taken" for a .JPEG file (from
a camera that provides such info).
|
|
|
|
|
Hi
I have a problem. How can I get detailed info about sound from the microphone - the info like the 'jumping bars' in winamp, amplitude, etc. I want to make a voice recognition program using a neural net, but need info about the sound.
Thanks for help
|
|
|
|
|
Those 'jumping bars' are just examining the wav file for increases in amplitude.
I'm not sure exactly how you examine data as it comes in, but I'm sure the answer will involve DirectShow, which is in the platform SDK.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Joseph,
there are some articles on CodeProject (like this one[^]) that may interest you.
|
|
|
|
|
You can used the managed version of DirectSound[^] with C# to capture waveform input from your soundcard.
You will capture the sound by using buffers. Once you have a buffer of waveform data, you can examine the samples that make up the buffer to answer questions about waveform amplitude, etc.
|
|
|
|
|
I am trying to use the OWC11 to edit an Excel template. the code below creates a NEW file instead of just changing the cells. Does anyone know how to make it so that it edits a cell in a file instead of creating a new file? Also, how much memory does OWC11 use on the server?
private void EditSpreadSheet()
{
spread = new OWC.SpreadsheetClass();
spread.ActiveSheet.Cells[1,1] = "HELLO";
spread.get_Range("A2:A2",Type.Missing);
spread.Export(Server.MapPath(".") + "\\" + "PR.xls",OWC.SheetExportActionEnum.ssExportActionNone,
OWC.SheetExportFormat.ssExportHTML);
}
Sincerely,
The Major Rager
|
|
|
|
|
Don't start another thread for the same topic. Keep it in your original thread so there's the opportunity for multiple people to collaborate on an answer.
|
|
|
|
|
Hello everyone,
I was wondering if it is possible to change the Opacity of control elements in a Form. I am awear that I can change the opacity of the entire Form but can I change the opacity of the elements such as Button, ListView, DataGridView and many other control units?
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
I don't think that you can change individual components opacity unless they directly support it.
|
|
|
|
|
Nope. It's the form or you move your code to WPF.
|
|
|
|
|
Hi,
For convert the any image into sketch format (draw just the dark pixels),I use following logic:
for (int i = 0; i < 300; i++)
{
for (int j = 0; j < 200; j++)
{
p = new Pen(bitmap.GetPixel(i, j), 1);//get pixel from the image/bitmap
for (int r1 = 0; r1 < 100; r1++)
{
for (int r2 =0; r2 < 100; r2++)
{
for (int r3 = 0; r3 < 100; r3++)
{
if (p.Color ! = Color.FromArgb(255, r1, r2, r3)) //check dark pixel
{
p.Color = Color.Transparent;
}
g.DrawRectangle(p, 1 * i, 1 * j, 1, 1);
}
}
}
But it is too slow and not efficient ………Is above code require more betterment (if required then tell me what things are requried)or it is totally wrong?………second question is that Am I convert the color picture into the grayscale format by using the built-in function in Visual Studio C-Sharp .Net (if anyone function/class is present then tell me) -or- it need a algorithm and has a lengthy processes =>please give the some hints about the image processing.
Please send your logic for conversion of any image into sketch style.
Thanks…
|
|
|
|
|
Hi,
this is completely wrong in many ways:
1.
your code includes a lot of magical numbers (a width of 300, a height of 200) ?
Good code does not do that. Such numbers are either constants (declare constants then),
or they are variables that get their value somewhere (e.g. int width=bitmap.Width;).
2.
you are nesting five for loops; the inner loop would execute some
300*200*100*100*100 times, thats 60 billion times. How long do you expect this will take ?
Nesting that many loops seldom is the right way to achieve anything.
3.
what is the use of the for loops over r1/r2/r3 ?
you can replace them with:
int r1=p.Color.Red;
int r2=p.Color.Green;
int r3=p.Color.Blue;
and then check whether r1/r2/r3 are in the range [0,100).
Why search for something that you already know ???
4.
Graphics.DrawRectangle with a size of 1*1 is an expensive way to set one pixel.
Cant you use bitmap.SetPixel ?
5.
Why create a new pen for every pixel, you can use the same pen over and over.
6.
I dont think turning some pixels transparant is the right way to achieve
whatever it is you are trying to achieve.
Conclusion:
I strongly suggest you search CodeProjects for some articles on Graphics,
they are plenty and there are some pretty good ones. Then study those and learn
about realistic ways of doing things, before you start creating some weird code
of your own... Have a look at image filtering, edge enhancement, and many more.
And once you think you know what you need, try creating some quality code, and
organize it such that you can test it on much smaller images.
|
|
|
|
|
You should read my articles on image processing. It includes a greyscale filter ( although you can use the built in GDI+ stuff to do that )
Apart from that, I agree with everything Luc said, especially the bit about the nested loops, but this is all very much wrong.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|