C#: Capture a ScreenShot
The following code demonstrates one method of capturing a screenshot. The method displayed returns a screenshot of the entire screen as a bitmap.
private Bitmap GetScreenShot()
{
// set screenshot bounds to match the size of the screen
Rectangle bounds = Screen.PrimaryScreen.Bounds;
// crate a bitmap with the dimensions of the sreen
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
}
return bitmap;
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = GetScreenShot();
}
Microsoft Dynamics Nav: Adding a Record through Web Services

- Create and XMLPort for transferring the data. Note: For this example the MaxOccurs property of the element should be set to ‘One’ to set a “one record limit”. It is possible to set multiple records

- Create a CodeUnit and add functions that will be used to through the Web Service
![GetCustomers(CustomerCode : Code[10];VAR CustXML : XMLport GetSetCustomer) Customer.SETRANGE("No.", CustomerCode); CustXML.SETTABLEVIEW(Customer); SetCustomers(VAR CustXML : XMLport GetSetCustomer) : Integer // Return 1 if import was successful IF CustXML.IMPORT THEN EXIT(1) ELSE EXIT(0);](/blog/image.axd?picture=2011%2f9%2fgetset1.png)
- Publish the CodeUnit as a Web Service

- Create a .NET Application and register the Microsoft Dynamics Nav Web Service
- Create the code that interacts with the registered Web Service (Note: This code is for basic demonstration only and additional coding practices should be applied for production code)
GetSetCustomers_Binding ws;
private void Form1_Load(object sender, EventArgs e)
{
ws = new GetSetCustomers_Binding();
ws.UseDefaultCredentials = true;
ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS%20USA,%20Inc./Codeunit/GetSetCustomers";
}
private void btnGet_Click(object sender, EventArgs e)
{
Customer cust = new Customer();
Customers cs = new Customers();
// in nav the XML should be set to maxoccurence of 1 so that we only return one
//customer
ws.GetCustomers(txtNo.Text, ref cs);
cust = cs.Customer[0];
txtName.Text = cust.Name;
txtPhone.Text = cust.Phone_No_;
txtContact.Text = cust.Contact;
}
private void btnSet_Click(object sender, EventArgs e)
{
Customers cs = new Customers();
Customer cust = new Customer();
List<Customer> custlist = new List<Customer>();
cust.No_ = txtNo.Text;
cust.Name = txtName.Text;
cust.Phone_No_ = txtPhone.Text;
cust.Contact = txtContact.Text;
custlist.Add(cust);
cs.Customer = custlist.ToArray();
if (ws.SetCustomers(ref cs) == 0)
{
MessageBox.Show("No Good.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
}
The sample application referenced in this post can be downloaded >>>here<<<.
View the following posts for additional examples:
Microsoft Dynamics Nav: Retrieving a set of Records through Web Services
Microsoft Dynamics Nav: Using an XMLPort as a .NET DataSource
Microsoft Dynamics Nav: Retrieving a set of Records through Web Services
In a previous post ( Microsoft Dynamics Nav: Using an XMLPort as a .NET DataSource and Microsft Dynamics Nav: Export XMLPort to File) I had demonstrated how to return a set of records, using Web Services, from Microsoft Dynamics Nav with an XMLPort as a dataset.

The following example demonstrates returning a filtered set of records from Microsoft Dynamics Nav through Services.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
GetCustomers_Binding ws;
Customers customers;
BindingSource bs;
private void Form1_Load(object sender, EventArgs e)
{
ws = new GetCustomers_Binding();
ws.UseDefaultCredentials = true;
ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS%20USA,%20Inc./Codeunit/GetCustomers";
customers = new Customers();
bs = new BindingSource();
BindData(textBox1.Text);
}
private void BindData(string salespersoncode)
{
ws.GetCustomers(salespersoncode, ref customers);
dataGridView1.DataSource = bs;
bs.DataSource = customers.Customer;
}
private void button1_Click(object sender, EventArgs e)
{
BindData(textBox1.Text);
}
}
![GetCustomers(SalesPerson : Code[10];VAR CustXML : XMLport Customer_Export) IF SalesPerson <> '' THEN Customer.SETRANGE("Salesperson Code",'PS'); CustXML.SETTABLEVIEW(Customer);](/blog/image.axd?picture=2011%2f9%2fgercustomers_2.png)
The sample application referenced in this post can be downloaded >>>here<<<.