|
If you don't want to bother with C-based printer enumeration callbacks (which happen to work differently depending on the operating system), I would suggest this fast hack :
- read this registry key : HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Control \ Print \ Printers
- the default printer is listed in : HKEY_CURRENT_USER \ Software \ Microsoft \ WindowsNT \ CurrentVersion \ Windows \ Device = "..." (on NT systems). And it's located in the [Device] section of the win.ini file (on 9X systems).
.NET provides API to access the registry and profile strings :
- Microsoft.Win32.Registry
- also check out Cp articles
|
|
|
|
|
Thanks..
I made it..
I appreciate your kindness...
However I found another way..
System.Drawing.Printing.PrinterSettings.InstalledPrinters
It shows currently installed printers.. Not using Registry..
|
|
|
|
|
bania wrote:
System.Drawing.Printing.PrinterSettings.InstalledPrinters
Ooo, nice to know
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hello,
I have few questions,
1. How to know whether scrollbars appeared in a list control at run time or not.
2. How to restrict user changing listview columns widths.
3. How to know whether a user has changed list view columns or not. How to keep track of changed list view columns.
4. How to know the names of all tcp and serial ports in a computer.
Chito
|
|
|
|
|
chito wrote:
1. How to know whether scrollbars appeared in a list control at run time or not.
You could figure out on your own how many items can appear in your list before the scroll bars apear and then in your App test if the amount of items has gone past the number you found. Of course this would only work if the listbox stayed the same size.
"We will thrive in the new environment, leaping across space and time, everywhere and nowhere, like air or radiation, redundant, self-replicating, and always evolving." -unspecified individual
|
|
|
|
|
1. .VScroll returns true of false
2. and 3. : also you are probably not going to like it, the only way I can think of is to override the WndProc method and provide a handler for the WM_NOTIFY message (HDN_TRACK notification). Lookup MSDN for more info about this WIN32 header control notification.
|
|
|
|
|
How would I go about encoding from a memory buffer to an mp3 file using the lame dll? Just want to feed the dll pcm data on the fly.
|
|
|
|
|
When I create a class library in C# it creates a DLL. The DLL it creates also references another DLL.
Is it possible to put the DLL I'm referencing INSIDE the DLL I created so I do not have to redistribute the referenced DLL ?
|
|
|
|
|
Only if you have the sources for the extra DLL or if said DLL is really a .NET Module (An Assembly without an Assembly Manifest) which isn't the case because you've been able to reference it. Anyway, what you could do is ILDASM the referenced DLL and ILASM the source file you get into a .NET Module, then use AL.exe to link the two.
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
There is various ways to do this. LIke said if you have the source , you can compile to a module and add that to an assembly, OR you can use the assemblyt linker (al.exe) and put everthing together.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Leppie...are you okay? That's what I just said. (I thought)
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
David Stone wrote:
That's what I just said. (I thought)
You must stop editing your messages
(I really cant remember that I saw it, my mistake)
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
You must stop editing your messages
I never edit messages...I always get them right the first time.
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
David Stone wrote:
I always get them right the first time
Stop fooling yourself No-one is perfect, except maybe 7of9
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Ok, I am back...
I have been working on a little tool for work that reads the reg, and then it will need to loop over an array and do some work. Well I can pull the string in and create the array:
RegistryKey regKey;
regKey = Registry.LocalMachine.CreateSubKey(@"Software\MyTestRegKey");
string[] valNames = regKey.GetValueNames();
string tmp = valNames.GetLength(0); //Cannot implicitly convert type 'int' to 'string' *ERROR*
// int tmp = regKey.ValueCount; // This blows up too...
return tmp;
It's kind of hard to loop from 0 to loop count when I can't get to the count. I keep getting that error when I try to compile.
I want to write a simple for loop that will pull the values and display them. I can access them like this:
string val0 = (string)regKey.GetValue(valnames[0]);
and then can write out val0 later on with no problems.
Thanks in advance,
Bill K.
|
|
|
|
|
Try this:
string[] valNames = regKey.GetValueNames();<br />
foreach(string tmp in valNames)<br />
{<br />
}
|
|
|
|
|
codeweenie wrote:
string tmp = valNames.GetLength(0); //Cannot implicitly convert type 'int' to 'string' *ERROR*
You're trying to assign an Int32 value to a String. The GetLength method returns "The number of elements in the specified dimension." As a side note, you are only ever going to have one dimension, so you could just use the Length property.
So what you could do is:
RegistryKey regKey = Registry.LocalMachine.CreateSubKey(@"Software\MyTestRegKey");
foreach(string name in regKey.GetValueNames())
{
Debug.Print(regKey.GetValue(name));
}
[edit]That skips the whole issue of getting the length or working with iterating through the list. It's actually a much better way of doing it unless you need the index of the value in the array later on.[/edit]
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
Perhaps I'm doing something wrong, but I'm using the TcpClient class and I had a button that uses it to connect to a POP3 server. Now once I'm connected the connect button will disconnect me by calling the TcpClient.Close method, the thing is the connection doesn't close. I break when I press connect again (connecting after the first disconnect) and now things are weird. I check the TcpClient.Active property to make sure I don't connect again if were already connected (we shouldn't be connected because I called close, but we are) and if I hover my mouse on the if statement it shows the property as false (not connected), but if I look at the same property in the watch window it shows as true. I guess what I'm wondering is why isn't the connection closing when I call the close method.
What's really got me angry is that if I call TcpClient.Connect again complains that were already connected, but if I try to use the connection to obtain the network stream (which I closed before) it complains that I can't call that method on a non-connected socket.
A big thanks in advance for any help, I've been trying to figure this out for hours and am getting pretty frustrated.
- monrobot13
|
|
|
|
|
I guess what I wrote above isn't really making sense so here's some code to explain it. The code below is simply a variable in the class:
private Pop3Client popClient = new Pop3Client (); Now the next piece of code is what is executed when I press the connect button:
popClient.Connect (server)
...
protected string Connect ()
{
string temp;
if (!Active) {
popClient.Connect (server, 110);
}
else
return ("Client is already connected.");
try {
streamWrite = PopClient.GetStream ();
streamRead = new StreamReader (PopClient.GetStream ());
state = ConnectState.AUTHORIZATION;
temp = streamRead.ReadLine ();
}
catch (InvalidOperationException ex) {
temp = "Error in Connect (): " + ex.ToString ();
}
return temp;
} The next code is called when I press the disconnect button:
public string Disconnect ()
{
string temp = "";
if (state != ConnectState.DISCONNECTED) {
try {
temp = QUIT ();
state = ConnectState.DISCONNECTED;
}
catch (SocketException ex) {
Debug.Write ("Error in Disconnect (): " + ex.ToString ());
}
temp += "\r\n" + "*** Disconnected Successfully ***";
}
else
temp = "Not connected";
Close ();
return temp;
} When I press connect and then disconnect it works the first time, but when I click connect again I'm getting an error in the popClient.Connect (server, 110); line. It tells me that the socketed is already connected even though I'm call Close () in the Disconnect method.
Please help!
Thanks!
- monrobot13
|
|
|
|
|
I thought this bug was fixed in the beta stages, but there was a bug in that TcpClient.Close would not close the underlying socket. The work-around was to close the underlying socket yourself (I think you did this by getting the NetworkStream then called Close on it).
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I have been working on a project and have gotten it to a beta point. At this time, I wish to be able to give this application to other people to be able to test out the functionality. To do this, I have been working with creating a setup project. The problem that I run into is that the access database is not in the same location on the new machine as it is on my development platform. As a result, anytime a database call is made an exception is raised.
I have looked for information on how to work with this (books, internet, friends), and have not been able to find any information. The only thing that I did find is that I cannot use xcopy to deploy the application. Does anyone know of an article on this site, or other reference that discusses how to create a setup project that will allow me to set the path for the db on the fly?
Thank you in advance for all of the help,
Eric VanWieren
It is the nature of man to rise to greatness if greatness is expected of him.
- John Steinbeck
|
|
|
|
|
Like you, I've written a couple programs that access a database. In order to do this with ADO.NET(which is what I use), you must set up a connection string inside your OleDBConnection object. The connection string gives(among other things) a path to your database file.
When you add a OleDBDataAdapter object to your form, a wizard pops up to help you set up your connection. For example, when I set up a data adapter to my Access database, the designer adds this line of code to my program:
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Password="""";User ID=Admin;Data Source= Path to your file here ;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
I know that looks like a bunch of jibberish, but what you can do is before you open a connection to your database, modify your connection string to reflect where your database is.
Because you don't know where the user will choose to install your program, you can use the System.Environment.CurrentDirectory property to locate where your application is running from and (assuming your database's location is based on the location of the app) append your database's path and name.
My code to do this looks like this:
string CurrentDir = System.Environment.CurrentDirectory;<br />
CurrentDir += "\\DB\\database.mdb";
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Password="""";User ID=Admin;Data Source=";<br />
this.oleDbConnection1.ConnectionString += CurrentDir;<br />
this.oleDbConnection1.ConnectionString += @";Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
I hope that helps.
Daniel E. Blanchard
|
|
|
|
|
I am an HCI student desperately trying to persuade my supervisor that Web services and smart client apps would provide a good bases for an honours project.
i) Has anyone ever come over any good articles on the issues or any project implementations? I’m currently searching for any written relevant documentation.
MS's Task vision was the kinda’ thing I was, considering until they published it, but a little more single user orientated.
ii) Has anyone ever come across sideshow (sshh!), is it web service consuming or not that smart yet?
Tia
gadget
|
|
|
|
|
Hi there
I am relative new in C# and I would like to save
the content of the TreeView control in my Program.
In other languages there I found something like
treeView->SaveToFile .... or something like that.
I tried already a little bit with Serialize and
BinaryFormatter but it doesn't work at all.
Could someone please help me ?
|
|
|
|
|
when you are saving the nodes on your treeview does it matter how they are saved? as in does order matter? or anything like that ?
if none of that is of concern...(just guessing here) you could use a foreach statement to parse through each node, and then just save the text of the node.
exsample :
<br />
<br />
foreach(TreeNode treenode in treeView.Nodes){
}<br />
Good Luck
Jesse M
The Code Project Is Your Friend...
|
|
|
|