|
hi there,
I have downloaded zedgraph and m using it as a class.I have copied the file(as per given in ur tutorial)but on exectuing the code,its giving a weird error:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in system.windows.forms.dll
Additional information: File or assembly name System.Drawing, or one of its dependencies, was not found.
plz help
|
|
|
|
|
Do you have a reference to System.Drawing in your project?
---
b { font-weight: normal; }
|
|
|
|
|
yes i have included System.Drawing as a namespace..
|
|
|
|
|
The System.Drawing namespace is spread across multiple assemblies. You need to explicitly add a reference to System.Drawing.dll.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have added the System.drawing.dll as a reference buts its still giving the same error.I m pasting the error here
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in system.windows.forms.dll
Additional information: File or assembly name System.Drawing, or one of its dependencies, was not found.
and the code is :
static void Main()
{
Application.Run(new Form1());
} (its showing error in this line)
private void Form1_Load(object sender,System.EventArgs e)
{
//blank
}
private void button1_Click(object sender, System.EventArgs e)
{
string value1 = textBox1.Text;
MessageBox.Show("Selected X label is " + value1);
string value2 = textBox2.Text;
MessageBox.Show("Selected Y label is "+value2);
string value3 = textBox3.Text;
string value4 = textBox4.Text;
GraphPane myPane;
myPane = new GraphPane( new Rectangle( 40, 40, 600, 400 ),
"My Test Graph\n(For CodeProject Sample)",
"My X Axis",
"My Y Axis" );
myPane.Draw(this.CreateGraphics());
|
|
|
|
|
i need to obtain computer names and their ip addresses of a network (LAN). i.e i have to scan the network and obtain all computer names and ip addresses WITHOUT USING ACTIVE DIRECTORY. i m developing in C#. can anybody help me in this context please?
Amar
|
|
|
|
|
AFAIK, there is no API in .NET to do what you want. You can pinvoke and use the NetServerEnum API (Netapi32.dll) instead.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Ping each IP address in the range your looking for. If you get a response, then you can use a DNS lookup on that address to return the name associated with that address.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
I have some notes on this topic if you still getting problem pls tell me
5.7.6. Get current user name
This sample presents two different approaches to getting current user information.
Namespaces:
using System;
using System.Net;
using System.Security.Principal;
Code:
static void Main(string[] args)
{
// get info about current user using Environment class
Console.WriteLine(Environment.UserDomainName + @"\" + Environment.UserName);
// --------------------------
// get current user from WindowsIdentity class
WindowsIdentity user = WindowsIdentity.GetCurrent();
// output current user name
Console.WriteLine(user.Name.ToString());
}
5.7.7. Impersonate as another user
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
class ImpersonateUser
{
// this implementation doesn't handle GetLastError function to catch error messages, it should be implemented in standard application
// mapping of Win32 function to logon under another account
[DllImport("advapi32.dll", SetLastError = true)]
public static extern bool LogonUser(
String lpszUsername,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
// this will duplicate access token based on current user's one
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public extern static bool DuplicateToken(
IntPtr ExistingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL,
ref IntPtr DuplicateTokenHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
static void Main(string[] args)
{
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_PROVIDER_DEFAULT = 0;
const int SecurityImpersonation = 2;
// handle of access token of current user
IntPtr token = IntPtr.Zero;
// new token based on the old one
IntPtr duplicateToken = IntPtr.Zero;
// this method returns handle to access token of user we want to use to logon, user is check just in local database
if (LogonUser("TestUser", ".", "Test1234]", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token))
{
// token is duplicated according to the token of impersonated user
if (DuplicateToken(token, SecurityImpersonation, ref duplicateToken))
{
Console.WriteLine("Current user name: " + WindowsIdentity.GetCurrent().Name);
// new identity is created
WindowsIdentity newIdentity = new WindowsIdentity(duplicateToken);
// !!!! This is the impersonation !!!!
WindowsImpersonationContext impersonatedUser = newIdentity.Impersonate();
Console.WriteLine("Current user name: " + WindowsIdentity.GetCurrent().Name);
// return to the old user
impersonatedUser.Undo();
Console.WriteLine("Current user name: " + WindowsIdentity.GetCurrent().Name);
// close handles to tokens
CloseHandle(token);
CloseHandle(duplicateToken);
}
else { Console.WriteLine("Error duplicate."); }
}
else { Console.WriteLine("Error logon."); }
}
}
5.7.10. List running processes and user accounts
Namespaces:
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Collections;
using System.Diagnostics;
Code:
class ListOfProcessAccounts
{
class ProcessIdentity
{
public Process Process;
public WindowsIdentity Identity;
public ProcessIdentity(Process process, WindowsIdentity identity)
{
this.Process = process;
this.Identity = identity;
}
}
[Flags]
enum TOKEN_ACCESS : uint
{
TOKEN_ASSIGN_PRIMARY = 0x0001,
TOKEN_DUPLICATE = 0x0002,
TOKEN_IMPERSONATE = 0x0004,
TOKEN_QUERY = 0x0008,
TOKEN_QUERY_SOURCE = 0x0010,
TOKEN_ADJUST_PRIVILEGES = 0x0020,
TOKEN_ADJUST_GROUPS = 0x0040,
TOKEN_ADJUST_DEFAULT = 0x0080,
TOKEN_ADJUST_SESSIONID = 0x0100,
TOKEN_READ = 0x00020000 | TOKEN_QUERY,
TOKEN_WRITE = 0x00020000 | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT,
TOKEN_EXECUTE = 0x00020000,
};
[DllImport("Advapi32.dll", SetLastError = true)]
extern static int OpenProcessToken(IntPtr processHandle, TOKEN_ACCESS desiredAccess, out IntPtr tokenHandle);
[DllImport("kernel32.dll", SetLastError = true)]
extern static bool CloseHandle(IntPtr handle);
static ProcessIdentity[] GetProcessesIdentities()
{
ArrayList list = new ArrayList();
foreach( Process process in Process.GetProcesses() )
{
try
{
IntPtr token = IntPtr.Zero;
if( OpenProcessToken(process.Handle, TOKEN_ACCESS.TOKEN_QUERY, out token) == 0 )
{
throw new ApplicationException("Can't open process token for: " + process.ProcessName);
}
list.Add(new ProcessIdentity(process, new WindowsIdentity(token)));
CloseHandle(token);
}
catch( Exception ex )
{
list.Add(new ProcessIdentity(process, null));
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
return (ProcessIdentity[])list.ToArray(typeof(ProcessIdentity));
}
static void Main(string[] args)
{
ProcessIdentity[] normalProcIDs = GetProcessesIdentities();
foreach( ProcessIdentity procid in normalProcIDs )
{
if( procid.Identity != null )
{
Console.WriteLine("{0} running under {1}", procid.Process.ProcessName, procid.Identity.Name);
}
else
{
Console.WriteLine("{0} *probably* running under SYSTEM", procid.Process.ProcessName);
}
}
}
}
8. Network Operations
8.1.1. Retrieve DNS computer name
Code:
public static void Main(string[] args) {
Console.WriteLine(“DNS: {0}”, System.Net.Dns.GetHostByName(“LocalHost”).HostName);
}
8.1.2. Retrieve NetBIOS computer name
Code:
public static void Main(string[] args) {
Console.WriteLine(“NetBIOS: {0}”, System.Environment.MachineName);
}
8.1.3. Obtain IP address and host
Namespaces:
using System;
using System.Net;
Code:
static void Main(string[] args)
{
string host = Dns.GetHostName();
Console.WriteLine("Hostname is: {0}", host);
IPHostEntry entry = Dns.GetHostByName(host);
foreach (IPAddress ip in entry.AddressList)
{
Console.WriteLine("IP address: " + ip.ToString());
}
}
8.1.4. Send email in .NET environment
Namespaces:
using System;
using System.Web.Mail;
Code:
static void Main(string[] args)
{
MailMessage mailMsg = new MailMessage();
mailMsg.From = "jan.seda@skilldrive.com";
mailMsg.To = "jseda@microsoft.com";
mailMsg.Cc = "";
mailMsg.Bcc = "";
mailMsg.Subject = "Here goes a subject";
mailMsg.Body = "Here goes email body";
mailMsg.Priority = (MailPriority)1;
mailMsg.Attachments.Add(new MailAttachment("c:\\links.txt"));
SmtpMail.SmtpServer = "smarthost";
SmtpMail.Send(mailMsg);
}
8.1.5. Retrieve email from POP3 mail server
Namespaces:
using System;
using System.IO;
using System.Text;
using System.Net.Sockets;
Code:
public static void Main ()
{
const string host = "pop3.yourdomain.com";
const string user = "youruseraccount";
const string password = "yourpassword";
// tcp client for pop3
TcpClient tcp = new TcpClient();
// connect to host to port 110 (pop3)
tcp.Connect(host, 110);
NetworkStream netStream = tcp.GetStream();
StreamReader reader = new StreamReader(tcp.GetStream());
// allocate bytes for buffered read by TCP stream
string inBuffer = "";
// sent bytes to mail server
byte[] outBuffer;
// read data into the buffer
inBuffer = reader.ReadLine();
// output data read from server (usually name of mail server with welcome message)
Console.WriteLine(inBuffer);
// authorize to the server (USER userName)
outBuffer = Encoding.ASCII.GetBytes("USER " + user + "\r\n");
netStream.Write(outBuffer, 0, outBuffer.Length);
// response from server (OK)
inBuffer = reader.ReadLine();
// send password (PASS password)
outBuffer = Encoding.ASCII.GetBytes("PASS " + password + "\r\n");
netStream.Write(outBuffer, 0, outBuffer.Length);
// response from server (OK - login)
inBuffer = reader.ReadLine();
Console.WriteLine("---------------------- Authenticated to server ----------------------");
outBuffer = Encoding.ASCII.GetBytes("STAT" + "\r\n");
netStream.Write(outBuffer, 0, outBuffer.Length);
inBuffer = reader.ReadLine();
Console.WriteLine(inBuffer);
// retrieve first message from server (RETR messageNumber)
outBuffer = Encoding.ASCII.GetBytes("RETR 1" + "\r\n");
netStream.Write(outBuffer, 0, outBuffer.Length);
inBuffer = reader.ReadLine();
Console.WriteLine(inBuffer);
while (!inBuffer.Equals("."))
{
inBuffer = reader.ReadLine();
Console.WriteLine(inBuffer);
}
outBuffer = Encoding.ASCII.GetBytes("QUIT" + "\r\n");
netStream.Write(outBuffer, 0, outBuffer.Length);
// close tcp connection
tcp.Close();
}
9. File operations
9.1. General IO operations
9.1.1. Get executing application’s path with reflection
Code:
static void Main(string[] args)
{
string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
Console.WriteLine(path);
}
9.1.2. Get executing application’s path
Code:
static void Main(string[] args)
{
// this shows application's path
Console.WriteLine(System.Windows.Forms.Application.StartupPath);
}
9.1.3. Classes working with file and directory information
9.1.4. Change file & folder attributes
Code:
using System;
using System.IO;
class ChangeAttrib
{
static void Main(string[] args)
{
// arg[0] represent path to files and folder where attributes will be changed
ChangeAttributes(args[0]);
}
public static void ChangeAttributes(string path)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
// set directory attribute to appropriate
dirInfo.Attributes = FileAttributes.Normal;
foreach (FileSystemInfo file in dirInfo.GetFileSystemInfos())
{
// here set appropriate attribute for file
file.Attributes = FileAttributes.Normal;
}
foreach (DirectoryInfo dir in dirInfo.GetDirectories())
{
// do recursive calls to change attributes in subdirectories
ChangeAttributes(dir.FullName);
}
}
}
9.1.5. Recursive list of directories/subdirectories & files
Code:
using System;
using System.IO;
class Sample
{
static void Main(string[] args)
{
DirectoryInfo dirInfo = new DirectoryInfo("c:\\Sample_path");
RecursiveList(dirInfo);
}
private static void RecursiveList(DirectoryInfo dirInfo)
{
// first list all subdirectories
DirectoryInfo[] subDirs = dirInfo.GetDirectories();
foreach(DirectoryInfo subDir in subDirs)
{
RecursiveList(subDir);
}
// list all files in current directory (as RecursiveList method is called)
FileInfo[] dirFiles = dirInfo.GetFiles();
foreach(FileInfo fileInfo in dirFiles)
{
Console.WriteLine(fileInfo.FullName);
}
}
}
hope this will help
Regards,
sanjeev
|
|
|
|
|
Hi,
Im trying to set the font in my Richtextbox by some buttons.
If I set some Text to bold, it works. then i want to reset the style to regular (for the whole Control). The first time it works, but any next time it fails. nothing changes.
background:
The words are set to bold by selecting text and then set the font for selected text in code.
Then at some point i want to reset it. But this just works once.
I tried it with substracting the bold style, by just overriding it. nothing works.
is there any way to reset the fontstyles to regular for ALL text, without selecting all and then set the font.
I really hope you can help me with this!
thank you!!
moon44
|
|
|
|
|
You can try with RichTextBox.ResetFont(), perhaps it works. I don't know any other method.
I think the problem cames from the RTF format: all the 'styles' for the text are set by tags similar (regarding the concept, not the syntax) to the HTML's tags. when you select a word, maybe the control DO NOT select correctly the tags... but this is only a supposition.
Try to print the RichTextBox.Rtf property, that reports all the RTF code.
|
|
|
|
|
hi,
thank you for your answer. this could explain the behavior. the *global* font tag just wraps around and does not override the *inner* tags.
the resetfont seems to do something, but i can't tell what exactly. WHAT is the default font value? it seems like thats not defined.
thank you for any additional hints!
|
|
|
|
|
The default font value is the one you have set in design-mode (or the automatically set value, MS Reference Sans Serif or so)
Sorry but I don't know more...
|
|
|
|
|
Hi all,
here is the real code I am using for with improved code and conditions but I am running also into the bracket.
but the last contition is false BAKER is not Meyers and so the I should never run into the bracket (MessageBox ..)
string a = "MR";
string b = "MRS";
string c = "BAKER";
string d = "Meyers";
if
(
((string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MR")) &&
(string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MRS"))) ||
((string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MRS")) &&
(string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MR"))) &&
(string.Equals(c.TrimEnd().TrimStart().ToString().ToUpper(),
d.TrimEnd().TrimStart().ToString().ToUpper()))
)
{
MessageBox.Show("ERROR");
}
where is the fault ?!?!?
please help
Thanks Frank
|
|
|
|
|
|
Let me break your statement into three parts:
bool a = (string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MR"))
&& (string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MRS"));
bool b = (string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MRS"))
&& (string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MR"));
bool c = string.Equals(c.TrimEnd().TrimStart().ToString().ToUpper(),
d.TrimEnd().TrimStart().ToString().ToUpper());
Combined it would look like this:
if (a || b && c) {
MessageBox.Show("ERROR");
}
What the compiler makes out of this statement is this:
if (a || (b && c)) {
MessageBox.Show("ERROR");
}
Thats because the logical AND has a higher priority than the logical OR. Its like this simple numeric example:
3 + 2 * 4 = 3 + (2 * 4)
In conclusion the statement will be true if a is true no matter what the other subparts are.
|
|
|
|
|
Thank you for your answer,
but I think I did:
if ( ( a || b) && c ) {
MessagBox.Show("ERROR")
}
Please look at the (many) brackets - therefor I placed the brackets around the or-expression to force the compiler to check the or-term fist and this result with the &&-expression !
And that's what's going wrong
Frank
|
|
|
|
|
Yes, you thought that you did, but you failed.
Instead of ((a || b) && c) you created ((a) || (b) && c).
string a = "MR";<br />
string b = "MRS";<br />
string c = "BAKER";<br />
string d = "Meyers"; <br />
<br />
a = a.Trim().ToUpper();<br />
b = b.Trim().ToUpper();<br />
c = c.Trim().ToUpper();<br />
d = d.Trim().ToUpper();<br />
<br />
if (((a == "MR" && b == "MRS") || (a == "MRS" && b == "MR")) && c == d) {<br />
MessageBox.Show("ERROR");<br />
}
---
b { font-weight: normal; }
|
|
|
|
|
no you did not. It will result in
if
(
(1) || ( 1 ) && (0)
)
{
MessageBox.Show("ERROR");
}
Must be this:
if
(
(((string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MR")) &&
(string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MRS"))) ||
((string.Equals(a.TrimEnd().TrimStart().ToString().ToUpper(),"MRS")) &&
(string.Equals(b.TrimEnd().TrimStart().ToString().ToUpper(),"MR")))) &&
(string.Equals(c.TrimEnd().TrimStart().ToString().ToUpper(),
d.TrimEnd().TrimStart().ToString().ToUpper()))
)
{
MessageBox.Show("ERROR");
}
will result in
if
(
((1) || ( 1 )) && (0)
)
{
MessageBox.Show("ERROR");
} and will not display message box.
But still, it's a mess.
David
|
|
|
|
|
May I suggest you little simplification?
a.TrimEnd().TrimStart().ToString().ToUpper() -> a.Trim().ToUpper()
David
|
|
|
|
|
Thank's but that doesn't help in my problem !
regards
Frank
|
|
|
|
|
fracalifa wrote:
that doesn't help in my problem !
Pardon, but it does. Low readability (daily-wtf calibre!) of your code is what caused problem here.
ok, it is prevence but not solution, that's why I say it is OT (off topic).
David
|
|
|
|
|
|
Hi all,
coming from "C" I'm a little bit confused on the result of the following boolean term.
I think this can never become TRUE but it does - why ?
if( ((("A"=="A") && ("B"=="B")) || (("A"=="B") && ("B"=="A"))) && (true==false) )
{
MessageBox.Show("Error"); // this code is not reachable ?????
}
A and B is really a comparison of strings
reduced to my understanding is that the results shoud be
if( (((TRUE)&&(TRUE)) ||((FALSE && FALSE))) && (FALSE) ) // should ever be FALSE
........\---------/........\----------/.........|
........... TRUE......||.......FALSE.......&& FALSE
.............\------------------/...............|
.....................TRUE..................&& FALSE = FALSE //!!
the second problem is that the code in the brackets is not reachable ????
the count of backets is correct !
that's leave my understanding of C#
where is my error in thinking ?
Thanks for your help
Frank
|
|
|
|
|
In c# the == operator has been redefined for strings, so when you compare two strings written like "abc" the compiler is able to compare them. Using variables, you have to use the string.Equals(...) or the string.CompareTo(...) methods to have reliable results. In VB.NET you can use the = operator also for string variables.
|
|
|
|
|