Archive

Archive for the ‘C#’ Category

Expansion DirectoryInfo.GetFiles() method

August 6, 2011 Leave a comment

Function DirectoryInfo.GetFiles() hỗ trợ khá nhiều overload tuy nhiên vẫn khá thiếu sót khi search file với overload GetFile(string parttern) thì chỉ trả về 1 loại file. Việc combine file extension là điều không thể.
Ví dụ, bạn có thể get tất cả các file txt bằng method _directioryInfo.GetFiles(“*.txt”), tuy nhiên sẽ bó cái tay nếu muốn sử dụng _directoryInfo.GetFiles(“*.txt|*.doc”) chẳng hạn, đều này là Impossible ^^ ./ Read more…

FastFrog v1.0 – Fast Download Mediafire.com

July 23, 2011 10 comments

image Mấy hôm nay bức bối vì mấy cái tool Get Direct Link Mediafire 3.0 trên mạng bắt đầu giở chứng không Get được link nữa, còn cả kho film trên MF mà đành đứng nhìn, thôi thì viết lấy một cái mà dùng vậy ;)
Read more…

Categories: C#, Front-End, Tip & Trick

Thao tác với Webcam sử dụng Aforge Framework

July 6, 2011 Leave a comment

AForge.NET FrameworkAForge.NET is a C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence – image processing, neural networks, genetic algorithms, machine learning, robotics, etc.

Aforge.NET Framework (gọi tắt là AF) 2.1.2 is now available [Download].

More Infomation : http://aforgenet.com/

Trong bài viết này mình sẽ hướng dẫn cách lấy frame từ webcam stream bằng cách sử dụng Aforge.NET Framework.

Đầu tiên, download các dll từ link trên và Reference vào Project.

Khởi tạo đối tượng videoSource có kiểu FilterInfoCollection và pass giá trị cho Contrustor. Lớp FilterInfoCollection trong AF được dùng để thể hiện tập hợp các đối tượng DirectShow đã được phân loại, như ở code dưới thì videoSources sẽ là tập hợp các đối tượng VideoInputDevice, dĩ nhiên là có Webcam trong đó ./

Read more…

Categories: C#, Tip & Trick

Expansion DirectoryInfo.GetFiles() method

December 7, 2010 Leave a comment

Function DirectoryInfo.GetFiles() hỗ trợ khá nhiều overload tuy nhiên vẫn khá thiếu sót khi search file với overload GetFile(string parttern) thì chỉ trả về 1 loại file. Việc combine file extension là điều không thể.
Ví dụ, bạn có thể get tất cả các file txt bằng method _directioryInfo.GetFiles(“*.txt”), tuy nhiên sẽ bó cái tay nếu muốn sử dụng _directoryInfo.GetFiles(“*.txt|*.doc”) chẳng hạn, đều này là Impossible ^^ ./ Read more…

Categories: C#

Thao tác với Webcam sử dụng Aforge Framework

March 24, 2010 Leave a comment

AForge.NET is a C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence – image processing, neural networks, genetic algorithms, machine learning, robotics, etc.

AForge.NET FrameworkAforge.NET Framework (gọi tắt là AF) 2.1.2 is now available [Download].

More Infomation : http://aforgenet.com/

Trong bài viết này mình sẽ hướng dẫn cách lấy frame từ webcam stream bằng cách sử dụng Aforge.NET Framework.

Đầu tiên, download các dll từ link trên và Reference vào Project.

Khởi tạo đối tượng videoSource có kiểu FilterInfoCollection và pass giá trị cho Contrustor. Lớp FilterInfoCollection trong AF được dùng để thể hiện tập hợp các đối tượng DirectShow đã được phân loại, như ở code dưới thì videoSources sẽ là tập hợp các đối tượng VideoInputDevice, dĩ nhiên là có Webcam trong đó ./

Read more…

Categories: C#, Tip & Trick

FastFrog v1.0 – Fast Download Mediafire.com

March 5, 2010 9 comments

