存档

文章标签 ‘C#’

C#截屏代码(截取全屏幕)

2009年7月30日
C#截屏代码(截取全屏幕)已关闭评论

代码很简单,使用Bitmap类的程序来获取屏幕图像,同时显示在对话框上,如果自己建立对话框,稍微做些改动就能直接编译通过。

使用C#截取全屏的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button cmdCapture;
private System.Windows.Forms.PictureBox pictureBox1;

public Form1() {
InitializeComponent();

}

private void cmdCapture_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();

Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
g.Dispose();
pictureBox1.Image = bmp;
pictureBox1.Size = bmp.Size;
}

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.cmdCapture = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(8, 8);
this.panel1.Name = “panel1”;
this.panel1.Size = new System.Drawing.Size(270, 233);
this.panel1.TabIndex = 0;
//
// cmdCapture
//
this.cmdCapture.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdCapture.Location = new System.Drawing.Point(169, 249);
this.cmdCapture.Name = “cmdCapture”;
this.cmdCapture.Size = new System.Drawing.Size(110, 30);
this.cmdCapture.TabIndex = 1;
this.cmdCapture.Text = “Capture Screen”;
this.cmdCapture.UseVisualStyleBackColor = true;
this.cmdCapture.Click += new System.EventHandler(this.cmdCapture_Click);
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = “pictureBox1”;
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(290, 288);
this.Controls.Add(this.cmdCapture);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font(“Tahoma”, 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = “Form1”;
this.Text = “Screen Capture”;
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);

}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}

//附  Graphics::CopyFromScreen  (Int32, Int32, Int32, Int32, Size)的方法说明

C#, IT技术 ,

c# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用

2009年7月30日
c# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用已关闭评论

大家好,相信大家都使用过代理IP上过网,但是有的IP一两天就失效了。要一个一个的手工去试打开IE,关闭IE,多烦啊。
有了这篇文章就好了。我们可以使用C#的HttpWebRequest,HttpWebResponse 来代理验证,谢谢大家评论指导!
呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!我不说了大家自己看
public void yanzhen(string str, int port)
{
WebProxy proxyObject = new WebProxy(str, port);//str为IP地址 port为端口号
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(“http://www.whatismyip.com.tw/”);
Req.Proxy = proxyObject; //设置代理

HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();
string str = “”;
string OkStr = “”;
Encoding code = Encoding.GetEncoding(“UTF-8”);
using (StreamReader sr = new StreamReader(Resp.GetResponseStream(), code))
{
if (sr != null)
{
try
{
str = sr.ReadToEnd();
StringSub.substr(str, “<h2>”, “</h2>”, 0);
str = str.Substring(str.IndexOf(start) + start.Length);
OkStr = str.Substring(0, str.IndexOf(last));
MessageBox.Show(“验证成功!显示IP为” + OkStr);
}
catch
{
MessageBox.Show(“文件读取失败!”);
}
finally
{
sr.Close();
}
}
}
}

呵呵,是不是很简单啊,其实这段代码改一下还可以做采集器,小偷等程序!

from问题解决园http://wenti.cnblogs.com/    http://www.cnblogs.com/wenti/archive/2009/07/22/wenti_3.html

IT技术 ,