I am developing desktop application.Front end:Visual studio 2010.
Is it possible to change the color(foreground & background) of only selected item in the ListBox?
is this possible with mousehover event?
Please suggest the better solution
I've a question about xmlSerializer in C#,
My question is how can you create an xmlfile with the xmlserializer from two or more different objects without creating a class contains all those objects.
For example this is the xml file wanted:
<?xmlversion="1.0"encoding="UTF-8"?><Root><Books><Book><Title>X</Title><Author>Mr x</Author></Book></Books><Movies><Movie> Movie Y</Movie></Movies></Root>
At the moment I'll do this with the XDocument class and create for each property an Xelement.
For example I create an XElement books which contains child elements and add them all to an XDocument and save this XDocument object.
public XElement getBooksElement(List<Book> books)
XElement ret = new XElement("Books");
foreach(Book b in books)
public XElement getBookElement(Book book)
XElement ret = new XElement("Book");
ret.Add(new XElement("Title", b.Title));
ret.Add(new XElement("Author", b.Author));
How can be this achieved without creating a class containing all elements which should be in the object but serialize each object to an xml part and add those to the xml file.
I hope my question is clear enough,
Thank you in advance.
So you want to serialize each object individually, without creating a container class to hold all the objects? How about if you serialize each object to a MemoryStream, then create an XElement or XDocument to contain them all, and stick all the data you saved into the MemoryStreams inside it?
Yes that's sounds like a good idea but how do I create a XElement or XDocument out of the memorystream, and how can I manage the deserialization of this? Because should I read the XDocument and divide this XDocument in multie memorystream for dividing this up?
You can use the XDocument.Load static method to create an XDocument from the stream. (You might need to call Seek on the stream to reset it to the beginning!) As for creating multiple MemoryStreams to load the XDocument's elements, you can do this:
foreach (var element in myXDocument.Elements()) // might need to get the elements of the root element, instead of the document itself, I'm not sure
var ms = new MemoryStream(Encoding.Unicode.GetBytes(element.ToString()));
// do your deserialization here from the memory stream
I don't really have a big issue with the powershell working because it works just fine.
The problem I'm having is the method exits before the command is actually completed on the Exchange server. I think it may have something to do with the way Exchange throttles powershell commands.
Is there a way to use powershell with Exchange but have it completely wait until the command is finish before refreshing my page?
Let me give you an example:
A user logs into the web interface and decides to enable their user for Exchange. So the user clicks Enable Exchange. This fires a powershell to Exchange running the Enable-Mailbox command. After it completes the command it retrieves updated information from Active Directory / Exchange about the users mailbox.
The problem I have is when it tries to retrieve the updated information it hasn't had time to populate in Exchange so it still thinks there isn't a mailbox. I know I could put a sleep in there but I rather do something cleaner.
I am working on a c# app that talks to an external device via a comm port.
The external device comes with a header file that defines the commands that can be sent and the possible return values, all as #define's.
Is there a way to get thease #define's in to my c# app, other than copying and pasting?
“If I had asked people what they wanted, they would have said faster horses.”
― Henry Ford
What's a crock is that in the original C/C++ files, the original programmer made the mistake of depending on a compiler-specific feature to write code.
I know full well that everyone used to use #define to declare their constants in C/C++, even when they had a perfectly good "const" keyword, but in doing so, the made the code specific to the C/C++ compiler.
Sorry, but don't blame C# for the failings of some other programmer in a previoud language.
Well... the quick and dirty way would be to pass it through a C pre-processor. However, you may want to limit the scope of what you do that way.
Without seeing what's actually in the header file and which parts you need, I'll show a simple example of what can be done:
# define OPEN 1
# define CLOSE 2
# define READ 3
# define WRITE 4
Example.csi (choose an extension)
public static class Command
public const int Open = OPEN ;
public const int Close = CLOSE ;
public const int Read = READ ;
public const int Write = WRITE ;
public enum Command
Open = OPEN
Close = CLOSE
Read = READ
Write = WRITE
Pass them through a C pre-processor, this uses the Visual C/C++ one: cl /nologo /C /EP /P /FIC:Example.h /FiExample.cs Example.csi
public static class Command
public const int Open = 1 ;
public const int Close = 2 ;
public const int Read = 3 ;
public const int Write = 4 ;
public enum Command
Open = 1
Close = 2
Read = 3
Write = 4
You can then include this file in your project. If needed, you can have a pre-build step that performs the above pre-processing.
0) The pre-C# file (csi) should not contain any directives
1) You should include a notice that it was generated
2) You could also set the file to read-only
3) Use a partial class if you want this to be part of a larger class so you don't pass the whole thing through the pre-processor
I am currently creating a media player but as I am searching online for some help, no one seems to be able to provide the information. I am trying to have a media player which I find easy to build to have it playing videos but what I am having the issue with is creating a file on the computer and having files like mp3 which are stored there be automatically put into a library on the media player which then can be played. I want it so that the files in a folder will be automatically stored onto the media player which then I can search for on the application for the file name and click to play it. Please can people be specific because people can be very vague and state the obvious and then leave it at that. What will I need to create e.g. access database ?, and what will I need to do for it like create a class coding to list in a drop down box etc.
If anyone can help I will be highly greatful.
What will I need to create e.g. access database ?, and what will I need to do for it like create a class coding to list in a drop down box etc.
There seems to be some discrepancy between your statement and your question. Rather than trying to decide whether to use a dropdown or not, you need to think in more abstract terms about the design of your application. For example, what problem do you think will be solved by an Access database or by a dropdown box?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
Coming from a C++ background, I'm keen to learn the C# idiom. Picking up the language is simple enough, and I'm finding my way around the class library, but I'm not familiar with the idiom, or "how things are done".
I would like the code I write to follow the conventions well enough that an experienced C# developer reading the code can see what's going on without getting confused about alien idioms.
(One example I've noticed is the use of foreach rather than for loops over collections.)
Now, I have a document class for a desktop application, and I'd write its IO interface like this:
// Default constructor (eg File->New)public Document()
// Construct by reading from file (eg File->Open)public Document(string path)
// Write document to path it opened from (eg File->Save, after opened or saved once)publicvoid Write()
// Write document to new path (eg File->Save As, of first File->Save after default construction)publicvoid Write(string path)
I don't think this is idiomatic C# though. Most examples seem to pass in streams instead of path names, for instance, and handle that aspect (eg opening and closing IO streams) outside the document class, in the application. Is that correct? Should I write a separate serializer?
Please let me know what the "proper" C# way of doing things like this is.
Last Visit: 21-Sep-20 14:56 Last Update: 21-Sep-20 14:56