image Mấy hôm nay bức bối vì mấy cái tool Get Direct Link Mediafire 3.0 trên mạng bắt đầu giở chứng không Get được link nữa, còn cả kho film trên MF mà đành đứng nhìn, thôi thì viết lấy một cái mà dùng vậy ;)
Read more…

Lập trình với CustomEvent và UserControl

June 26, 2009 Leave a comment

Đây là hội thi làm trái cây mau chín do bác B.F lần đầu tiên tổ chức :) )

Đùa chơi một chút với các em trái cây để tìm hiểu sơ sơ về cái CustomEvent và UserControl trong C#.
Giả định em có 2 trái cây Chanh chua với Chùm Nho ở dưới, cả 2 trái này đều thuộc một loại gọi là loại … Trái cây ^^.
Mỗi trái cây thì có những thuộc tính thế này :
  • Tên trái cây
  • Màu sắc khi non
  • Màu sắc khi chín
  • Thời gian non -> chín



Bên cạnh đó khi em nó chín thì em nó cũng tạo ra một Event gọi là Event “Quả đã chín” để các anh biết mà hái.


Em mà chín thì em đổi màu :) )

Tạo một đối tượng trái cây kiểu UserControl, đưa các thuộc tính cần thiết cho “Trái” :

public partial class UcFruit : UserControl{private string _fruitName;private Color _colorUnMature;private Color _colorMature;private int _timeToMature;

public UcFruit(){InitializeComponent();}

...}

Xây dựng Delegate để tạo Event

// Khái niệm Delegate có nhiều điểm tương đồng với con trỏ hàm trong C++// Định nghĩa một delegate là định nghĩa một "câu móc" móc các sự kiện và các// hàm thụ lý sự kiện với nhau.

public delegate void FruitMatureHandler(object sender, FruitMatureArgs fruit);

/// /// Đây là Entities/// public class FruitMatureArgs:EventArgs{private string _fruitName;private Color _colorUnMature;private Color _colorMature;private int _timeToMature;

public FruitMatureArgs(){}

public FruitMatureArgs(string fruitName, Color colorUnMature, Color colorMature, int timeToMature){_fruitName = fruitName;_colorUnMature = colorUnMature;_colorMature = colorMature;_timeToMature = timeToMature;}

public string FruitName{get { return _fruitName; }set { _fruitName = value; }}

public Color ColorUnMature{get { return _colorUnMature; }set { _colorUnMature = value; }}

public Color ColorMature{get { return _colorMature; }set { _colorMature = value; }}

public int TimeToMature{get { return _timeToMature; }set { _timeToMature = value; }}}

Xây dựng Event và hàm RaiseEvent
Event quả chín sẽ được quẳng ra khi quả đến thời gian “chín”, tức là Click đủ _timeToMature lần, xử lý sự kiện Nút_Click để mỗi lần Click giảm thời gian chờ đi 1 đơn vị.


// Khai báo sự kiện Trái cây chín, còn Raise ra khi nào là tùy mình// Nhớ là phải để Delegate và Event Public thì bên ngoài mới dùng được.public event FruitMatureHandler FruitMature;

// Hàm RaiseEvent - quăng sự kiện Quả chín ra để bên ngoài bắt lấy.// Hàm này chỉ cần bấm chuột vào event FruitMature ở trên là Resharper nó tự Generate,// ko thì chịu khó chép lại :) )private void InvokeFruitMature(FruitMatureArgs fruit){FruitMatureHandler mature = FruitMature;if (mature != null) mature(this, fruit);}

// Click vô để giảm thời gian chờ quả chínprivate void btnFruitClick_Click(object sender, EventArgs e){// Nếu hết thời gian chờ TimeToMature thì rung cây "Invoke" cho "văng" ra sự kiện quả chínif (_timeToMature <= 0)             {                 // Thông báo sự kiện được sinh ra                 InvokeFruitMature(new FruitMatureArgs(_fruitName, _colorUnMature, _colorMature, _timeToMature));                 // Đổi màu cho quả                 btnFruitClick.BackColor = _colorMature;             }             // Ngược lại giảm thời gian chờ đi 1 đơn vị.             _timeToMature -= 1;         }

