How to Create Shortcut of Application programatically using C# | C#
There are some situations in which we need to code to create a short cut of our application especially when user loose the shortcuts created by the application after the setup has been run because some shortcuts also have defines special parameters that are for executable that runs program.
Step 1:
Create a New Windows Form Project.
Step 2:
Drag drop a button control from Toolbox to Form name it btnShortcut and Set text Property to “Create Shortcut “
Step 3:
For creating shortcut you need to reference Windows Script Host Object so follow the steps as below
Step 4:
Add namespace as below
using IWshRuntimeLibrary;
Step 5:
Now write code in Button’s Click event like below
private void btnShortcut_Click(object sender, EventArgs e)
{
WshShellClass shell = new WshShellClass();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(@”D:\shotcut.lnk”);
shortcut.TargetPath = Application.ExecutablePath;
//shortcut.IconLocation = ‘Location of iCon you want to set”;
// add Description of Short cut
shortcut.Description = “Any Description here “;
// save it / create
shortcut.Save();
}
View the original article here
Drawing Shaped Forms and Windows Controls in GDI+
This article has been excerpted from book “Graphics Programming with GDI+”
Normally, all Windows controls and forms are rectangular, but what if we want to draw them in nonrectangular shapes? We can do this by setting the Region property. The Region property of a form or a control represents that window’s region, which is a collection of pixels within a form or control where the operating system permits drawing; no portion of a form that lies outside of the window region is displayed. To draw nonrectangular shapes, we trick the system into drawing only the region of a control.
Let’s draw a circular form. We can use the GraphicsPath class to draw graphics paths. In this application we’ll create a circular form and a circular picture box, which will display an image. To test this application, we follow these simple steps:
We create a Windows application and add a button and a picture box to the form. Then we set the Text property of the button control to “Exit” and write the following line on the button click event handler:
this.Close();
Next we add a reference to the System.Drawing.Drawing2D namespace that we can use the GraphicsPath class:
using System.Drawing.Drawing2D;
On the form-load event handler, we create a Bitmap object from a file and load the bitmap in the picture box shown in the following code snippet.
Image bmp = Bitmap.FromFile(“aphoto.jpg”;
pictureBox1.Image = bmp;
The last step is to set the form and picture box as circular. We can modify the InitializeComponent method and add code as in Listing 15.5 at the end of the method, or we can add the code on the form-load event handler. We just set the Region property of the form and picture box to the region of our GraphicsPath object.
Setting a form and picture box control as circular
private void Form1_Load(object sender, System.EventArgs e)
{
//Create a rectangle
Rectangle rect = new Rectangle(0, 0, 100, 100);
//Create a graphic path
GraphicsPath path = new GraphicsPath();
//Add an ellipse to the graphics path
path.AddEllipse(rect);
//Set the Region property of the picture box
//by creating a region form the path
pictureBox1.Region = new Region(path);
rect.Height += 200;
rect.Width += 200;
path.Reset();
path.AddEllipse(rect);
this.Region = new Region(path);
//Create an image from a file and
//set the picture box’s Image property
Image bmp = Bitmap.FromFile(“aphoto.jpg”);
pictureBox1.Image = bmp;
}
Drawing a circular form and Windows controls
When we build and run the application; the output will look like Figure 15.3. Because we have eliminated the normal title bar controls, we must implement an Exit button.
Getting detailed Information about Windows User Accounts with WMI and C#
This article is aimed about how to get detailed information about Windows user accounts like accounts SID, SID type, Name, caption, Account domain and whether Account Status is OK, degraded unknown etc through WMI.
To access account information of windows users we need to Use System.Management name space.
To use this namespace first of all we need to add reference to System.management by
Project Menu>>Add Reference.
after that at the top of the code use
using System.Management; so that you can use of its classes .
Now its simple to get information about any Windows user Account through querying ManagementObjectSearcher Class .
we can get all information about Windows User through Win32_Account class .
so we need to query on that class to get related Management object and then we just need to get various properties related to it .
Basic WCF Implementation
This article will contain how to create publish and consume WCF service.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace Microsoft.ServiceModel.Samples
{
[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
public interface Icalculator
{
// Step7: Create the method declaration for the contract.
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
}
}
Creation of service.
public class CalculatorService : Icalculator
{
decimal CallCnt = 0;
// Step 2: Implement functionality for the service operations.
public double Add(double n1, double n2)
{
CallCnt += 1;
double result = n1 + n2;
Console.WriteLine(“Received Add({0},{1})”, n1, n2);
// Code added to write output to the console window.
Console.WriteLine(“Return: {0}”, result);
Console.WriteLine(“Call Count: {0}”, CallCnt);
return result;
}
public double Subtract(double n1, double n2)
{
CallCnt += 1;
double result = n1 – n2;
Console.WriteLine(“Received Subtract({0},{1})”, n1, n2);
Console.WriteLine(“Return: {0}”, result);
Console.WriteLine(“Call Count: {0}”, CallCnt);
return result;
}
public double Multiply(double n1, double n2)
{
CallCnt += 1;
double result = n1 * n2;
Console.WriteLine(“Received Multiply({0},{1})”, n1, n2);
Console.WriteLine(“Return: {0}”, result);
Console.WriteLine(“Call Count: {0}”, CallCnt);
return result;
}
public double Divide(double n1, double n2)
{
CallCnt += 1;
double result = n1 / n2;
Console.WriteLine(“Received Divide({0},{1})”, n1, n2);
Console.WriteLine(“Return: {0}”, result);
Console.WriteLine(“Call Count: {0}”, CallCnt);
return result;
}
}
class Program
{
static void Main(string[] args)
{
// Step 1 of the address configuration procedure: Create a URI to serve as the base address.
Uri baseAddress = new Uri(“http://localhost:8000/ServiceModelSamples/Service”);
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(
typeof(Icalculator),
new WSHttpBinding(),
”CalculatorService”);
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine(“The service is ready.”);
Console.WriteLine(“Press
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine(“An exception occurred: {0}”, ce.Message);
selfHost.Abort();
}
}
}
Calling service from client
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using ServiceModelSamples;
namespace ServiceModelSamples
{
class Program
{
static void Main(string[] args)
{
//Step 1: Create an endpoint address and an instance of the WCF Client.
IcalculatorClient client = new IcalculatorClient();
// Step 2: Call the service operations.
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine(“Add({0},{1}) = {2}”, value1, value2, result);
// Call the Subtract service operation.
value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine(“Subtract({0},{1}) = {2}”, value1, value2, result);
// Call the Multiply service operation.
value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine(“Multiply({0},{1}) = {2}”, value1, value2, result);
// Call the Divide service operation.
value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine(“Divide({0},{1}) = {2}”, value1, value2, result);
//Step 3: Closing the client gracefully closes the connection and cleans up resources.
client.Close();
IcalculatorClient client1 = new IcalculatorClient();
result = client1.Add(value1, value2);
Console.WriteLine(“Add({0},{1}) = {2}”, value1, value2, result);
result = client1.Divide(value1, value2);
Console.WriteLine(“Divide({0},{1}) = {2}”, value1, value2, result);
client1.Close();
Console.WriteLine();
Console.WriteLine(“Press
Console.ReadLine();
}
}
}
Get Laptop Battery Status using C# and WMI
In this article I will show you how to show battery status of laptop battery like its battery is discharging, charging, full etc. We will do this using WMI because WMI have power to answer questions about battery status .So let’s start with WMI.
To use this name space first of all we need to add reference to System.management by
Project Menu>>Add Reference.
after that at the top of the code use
using System.Management;
so that you can use of its classes .Now its simple to get information about any Windows user Account through querying ManagementObjectSearcher Class .
We can get all information about Laptop Battery through Win32_Battery class.
so we need to query on that class to get related Management object and then we just need to get various properties related to it . Here i have taken two labels one textbox with read only property and one progress bar and a timer control .
now to get battery status we need to code like below .
Dictionary
private void Form1_Load(object sender, EventArgs e)
{
StatusCodes = new Dictionary
StatusCodes.Add(1, “The battery is discharging”);
StatusCodes.Add(2, “The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging”);
StatusCodes.Add(3, “Fully Charged”);
StatusCodes.Add(4, “Low”);
StatusCodes.Add(5, “Critical”);
StatusCodes.Add(6, “Charging”);
StatusCodes.Add(7, “Charging and High”);
StatusCodes.Add(8, “Charging and Low”);
StatusCodes.Add(9, “Undefined”);
StatusCodes.Add(10,”Partially Charged”);
/* Set progress bar values and Properties */
progressBar1.Maximum = 100;
progressBar1.Style = ProgressBarStyle.Continuous;
timer1.Enabled = true;
ManagementObjectSearcher mos = new ManagementObjectSearcher(“select * from Win32_Battery”);
foreach (ManagementObject mo in mos.Get())
{
lblBatteryName.Text = mo["Name"].ToString();
UInt16 statuscode = (UInt16)mo["BatteryStatus"];
string statusString = StatusCodes[statuscode];
lblBatteryStatus.Text = statusString;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ManagementObjectSearcher mos = new ManagementObjectSearcher(“select * from Win32_Battery where Name=’”+lblBatteryName.Text+”‘”);
foreach (ManagementObject mo in mos.Get())
{
UInt16 statuscode = (UInt16)mo["BatteryStatus"];
string statusString = StatusCodes[statuscode];
lblBatteryStatus.Text = statusString;
/* Set Progress bar according to status */
if (statuscode == 4)
{
progressBar1.ForeColor = Color.Red;
progressBar1.Value = 5;
}
else if (statuscode == 3)
{
progressBar1.ForeColor = Color.Blue;
progressBar1.Value = 100;
}
else if (statuscode == 2)
{
progressBar1.ForeColor = Color.Green;
progressBar1.Value = 100;
}
else if (statuscode == 5)
{
progressBar1.ForeColor = Color.Red;
progressBar1.Value = 1;
}
else if (statuscode == 6)
{
progressBar1.ForeColor = Color.Blue;
progressBar1.Value = 100;
}
}
}
Here i have used few status only to show in progress bar you can code whatever you want to show in progress bar..
Thank you
A generic error occurred in GDI+
ISSUE :
System.Runtime.InteropServices.ExternalException: “A generic error occurred in GDI+.” Issue occurred: When you are trying to save the image.
SOLUTION:
The System.Runtime.InteropServices namespace provides a wide variety of members that support COM interop and platform invoke services. If you are unfamiliar with these services, see Interoperating with Unmanaged Code.
The System.Runtime.InteropServices namespace provides a collection of classes useful for accessing COM objects, and native APIs from .NET. The types in this namespace fall into the following areas of functionality: attributes, exceptions, managed definitions of COM types, wrappers, type converters, and the Marshal class.
A generic error occurred in GDI+, one of the most common error occured while saving the image into the directory, the error occured because of the several reasons including the permission on the folder to write, which can be done by right click on the folder and assign write permission to the user. Some times, you get this error when someone else is using the same file on which you are performing the operation, the better solution is to lock the file when it is use and dispose the object when you are done.Â
I have illustrated the series of cause and remedy in my article.
Please check this article for complete detail: http://tinyurl.com/25khl98
Your comments and suggestions are highly appreciated. kindly let me know if the tutorial is not able to solve your issue.
To get the more information about this error, please check this site http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.externalexception.aspx.
Thanks
Â
-
About the Author:
Anuj Tripathi
Visit my Blog: http://www.anujtripathi.net
When you lose, don’t lose the lesson.
Mothers are those wonderful people who can get up in the morning before the smell of coffee.
Article Source
How to Remove Spyware From a Computer Easily and Quickly?
Spyware can be a pain in the rear and if you feel that your computer has been infected with it then you shouldn’t delay when it comes to taking action. There is almost an endless supply of different types of spyware that can make your experience online chaotic.
Â
There are some spyware out there that can be considered a lot more dangerous than other types. The more dangerous spyware can ruin your life and computer. It can ruin your life by stealing important information that you have stored or typed onto your computer, and it can ruin your computer by causing it to slow down until it is eventually left unusable.
Â
Less dangerous spyware will annoy you by spamming your computer with unsolicited ads. If you are working form your computer these pop up-ads will definitely slow down your productivity. The worse part is, these unwanted advertisements will pop up as soon as you turn on your computer and will continue to pop up even when your not surfing the web.
Â
These are some of the reasons why it’s important for any person infected with this virus to learn how to remove spyware from a computer. When trying to remove spyware you can either do it manually or by installing a virus removal software made specifically for the job. Manual removal of spyware is a difficult and risky task if you are not a computer expert.
Â
Trying to remove spyware manually from your computer will cause more harm than good if you delete the wrong system files. If this happens then this mistake will cause your whole operating system to crash.
Â
It is a lot easier and less risky to use a good virus removal software to eliminate spyware from a computer. There are many out there but the best of the best are effective at detecting and removing spywares, user friendly, provides updates on new spyware regularly, won’t slow down the performance of your computer, and has firewall monitors to keep your computer from getting infected in the future.
Â
Virus/spyware removal software provide people who want to know how to remove spyware from a computer with the peace of mind they deserve when using their computer.
-
About the Author:
Have a try on professional Best Spyware Scanner.
Article Source
By providing cutting edge Website Application Development services PHP-techie is the best
PHP-techie an extensively experienced and global PHP Web Development Company based in India with strategic partners abroad offers world class services of effective web solutions in PHP Programming and website application development which solves critical and complex business problems. We use latest technology languages, databases, advanced programming and industry trends to develop website to help you reinforce your online business. We provide end to end solutions from front-end programming to backend programming and maintenance. With our technical capabilities we are able to deliver deployment of every complexity from simple script to complex application.
Â
We Offers Custom PHP mysql application development services Using PHP Smarty template, MVC framework, CakePHP, Rapid PHP Mysql, Zend Framework development by outsource PHP programming. Our PHP Programming Web development services are secure, reliable, professional looking; compatible and easy to use are effective and value-added. PHP-techie has expert and sizable team of PHP developers well versed in Linux Apache MySQL PHP (LAMP) & AJAX. Our PHP team is capable to develop a customized LAMP-based solution from considerably small website to complex internet application. We leverage the time and cost saving advantages of open source technologies to deliver full-featured, scalable and inexpensive web solutions. Our major domain experience is in Corporate / Business Information Websites, Retail / Ecommerce, Communities & Network, Dating, B2B / B2C Internet Portals, eLearning / Online Training, Real Estate, Media Distribution, Customer Management
Â
PHP-techie offers PHP Programming expert services as per various clients needs on affordable cost solutions with quality assurance of work by our efficient team, expertise and extensive understanding of latest technology, no budget overturn, robust Infrastructure, research & development, confidentiality of client information, finding right talents for quality work in quick time. Clients can hire PHP and MySQL developers from us for all their offshore web application development requirements. Choose PHP-techie for Global presence, International Quality Standards and environmental management, professional, responsive and bearing strong analytical skills, topping and straining for 100% client satisfaction, 24X7 presence, cost saving and making value addition, highly qualified, talented and expert team which helps code your imagination.
Â
Contact PHP-techie’s solutions were we enable businesses to leverage leading-edge technology to gain sustainable competitive advantage in today’s marketplace.
-
About the Author:
Contact Information:-
DRC Systems
409, Mauriya Atria,
Opp. Kalgi Flats and Atithi Dining Hall,
Bodakdev, Ahmedabad- 380054
Phone: 079-40027350
Â
PHP Web Development Company
PHP Web Development
Article Source
Facebook Like URL data Extract Using jQuery PHP and Ajax
You have seen in Facebook, that how we give a url and it extract data such as images, title and description. Here now you can get this amazing script at 99Points. You have seen amazing and popular facebook style tutorials which can help you to get some amazing effects on your websites. I have created this awesome tutorial which is 99% same as facebook style. Check the demo and download the source code.
I have get images and title using fopen method of php but for description I used get_meta_tags() function which returns meta tags of url. After getting all images I just put a loop and get all images which size is greater than 100px so that small images should not be included. I have created this tutorial separate from our facebook style wall posting and comment application and facebook profile edit. However if you want to add this functionality in that script just download all files and add your code.
All source files have been attached with downloads. Check the demo and use this awesome script.
Â
After getting all images I just put a loop and get all images which size is greater than 100px so that small images should not be included. I have created this tutorial separate from our facebook style wall posting and comment application and facebook profile edit. However if you want to add this functionality in that script just download all files and add your code.
There are many tutorials on facebook, youtube, jquery and other popular topics.
Â
-
About the Author:
Zeeshan Rasool is a web developer, blogger and technology lover who loves to work in latest technologies to create some interactive web pages. He is curently working on www.99Points.info
Article Source
New Application Development for Social Networking
Surging advances in software technology are bringing in new types of application development compatible with all browsers and operating systems. These are the Flex developers who have managed to bring in enhanced expression and interaction with the help of programs that finally end up bringing in more online traffic to websites. The huge flow of global data is supported by the development in Flex technology and the webpage need not go to the main server to display latest information.
High user interactivity with some great visual interface can be achieved with a Flex programming solution. The applications respond quickly and the user can experience rapid logic processing of business with a no-refresh look. Instead of the system crashing now and then, myriad types of data flow works can be supported with better synchronization. Flex components can be reused and the modules are tailor made for individual business requirements.
There is a wide array of components and containers available the library of the Flex web development that can range from color pickers and basic widgets like buttons to more advanced controls like an accordion pane, data grid and a rich text editor. Using application development components, developers can construct user interface, subclass them or use the API to create even newer components.
Developers that provide Flex web development services can take advantage of predefined interactions like the drag able columns on a data grid or control an application’s visual appearance better by using MXML. They can also fine tune the application for better responses to diverse user actions as well as customize the looks using Transitions and View States. Using inbuilt supports they can attach custom visual assets and literally customize the feel and look of an application.
For greater Flexibility of working with data, the user interface is automatically updated making it easier for applications to be responsive while waiting for server results. This has become necessary these days as social networking is at an all time high. Video chats and live interaction between people have grown largely due to Flex programming and all the major social networking sites rely on customized user interactive services. Developers are taking advantage of this application to meet future challenges.
-
About the Author:
This article is written by a technical writer, working at SynapseIndia, a Flex application development company in India offering affordable Flex programming solution to worldwide clients. For more details on Flex developers please, contact us.
Article Source