суббота, 23 апреля 2011 г.

Taking Website Screenshots With The WebBrowser Control

Sample code on how to take screenshots of websites, resize them to thumbnails and save them as PNG file onto the harddrive.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Drawing.Imaging;
  10. using System.Drawing.Drawing2D;
  11. using System.IO;
  12. using System.Runtime.InteropServices;
  13.  
  14. namespace ScreenshotTaker
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void btnLoad_Click(object sender, EventArgs e)
  24.         {
  25.             webBrowser1.Navigate("http://www.geekpedia.com");
  26.         }
  27.  
  28.         private void btnSnap_Click(object sender, EventArgs e)
  29.         {
  30.             // The size of the browser window when we want to take the screenshot (and the size of the resulting bitmap)
  31.             Bitmap bitmap = new Bitmap(1024768);
  32.             Rectangle bitmapRect = new Rectangle(001024768);
  33.             // This is a method of the WebBrowser control, and the most important part
  34.             webBrowser1.DrawToBitmap(bitmap, bitmapRect);
  35.  
  36.             // Generate a thumbnail of the screenshot (optional)
  37.             System.Drawing.Image origImage = bitmap;
  38.             System.Drawing.Image origThumbnail = new Bitmap(12090, origImage.PixelFormat);
  39.  
  40.             Graphics oGraphic = Graphics.FromImage(origThumbnail);
  41.             oGraphic.CompositingQuality = CompositingQuality.HighQuality;
  42.             oGraphic.SmoothingMode = SmoothingMode.HighQuality;
  43.             oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
  44.             Rectangle oRectangle = new Rectangle(0012090);
  45.             oGraphic.DrawImage(origImage, oRectangle);
  46.  
  47.             // Save the file in PNG format
  48.             origThumbnail.Save("Screenshot.png", ImageFormat.Png);
  49.             origImage.Dispose();
  50.         }
  51.     }
  52. }

How to check JQuery object is null



This is simple and no need to write post for it. You may feel same right? But, this is the question I received from almost 10 people till now. So, I thought of writing a post on it. So that, it may help people who are looking for the same through out the world.
By default JQuery returns object when you declare $("$id") or $(".class"). If you write code for it as below, then that's wrong.
  1. if($("#id") != null)  
  2. {  
  3. //Write code if the object is not null  
  4. }  
  5.   
  6. if($(".class") != null)  
  7. {  
  8. //Write code if the object is not null  
  9. }  
If you write the above code for checking null condition then if condition always success and will execute code inside of the if condition. So, the correct solution is,
  1. if($("#id").length > 0)  
  2. {  
  3. //Write code if the object is not null  
  4. }  
  5.   
  6. if($(".class").length > 0)  
  7. {  
  8. //Write code if the object is not null  
  9. }  
It tries to find all objects which has the given id or class and if any exists then the length will be equal to the number of times the id or class occurred. So, if the length is zero then it's nothing but the id or class don't exist and the object is null.
Hope, this solved your problem and this is a new tip for today. Is this helpful?

пятница, 22 апреля 2011 г.

Сравнение Timer с DispatcherTimer

Windows.Forms.Timer uses the windows forms message loop to process timer events. It should be used when writing timing events that are being used in Windows Forms applications, and you want the timer to fire on the main UI thread.

DispatcherTimer is the WPF timing mechanism. It should be used when you want to handle timing in a similar manner (although this isn't limited to a single thread - each thread has its own dispatcher) and you're using WPF. It fires the event on the same thread as the Dispatcher.

In general, WPF==DispatcherTimer and Windows Forms==Forms.Timer.

That being said, there is also System.Threading.Timer, which is a timer class that fires on a separate thread. This is good for purely numerical timing, where you're not trying to update the UI, etc.

среда, 6 апреля 2011 г.

GridView.PagerTemplate Property


Specifies the template to use for the pager row in a GridView control.

Syntax



   <pagertemplate>
      ... template definition here
   

Property Value

An ITemplate interface that defines how the pager row of a GridView control is rendered.
The property is read/write with no default value.

Remarks

The PagerTemplate describes the layout of elements to render in the pager section of a GridView control.
When the paging feature is enabled ( AllowPaging is set to true ), a pager row is displayed in the GridView that contains the controls to enable users to navigate to the different pages in the control. The PagerTemplate enables customizing this paging interface.
 NOTE: When the PagerTemplate property is set, it overrides the built-in pager row interface.
To specify a template for the pager section of a GridView, declare a  element between the opening and closing tags of the control. You can then list the contents of the template between the opening and closing  ...  tags.
In addition, the appearance for this template can be set using the PagerStyle property.
Typically, button controls are added to the pager template to perform the paging operations. The GridView control performs a paging operation when a button control with its CommandName property set to Page is clicked. The button's CommandArgument property determines the type of paging operation to perform. The following table lists the command argument values supported by the GridView control.
CommandArgumentDescription
NextNavigates to the next page.
PrevNavigates to the previous page.
FirstNavigates to the first page.
LastNavigates to the last page.
Integer valueNavigates to the specified page number.
 NOTE: The PagerTemplate item cannot be data bound.

Paging In Gridview Using PagerTemplate


01<asp:GridView ID="gv" Runat="Server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"
02BorderColor="#000080"
03BorderWidth="2px"
04HorizontalAlign="Center"
05Width="90%" AllowPaging=true BackColor=Gray  PagerSettings-Position=TopAndBottom  >
06<Columns>
07<asp:BoundField HeaderText="localityID" DataField="localityid"  />
08<asp:BoundField HeaderText="localityName" DataField="localityname" />
09 
10Columns>
11 
12<PagerTemplate>
13<asp:LinkButton CommandName="Page" CommandArgument="First"
14ID="LinkButton1" runat="server" Style="color: white">
15« Firstasp:LinkButton>
16<asp:LinkButton CommandName="Page" CommandArgument="Prev"
17ID="LinkButton2" runat="server" Style="color: white">
18Prev
19[Records <%= gv.PageIndex * gv.PageSize%>-<%= gv.PageIndex * gv.PageSize + gv.PageSize - 1%>]
20<asp:LinkButton CommandName="Page" CommandArgument="Next"
21ID="LinkButton3" runat="server" Style="color: white">
22Next >asp:LinkButton>
23<asp:LinkButton CommandName="Page" CommandArgument="Last"
24ID="LinkButton4" runat="server" Style="color: white">
25Last »asp:LinkButton>
26PagerTemplate>
27asp:GridView>
28<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT * FROM locality"
29ConnectionString="<%$ ConnectionStrings:ConnectionString %>" />