Xong UserControl, giờ qua Form

public partial class Form1 : Form{public Form1(){InitializeComponent();}

private void Form1_Load(object sender, EventArgs e){// Qủa chanh khi còn non thì màu Green, chín màu Yellow - Đồng ý ko ^^var quaChanh = new UcFruit();quaChanh.FruitName = "Chanh chua";quaChanh.ColorUnMature = Color.Green;quaChanh.ColorMature = Color.Yellow;quaChanh.TimeToMature = 5;

// Quả nho non màu xanh, chín màu đỏ :">var quaNho = new UcFruit();quaNho.FruitName = "Chùm nho";quaNho.ColorUnMature = Color.Green;quaNho.ColorMature = Color.Red;quaNho.TimeToMature = 10;

//Treo quả chanh với quả nho lên Form , gọi là lên "Cành" cho nó văn vẻthis.flowLayoutPanel1.Controls.Add(quaChanh);this.flowLayoutPanel1.Controls.Add(quaNho);

//Đặt hàng khi nào Chanh Chín thì gọi hàm Hái để hái chanhquaChanh.FruitMature += Picker;

//Đặt hàng khi nào Nhon chín thì gọi hàm Hái để hái nhoquaNho.FruitMature += Picker;

}

void Picker(object sender, FruitMatureArgs fruit){MessageBox.Show("Em " + fruit.FruitName + " chín rồi mấy anh ơi !");// Hái hái hái}

}

Comment đầy đủ trong code ở trên, có thể tham khảo bằng sourcecode của Form tại đây : http://www.mediafire.com/?hkhwmiz2ziz

Categories: C#

Cách sử dụng điều kiểm ListBox trong C#

June 24, 2009 4 comments

Cách sử dụng điều kiểm ListBox trong C# :

Cần quan tâm 2 thuộc tính :
- DataSource
- DataMember
- ValueMember
Để đưa một tập hợp các phần tử vào một ListBox có nhiều cách, hoặc Add từng phần tử, hoặc đưa một “cục” dữ liệu vào cho nó.
Đưa từng cái thì cứ tạo từng object ListItem, fill đầy đủ thông tin rồi listView.Add(ListItem).

Để Add cả cục, đầu tiên cần chuẩn bị “source” cho ListBox,
Source có thể là một mảng (Array) hay một Danh sách (List) các đối tượng.
Ví dụ sau add các đối tượng vào ListBox1 trên form.


public class Model
{
private int id;
private string userName;
private string address;

public Model()
{
}

public Model(int id, string userName, string address)
{
this.id = id;
this.userName = userName;
this.address = address;
}

public int Id
{
get { return id; }
set { id = value; }
}

public string UserName
{
get { return userName; }
set { userName = value; }
}

public string Address
{
get { return address; }
set { address = value; }
}
}

Giả sử có lớp Model mô tả đối tượng cần đưa vào.
Chuẩn bị một “source” là một danh sách khoảng vài phần tử – ở đây là dữ liệu mẫu nên tạo tại chỗ, trên thực tế List lấy từ các hàm bên ngoài vào.

List lst = new List();
lst.Add(new Model(1,"Hoai An","Hue"));
lst.Add(new Model(2,"Bx yeu","Thanh Hoa"));
lst.Add(new Model(3,"Ula ula","Paracetamol"));


// Đưa Source vào List thông qua thuộc tính DataSource của ListBox
listBox1.DataSource = lst;
// Display Member : Chỉ ra thuộc tính nào của Object sẽ được hiển thị lên List
listBox1.DisplayMember = "UserName";
//Value Member : Chỉ ra thuộc tính nào sẽ trả về khi Select.
listBox1.ValueMember = "Id";

Sau khi add xong sẽ thấy thể hiện trên List là các thông tin của thuộc tính Username, khi Click vào sẽ trả về Id.

private void listBox1_Click(object sender, EventArgs e)
{
MessageBox.Show(listBox1.SelectedValue.ToString());
}


Categories: C#
Follow

Get every new post delivered to your Inbox.

Join 39 other followers