|
In either case, it's a bad idea to go hunting for a process then close it. Since he didn't directly launch it, he shouldn't be closing it in the first place. IMHO, it's just bad practice.
Good point; I agree.
That's kind of why I was suggesting the extra checks. However, now that you mention it, I think the better suggestion is to either not try to kill the instance of IE that's created by this other process, or work out a better interface with the creators of that other process, if possible. The idea of a browser window appearing with some stuff, then automatically disappearing seems pretty bad. Long before you are doing something this kludgy, it is time to start trying to work out a better solution.
Matt Gerrans
|
|
|
|
|
Hello
I want to change the icon of exe of my program as i want to place an icon of my choice as to appear if i place it on my desktop. If any body can help.
Regards
asmyan
|
|
|
|
|
You can add an icon of your choice to File System Editor.
Go to File System Editor in Setup and Deployment, add a shortcut of Priamry output to User's Desktop and right click on the copied shortcut and goto ICON property and select the ICON you want.
As far as I know, you can only add an ICON to an exe with extension .ico
Hope this helps.
Looney
|
|
|
|
|
Assuming you are using VS .NET 2003, Right click on the Project in Solution Explorer, click Properties, go to Common Properties->General, you'll find an entry for Application Icon.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I would to convert to int a number got by a division of two doubles....
For example 500/900 i get 0.555... that is converted using Convert.ToInt16() in 1.
I would get 0 instead, then 1 if i divide 900/900 or 970/900.
How can i do?
|
|
|
|
|
Perhaps you are looking for the Math.Round function?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Math.Round just convert a double value to the nearest one, i need to convert it to the littlest one,
example:
1,43 to 1
1,21 to 1
1,98 to 1
2,01 to 2
2,54 to 2
8,76 to 8
5,99 to 5
ok? How can i do?
|
|
|
|
|
ok Floor is the method i need.
|
|
|
|
|
You are talking about the Floor function (returning nearest LOWER integer):
<br />
double a = 1.43;
int i = (int)Math.Floor(a);
Similar function is Ceiling, it returns a nearest higher integer ( Math.Ceiling(1.43) = 2 ), just for curiosity.
|
|
|
|
|
Have you considered Math.Floor() ?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
And what i've told??
|
|
|
|
|
Check out the pasted code. When the app starts, you can hit Alt-Tab and see the colorful icon in the Task Switching window. Now check the box and hit Alt-Tab again. We are left with a different icon.
The actual application I am working on has an Icon that appears on the exe and in the top-left of the form, but when ShowInTaskBar goes false, the Alt-Tab icon goes from the icon I designed to some default icon.
Any ideas?
///////////////////////////////////////////////////////////////////
// compile with csc /target:winexe MenuTest.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class MenuTest : System.Windows.Forms.Form
{
private System.Windows.Forms.CheckBox chkShowInTaskBar;
private System.ComponentModel.Container components = null;
public MenuTest()
{
InitializeComponent();
chkShowInTaskBar.Checked = true;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.chkShowInTaskBar = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// chkShowInTaskBar
//
this.chkShowInTaskBar.Location = new System.Drawing.Point(56, 8);
this.chkShowInTaskBar.Name = "chkShowInTaskBar";
this.chkShowInTaskBar.Size = new System.Drawing.Size(160, 24);
this.chkShowInTaskBar.TabIndex = 0;
this.chkShowInTaskBar.Text = "Show In Taskbar";
this.chkShowInTaskBar.CheckedChanged += new System.EventHandler(this.chkShowInTaskBar_CheckedChanged);
//
// MenuTest
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(256, 45);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.chkShowInTaskBar});
this.Name = "MenuTest";
this.Text = "MenuTest";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new MenuTest());
}
private void chkShowInTaskBar_CheckedChanged(object sender, System.EventArgs e)
{
this.ShowInTaskbar = chkShowInTaskBar.Checked;
}
}
|
|
|
|
|
i didn't understand, ur icon on alt-tab? do you have the correct icon for each size required?
IM PROUD TO BE A GMAIL;
|
|
|
|
|
If you compile that code, you'll see that there is an icon (albiet some default icon) that represents the Application when you hit alt-tab and see the task switcher come up. This icon has three colored boxes.
Now, see what happens when you go back to the application and uncheck the check box. Hit alt-tab again, and you see some new icon representing the application. This new icon looks like an empty Windows form with a blue border on the top. My question is: What happened to the other icon with the boxes? I only posted a test program to show this; my actual program has icons every place I need them, except for alt-tab when ShowInTaskBar is false.
|
|
|
|
|
hi all.
I have some problems in programming rich text box i succeeded to draw an image inside text box as emoticons by using dataformats and clipboard but the problems are:
1- the emoticons entered inside the rtb unanimated even if it is animated how can i implement that emoticons animated ?????????????
2- when the emoticons entered the richtext box if you point with your mouse pointer on it in rtb you can resize it how can i make it fixed ?????????
3- when i press my send button to send emoticons to the other user in chat the previous emoticons in my rich text box disappears and even the previous one transfered disappears in the private chat of the other user.
how can i make the emoticons don't disappears and make my rtb contains all the emoticons ?
Any help with this please .
i used the following code.
<br />
Bitmap myemot = new Bitmap(dialog.filename);<br />
ClipBoard.setDataObject(myemot);<br />
DataFormats.Format chm = DataFormats.GetFormat(DataFormats.Bitmap);<br />
rtb.text +=myusername + " \r\n";<br />
if(rtb.canpaste(chm))<br />
{<br />
rtb.paste(chm);<br />
}<br />
The Above Code makes the bitmap enter the rtb but with the previous problems any help with that please
Mess With The Best And Die Like The Rest
|
|
|
|
|
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
|
|
|
|
|