|
-
Aug 17th, 2009, 08:06 PM
#1
Thread Starter
Frenzied Member
progressBar
Hi,
I currently have a code, and i would like my progress bar to increase while the current code is running. How can i do it?
Thx
request Code:
using System; using System.IO; using System.Net; using System.Text; namespace Examples.System.Net { public class WebRequestPostExample { public static void Main () { // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx "); // Set the Method property of the request to POST. request.Method = "POST"; // Create POST data and convert it to a byte array. string postData = "This is a test that posts this string to a Web server."; byte[] byteArray = Encoding.UTF8.GetBytes (postData); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream (); // Write the data to the request stream. dataStream.Write (byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close (); // Get the response. WebResponse response = request.GetResponse (); // Display the status. textbox1.text = (((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream (); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader (dataStream); // Read the content. string responseFromServer = reader.ReadToEnd (); // Display the content. textbox2.text (responseFromServer); // Clean up the streams. reader.Close (); dataStream.Close (); response.Close (); } } }
Last edited by met0555; Aug 17th, 2009 at 08:22 PM.
-
Aug 17th, 2009, 08:08 PM
#2
Re: progressBar
Why is this even here...? This is the wrong language!
-
Aug 17th, 2009, 08:11 PM
#3
Re: progressBar
... comin back around to one of my posts, as formless has provided in his sig
met0555, a progress bar wont be of any use here, everything's running in the sub Main which means this is a console app, no form for the progress bar to be on.
You could get the Windows API Code Pack for VS 2008 and if the user's running Win7 your app can use the TaskBar Icon ProgressBar (which is really neat, btw)
-
Aug 17th, 2009, 08:14 PM
#4
Thread Starter
Frenzied Member
Re: progressBar
Hi,
Sorry for C# and consol applicatoin, but i'm using the exact code but changed few lines so it works with windows apllication. If you can provide me the correct code for the progressBar with VB.net or C# it's ok with me.
thx
-
Aug 17th, 2009, 08:17 PM
#5
Re: progressBar
 Originally Posted by met0555
Hi,
Sorry for C# and consol applicatoin, but i'm using the exact code but changed few lines so it works with windows apllication. If you can provide me the correct code for the progressBar with VB.net or C# it's ok with me.
thx
So you're using different code than what you posted, you thought that would be useful... how?
Also, wouldn't it make more sense to either post that in the C# forum -or- post vb code of it here in the vb forum?
We can't help you if you don't apply at least some common sense.
-
Aug 17th, 2009, 08:25 PM
#6
Thread Starter
Frenzied Member
Re: progressBar
Hi,
ok, here it is.
vb Code:
Imports System Imports System.IO Imports System.Net Imports System.Text Namespace Examples.System.Net Public Class WebRequestGetExample Public Shared Sub Main() ' Create a request for the URL. Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html") ' If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials ' Get the response. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) ' Display the status. textbox1.text = (response.StatusDescription) ' Get the stream containing content returned by the server. Dim dataStream As Stream = response.GetResponseStream() ' Open the stream using a StreamReader for easy access. Dim reader As New StreamReader(dataStream) ' Read the content. Dim responseFromServer As String = reader.ReadToEnd() ' Display the content. textbox2.text = (responseFromServer) ' Cleanup the streams and the response. reader.Close() dataStream.Close() response.Close() End Sub 'Main End Class 'WebRequestGetExample End Namespace
-
Aug 17th, 2009, 08:52 PM
#7
Re: progressBar
This still isn't a vb form. It's still a console app by nature of everything being run in the Main() sub. Just because you reference textboxes doesn't mean they're actually there.
-
Aug 17th, 2009, 08:58 PM
#8
Thread Starter
Frenzied Member
Re: progressBar
Well ok, can you please show me how to use the progress bar while a code is running?
thanks
-
Aug 17th, 2009, 11:09 PM
#9
Re: progressBar
Put a ProgressBar on the form, set it's Min and Max values then in the code use it's .Value property to set the bar's position between the Min and the Max.
What value you set it to and when depends on how you want it to work which we can't help you with, you'll need to play with it for a while.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|