|
<br />
public partial class Form1 : Form<br />
{<br />
WebClient wc = new WebClient();<br />
public Form1()<br />
{<br />
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);<br />
InitializeComponent();<br />
}<br />
void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)<br />
{<br />
pb.Value=e.ProgressPercentage;<br />
<br />
}<br />
private void load_url(string url)<br />
{<br />
<br />
wc.DownloadData(url);<br />
<br />
}<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
load_url(tblink.Text);<br />
}<br />
<br />
}<br />
Hi,
The problem with the above code is that the following method is never called..
void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e)<br />
{<br />
pb.Value=e.ProgressPercentage;<br />
<br />
}<br />
so the progressBar(pb) never get updated...Any Ideas what I am doing wrong?
I am using .Net Framework v 2.0
Regards
Q@!$3r
|
|
|
|
|
The documentation of the DownloadProgressChanged event clearly states that the event only occurs, if you execute the download asynchronously. Therefore, you need to replace wc.DownloadData(url); with wc.DownloadDataAsync(url); .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
I need to set table header forecolor and backcolor properties:
using System.Windows.Forms;
DataGridTableStyle tableStyle = new DataGridTableStyle();
Desktop td = new Desktop();
td.GetColors(tableStyle.HeaderForeColor,
tableStyle.HeaderBackColor);
However colors are not changed since it seems that parameters are passed by value.
Which is the best practice for change colors ?
I'll prefer to execute only one query in sql server and not to add additional properties, classes and structures to code.
Desktop class GetColors method contains:
public void GetColors(System.Drawing.Color foreColor,
System.Drawing.Color backColor) {
IDataReader tableReader = ExecReader(
"SELECT hforecol,hbackcol FROM desktop");
if (tableReader.Read()) {
foreColor = GetColor(tableReader.GetDecimal(0));
backColor = GetColor(tableReader.GetDecimal(1));
}
tableReader.Close();
}
Andrus
|
|
|
|
|
AndrusM wrote: it seems that parameters are passed by value.
Not generally true. Value types are passed by value and reference types are passed by reference.
If for example you have a int parameter, any changes to this parameter won't reflect outside the method.
If on the other hand the int is a field of some class assumably called IntHolder and a method has a parameter of this class, changes to the int field of an instance of the IntHolder class will reflect outside the method, because the object is passed by reference and the parameter points to the same object as a variable outside the method.
What will not reflect outside the method is the assignment of a new instance of the IntHolder class to the parameter. To circumvent the latter restriction and those mentioned for the value types, you can declare a parameter as ref or out . In short you could say that they cause a value type to be passed by reference and in case of a reference type imagine the reference to be passed by reference. For more information on the both keywords take a look at the docs.
In your specific case, I think the easiest would be passing the DataGridTableStyle instance to the GetColors method (is passed by reference) and assign the colors retrieved from the database to the corresponding properties.
public void GetColors(DataGridTableStyle tableStyle)
{
IDataReader tableReader = ExecReader("SELECT hforecol,hbackcol FROM desktop");
if (tableReader.Read())
{
tableStyle.HeaderForeColor = GetColor(tableReader.GetDecimal(0));
tableStyle.HeaderBackColor = GetColor(tableReader.GetDecimal(1));
}
tableReader.Close();
}
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you.
GetColors() method is located in my business object class.
DataGridTableStyle is in System.Windows.Forms
My business object class is compiled to separate dll . This dll cannot have reference to System.Windows.Forms since business object class must be independent of presentation.
BO class can be used with WebForms or WebServices. In tose classes other properties need to be initialized by GetColors.
So I cannot pass DataGridTableStyle object as business class method parameter.
I also tried out and ref properties but got compile time error that out and ref cannot be used with properties.
So I do'nt have any idea. It seems that I need to create 2 color methods in my BO only for getting colors back. Very inconvenient.
Andrus
|
|
|
|
|
AndrusM wrote: It seems that I need to create 2 color methods in my BO only for getting colors back.
There are still some other options.
1. You could return an array or some other collection with Color instances from the GetColor . The first item could be the fore color and the second the back color.
2. Define a custom struct or class that encapsulates two Color instances and return an object of this struct/class from the GetColor method. In my opinion better than option 1, because this way you can access the components of the return value by name and do not need to operate with anonymous fields of a collection.
3. Circumvent the compile error by passing in objects and afterwards assign them to the properties.
Color foreColor, backColor;
td.GetColors(out foreColor, out backColor);
tableStyle.HeaderForeColor = foreColor;
tableStyle.HeaderBackColor) = backColor;
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
What is the best Code Snippets Manager? I’ve found only this:
1) Total .NET SourceBook
http://www.fmsinc.com/dotnet/SourceBook/index.asp
2) Code Library .NET
http://myweb.hinet.net/home4/s630417/CodeLib.htm
3) Code Warehouse 2007
http://www.xcca.com
|
|
|
|
|
put imagelist control on your form and add images in it as you like. now come in to the list view property using smart tag. and go to the node which u add in listview and select your imageindex property value with ur imagelist control. you can only show images in listview over listnodes
|
|
|
|
|
Sir/Madam
Protected and internal protected can be inherited in the derived classes(I mean it's functions can shared among different classes by typing internal or protected internal before the functions or variables).Then what's the difference between them.
Thanks and regards
Pankaj
|
|
|
|
|
From MSDN (do a google search on "protected internal"):
A class member can be declared as protected using the protected keyword, meaning that only derived types using the class as a base can access the member. By combining the protected and internal keywords, a class member can be marked protected internal — only derived types or types within the same assembly can access that member.
Marc
Thyme In The CountryInteracxPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
how to change input language in TextBox as like (Right-to-Left) in MS-Office Word
|
|
|
|
|
err...if it's office so why did you post it in the C# section?
and it's Ctrl+shift (on the right side) for right to left and Ctrl+Shift on the left side of the keyboard for left to right o_O
|
|
|
|
|
How to do this.
When I left click on a button to appear the context menu in the location where is the button.
C#
|
|
|
|
|
Handle the click event, get the position of the button, and then show the menu there.
A better way is to create a button that has a drop menu built into it, given that this is what the button will do.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
How do I do the following:
int i = 0;<br />
for (i = 1; i < 4; i++)<br />
{<br />
if (texBox(i).Text.Length > 50)<br />
{<br />
}
there are text boxes named textBox1, textBox2 etc.
TIA
Glen Harvy
|
|
|
|
|
for(int i = 1; i<4; i++)
{
if(this.textBox1.Text.Length >50)
{
/// do something
}
}
|
|
|
|
|
Nah - that will just do the same thing 3 times to one textBox (viz textBox1).
I want to do one thing on three textboxes viz (textBox1, textBox2 and textBox3).
Glen Harvy
|
|
|
|
|
Ahh.. I misunderstood the question..
|
|
|
|
|
Put references to the textboxes in an array:
TextBox[] boxes = new TextBox[] { TextBox1, TextBox2, TextBox3 };
Now you can address the textboxes by index by using the array.
---
single minded; short sighted; long gone;
|
|
|
|
|
|
Assuming you stick with the naming convention, one way would be to iterate over the controls collection and look for the textboxes by name as you go. You could also just look for all textboxes, no matter what they are named, if you want them all.
foreach(Control control in Controls)
{
TextBox tb = control as TextBox;
if (tb != null && tb.Text.Length > 50)
{
// do something
}
}
The beauty of this approach is you don't need to build any array, there's no code to add if you change the textboxes on teh form.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i have created a usercontrol in .Net and im adding that control from code behind of the webform,i have created some properties in the user controls .How do i access those property from the code behind of my web form?
people laugh at me because they say im different and I laugh at them because they are all the same.
|
|
|
|
|
You would have to declare those properties as Public within the userControl first. Then when you've added the control you can access the properties from the new object once its added.
|
|
|
|
|
As mentioned in the title.
How to get computer current time?
|
|
|
|