Showing posts with label Windows Form. Show all posts
Showing posts with label Windows Form. Show all posts

16 February 2015

Hi, today I will demonstrate you how to download / pull image from another website.

For this it is required for use below namespace :

 using System.Net;  
 using System.IO;  


Now for c# part

 private void DownloadImage(string imageURL, string FolderAndFile_NameToDownload)  
   {  
     HttpWebRequest lxRequest = (HttpWebRequest)WebRequest.Create(imageURL);  
     String lsResponse = string.Empty;  
     using (HttpWebResponse lxResponse = (HttpWebResponse)lxRequest.GetResponse())  
     {  
       using (BinaryReader reader = new BinaryReader(lxResponse.GetResponseStream()))  
       {  
         Byte[] lnByte = reader.ReadBytes(1 * 1024 * 1024 * 10);  //Buffer
         using (FileStream lxFS = new FileStream(Server.MapPath(FolderAndFile_NameToDownload), FileMode.Create))  
         {  
           lxFS.Write(lnByte, 0, lnByte.Length);  
         }  
       }  
     }  
   }  

that's all.

Two thing too keep in mind.
1)  imageURL : apply image url which you want to download.
2) FolderAndFile_NameToDownload : apply FolderName with FileName where you want to download that image in your website.

Above code can be apply fro Website as wall as Windows Form application.

02 November 2009

 

Visual Basic Power Packs 3.0 have very cool same as we web application, named DataRepeater.

lets do some cool stuff with DataRepeater control.

  • Add Data source.
  • Add Combobox in datarepeater control
  • Hide show controls runtime in datarepeater control

 

DataRepeater

See the above image, We have a button, a DataRepeater control and in data  repeater control we have a textbox, a combo box and a label which will hide and show runtime by selecting value of combobox.

So lets start, how to do this.

 

Create a class to save data, I am not using any DataTable for this example.

public class data1 : List<data1>
    {
        private string mName;
        private string mDdlValue;

        public data1()
        {
        }

       public string Name
        {
            get { return mName; }
            set { mName = value; }
        }

        public string DdlValue
        {
            get { return mDdlValue; }
            set { mDdlValue = value; }
        }
    }
}

In above code we have two property “Name” and “DdlValue” and it is inherited with “List” to bind data.

Now lets bind that controls with data1 class

I will use Form_Load  event to do this.

/// <summary>
/// data1 variable declaration in Form Class
/// </summary>
private data1 objData = new data1();

 

private void Form1_Load(object sender, EventArgs e)
{
    ///Bind Textbox with Name property
    tbName.DataBindings.Add(new System.Windows.Forms.Binding("Text", objData, "Name"));

    ///Bind Combo box with DdlValue property
    comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", objData, "DdlValue"));
}

 

And databind “objData” to DataRepeater1 control, I will use button click event to do this.

private void button2_Click(object sender, EventArgs e)
{
    objData.Add(new data1());
    dataRepeater1.DataSource = null;
    dataRepeater1.DataSource = objData;
}

 

Ok to now when  you will click on button2, it will add new item in “objData” and then, bind it to dataRepeater1 control.

But still we have to add item in combobox, So we need to use “ItemCloned” event to do this.

private void dataRepeater1_ItemCloned(object sender, Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
{
    ComboBox c1 = (ComboBox)e.DataRepeaterItem.Controls.Find("comboBox1", true)[0];

    c1.Items.Add("sa1");
    c1.Items.Add("sa2");
    c1.Items.Add("sa3");
    c1.Items.Add("sa4");
    c1.Items.Add("sa5");
}

you can see that now there are 5 item in combo box.

and finally let hide and show a label control dynamically, Here in example the logic is, when use select “sa2” from combo box it will show the label else it will be hide.

We have to use DrowItem event to do this.

private void dataRepeater1_DrawItem(object sender, DataRepeaterItemEventArgs e)
{
    if (objData[e.DataRepeaterItem.ItemIndex].DdlValue == "sa2")
    {
        ((Label)e.DataRepeaterItem.Controls.Find("label2", true)[0]).Text = "this is second option";
    }
    else
    {
        ((Label)e.DataRepeaterItem.Controls.Find("label2", true)[0]).Visible = false;
    }
}

So this is good to run our program, but one more thing, If you want to hide show label directly when use change value from dropdown list, you have to add SelectedIndexChanged to combobox1.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox cbo = ((ComboBox)(sender));

    DataRepeaterItem prnt = (DataRepeaterItem)(cbo.Parent);

    Label objLavel = ((Label)(prnt.Controls.Find("Label2", true)[0]));
    if (cbo.SelectedIndex == -1)
    {
        return;
    }
    if (cbo.Text == "sa2")
    {
        objLavel.Visible = true;
        objLavel.Text = cbo.Text;
    }
    else
    {
        objLavel.Visible = false;
    }
}

So just press F5 to run this program.

So this is a very simple example to work with dataRepeater control, you can utilize your requirement in it and have some cool looking information in your window application!

19 September 2007

Create shapes on form as Visual Basic 6.0 can do that directly on the form.

Power Pack 2.0 is a line, shape controls, printform component, and printer compatibility library.

It has 4 controls.

There are so many property and event.

Download Microsoft Visual Basic 2005 Power Packs 2.0

14 May 2007

Now there is a new web site named WindowsClient.net.
Its a comunity to learning Wondows Form and WPF (Windows Presentation Foundation).

Find help to develop rich client development on Windows Form with .NET framework.

06 August 2006


It is a grate online book to learn DataBinding Controls with Dasktop Application. it is a grate for beginers. you can found many many examples there, which are so easy to understand.

i found this link form
http://www.itzero.com/0day/0day_ebook_OL_read/
0day_Online_Microsof/Index.html

there is also many other usefull information.