|
Almost...
private void textBox_TextChanged(object sender, System.EventArgs e)
{
try
{
if(this.Text.Length > 0)
int.Parse(this.Text);
this.validValue = this.Text
}
catch (System.FormatException)
{
this.Text = this.validValue;
}
}
|
|
|
|
|
Interesting, I will consider this in my application.
Never needed to look for an empty string, because all my TextBoxes, i use this for, have default values. But better be prepared for all cases
By the way, what happens, if the Parse method is called with a string with Length = 0?
|
|
|
|
|
int.Parse throws a FormatException when given a zero length string so that check is definitely necessary (at least it is for my application)
|
|
|
|
|
how to assigning a Drive to a Share in c#?
Currently, i try the API for make that but he don't run....
Could you help me ?
public enum ResourceScope
{
RESOURCE_CONNECTED = 1,
RESOURCE_GLOBALNET,
RESOURCE_REMEMBERED,
RESOURCE_RECENT,
RESOURCE_CONTEXT
};
public enum ResourceType
{
RESOURCETYPE_ANY,
RESOURCETYPE_DISK,
RESOURCETYPE_PRINT,
RESOURCETYPE_RESERVED
};
public enum ResourceUsage
{
RESOURCEUSAGE_CONNECTABLE = 0x00000001,
RESOURCEUSAGE_CONTAINER = 0x00000002,
RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004,
RESOURCEUSAGE_SIBLING = 0x00000008,
RESOURCEUSAGE_ATTACHED = 0x00000010,
RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED),
};
public enum ResourceDisplayType
{
RESOURCEDISPLAYTYPE_GENERIC,
RESOURCEDISPLAYTYPE_DOMAIN,
RESOURCEDISPLAYTYPE_SERVER,
RESOURCEDISPLAYTYPE_SHARE,
RESOURCEDISPLAYTYPE_FILE,
RESOURCEDISPLAYTYPE_GROUP,
RESOURCEDISPLAYTYPE_NETWORK,
RESOURCEDISPLAYTYPE_ROOT,
RESOURCEDISPLAYTYPE_SHAREADMIN,
RESOURCEDISPLAYTYPE_DIRECTORY,
RESOURCEDISPLAYTYPE_TREE,
RESOURCEDISPLAYTYPE_NDSCONTAINER
};
public class ServerEnum : IEnumerable
{
enum ErrorCodes
{
NO_ERROR = 0,
ERROR_NO_MORE_ITEMS = 259
};
public class ServerEnum : IEnumerable
{
enum ErrorCodes
{
NO_ERROR = 0,
ERROR_NO_MORE_ITEMS = 259
};
[StructLayout(LayoutKind.Sequential)]
private class NETRESOURCE
{
public ResourceScope dwScope = 0;
public ResourceType dwType = 0;
public ResourceDisplayType dwDisplayType = 0;
public ResourceUsage dwUsage = 0;
public string lpLocalName = null;
public string lpRemoteName = null;
public string lpComment = null;
public string lpProvider = null;
};
[DllImport("Mpr.dll", EntryPoint="WNetAddConnection2", CallingConvention=CallingConvention.Winapi)]
private static extern ErrorCodes WNetAddConnection2(NETRESOURCE lpNetResource,ref string lpPassword,ref string lpUsername, System.UInt32 dwFlags );
public void connectMapDrive(){
NETRESOURCE lpNetResource = new NETRESOURCE();
lpNetResource.dwType =ResourceType.RESOURCETYPE_ANY;
lpNetResource.lpLocalName="O:";
lpNetResource.lpRemoteName= @"\\Bruxptest\Fichiers" ;
lpNetResource.lpProvider = "";
string lpPassword ="PASSWORD**" ;
string lpLocalName =@"bruxptest\ll2";
ErrorCodes rc = WNetAddConnection2(lpNetResource,ref lpPassword,ref lpLocalName,0x01);
}
}
-=zoltx=-
|
|
|
|
|
First, you didn't describe any errors or what exactly the problem was. It's very hard to help you when you don't mention specific problems.
Second, why not make this easier:
string drive = "X";
string share = @"\\machine\share";
Process.Start("net.exe", string.Format("use {0}: {1}", drive, share)); You could easily add switches for a username and password, too. Type "net use /?" in the command prompt for more information.
If you'd rather do this programmatically, then please be more specific about the nature of your problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
sorry,
I would like to make a windows service which able to check and map the shared drive automatically. When i launch my api for that, I receive a error message 2202: ERROR_INVALID_WINDOW_STYLE
the equivalence in c++ is :
#include <windows.h>
#include <stdio.h>
#include <winnetwk.h>
void main()
{
NETRESOURCE nr;
DWORD res;
TCHAR szUserName[32] = "MyUserName",
szPassword[32] = "MyPassword",
szLocalName[32] = "Q:",
szRemoteName[MAX_PATH] = "\\\\products2\\relsys";
//
// Assign values to the NETRESOURCE structure.
//
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = szLocalName;
nr.lpRemoteName = szRemoteName;
nr.lpProvider = NULL;
//
// Call the WNetAddConnection2 function to assign
// a drive letter to the share.
//
res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE);
//
// If the call succeeds, inform the user; otherwise,
// print the error.
//
if(res == NO_ERROR)
printf("Connection added \n", szRemoteName);
else
printf("Error: %ld\n", res);
return;
}
and it is work?
-=zoltx=-
|
|
|
|
|
Are you running the app as the LOCAL SYSTEM account or as a user? Also, you have to tag the service as able to interact with the desktop.
RageInTheMachine9532
|
|
|
|
|
user, and interact........
-=zoltx=-
|
|
|
|
|
helo, my name is keen weng. i am new in c#. I am currently doing a project using c#, my question is how could i write a program which i could remotely control a mouse or access to a hard disk in other pc which is connected in a same local area network?is it possible? but, i am not talking about hacking because i am making something like network monitoring system .what references should i refer to? , thank you.
weng
|
|
|
|
|
Yes, it's called PCAnywhere from Symantec. Your going to need to write a client and server, just like PCAnywhere.
The server piece will go on the workstations you want to control. It will have to have code to get the desktop image, hooks into Windows to control the mouse and keyboard, and you'll probably want to write a small file transfer server also. You'll also need to write a communications class that can encode and decode commands between the two modules.
The client piece is going to call into the servers to get the screens that they are looking at. Also, you'll need to map mouse moves and clicks and keystrokes on your client to the screen that is coming from the workstation you want to control.
It's very possible to do, but is a bunch of work. I'd consider going with a commercial package before dumping your time into a few months of development, especially since your new to C#. I'd tackle a more managable project to learn with first.
RageInTheMachine9532
|
|
|
|
|
In addition to PCAnywhere, there are others. If your workstations are running Windows XP, there's a client build right-in (but works on a request basis). You can enable it (I think it is by default) by going to your System properties (in the Control Panel, or right-click on My Computer and select Properties), then the Remote tab, and right there are the top is information about Remote Assistance, which users can invoke from the Help and Support menu off the Start menu. Help and Support can also be highly customized to fit the needs of OEMs and domains.
As Dave said, why spend lots of man hours when so many things like this already exist, many of which are cheaper than all the time spent developing such a project. And not just because you're new to C# and .NET, those existing products will most likely be better (to some degree) because they've been in development by dedicated teams of professionals for many years (even the Windows XP remote assistance has foundations in NetMeeting technology introduced back in '96 or so).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Besides what Dave and Heath wrote, you can also take a look at VNC. There are lots of VNC variants available, all with C++ sources.
VNC is pretty good (specially RealVNC, which can achieve speeds similar to Remote Desktop and Terminal Services) and is multiplatform.
But is not written in C#.
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
I am currently working on development of a framework that satisfies mathematical requirements.
This framework is supposed to have a CAD-like interface that will allow users to drag and drop visual mathematical components. It also provided the user with the ability to create new components from basic predefined ones and use them in new components.
The problem is I do not know if c# forms have any tools that will make it easy to create graphical components with inputes/outputs labelled pins and support connection of components in a visio-kind of way.
PLEASE IF U KNOW A WAY TO ACCOMPLISH THIS IN DOTNET HELP!!!!
|
|
|
|
|
The base class library of the .NET Framework does not support such behavior "out-of-the-box". That's the nice thing about a framework, though: it gives you the basic with which to write custom controls.
You could start with a simple base class that maintains a collection of points (which you override in derivative classes). Each point contains coordinates in relation to the object and a reference to another point in another object. For your control that contians these objects, you draw lines using this point information, as well as pass the Graphics object to each object so it can draw itself. It's a fairly simple solution to a relatively easy problem, but it should give you some idea of where to start. You could just extend UserControl , for instance, that has a collection of these objects. Through the power of polymorphism, the UserControl that contains the drawing surface doesn't need to care about what the objects are and how to draw them, so long as they derive from a common base class and draw themselves.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thank u for your contribution. it is very helpfull.
|
|
|
|
|
If willing to spend the cash, this toolset[^] looks like it's just what you need.
--
Russell Morris
"So, broccoli, mother says you're good for me... but I'm afraid I'm no good for you!" - Stewy
|
|
|
|
|
Forgive me if this is a simple question
I need to write C# code that dials the computers modem and connects to the Internet using the users default connection information. I cannot seem to find an example that shows me how to do this simple task.
Any article pointers anyone?
Thanks in advance
|
|
|
|
|
You should use win32 API for start point look at InternetDial() function. About how to use win32 API in C#, search for DllImport in this site or MSDN.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Does anyone know if there is a VB.net to C# language converter, and if so, where to download it?
Thanks,
Ryan
|
|
|
|
|
It's in the ASP.NET Resource Kit. You can download it free of charge here:
http://msdn.microsoft.com/asp.net/asprk/
it quite the download, but it's WELL worth it!
-------------------------------
Joan
MomComputerGeek.com
|
|
|
|
|
Opps, I'm sorry the ASP.NET Resource kit has the exact opposite of what your looking for. It converts C# to VB.NET... Sorry. It's still worth the download if you dont already have it.
-------------------------------
Joan
MomComputerGeek.com
|
|
|
|
|
Once compiled, it doesn't matter what the source language is. If you need to maintain the source, why not just learn VB.NET? It's just a different syntax. It uses assemblies in the same way that any other language can.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I tend to agree with you Heath, but my project manager has asked me to convert it, alas, I must do it. Anyone else know of any vb.net to c# converters?
Thanks,
Ryan
|
|
|
|
|
A quick and simple search on google turned up a couple, one of which is right here on CodeProject:
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
If you need to maintain the source, why not just learn VB.NET?
And while you're at it, COBOL .Net and Fortran .Net work pretty well too. Why don't you mix some of them into your project? Then nobody on your team will be able to maintain your project. Job security, man!
Top 10 Reasons to mix languages as much as possible:
#10: Find all those hidden inter-language bugs before all your buddies!
#9: Flaunt company coding standards
#8: Help prepare you for the MCSD exams instead of working, like you're paid to do
#7: Since nobody else can read your code, you stay employed longer
#6: Unable to cut-and-paste between different languages forces better encapsulation and prevents clipboard inheritance
#5: Adds at least one more language item to your resume!
#4: Microsoft *never* has a history of modifying a language like VB after everyone has already learned it
#3: Experience the magic of inter-language type-casting!
#2: Because occasionally your semi-colon pinky gets tired
And the top reason to mix languages in .Net as much as possible:
#1: Just because your boss told you not to do it, doesn't necessarily mean you'll actually get fired for trying.
- Tony Goggin
|
|
|
|
|