|
manormi1 wrote: Do i need some sort of function around this that I can call recursively with different URL's ?
Yes. That is exactly you need.
|
|
|
|
|
Hello everyone-
I have an imagelist in my application with 6 images, all .png, all 24x24, 32 bits resolution. I am using them in a treeview control. All is well they show up perfectly for a little while but then during the course of me making code changes and compiling they appear to be getting corrupted. After a few compiles / a few hours later the images will begin to show up on the tree view with hatch marks in them. If I click "choose images" on the image list, they show up in the last with hatch marks. A few compiles later or another hour or two goes by, and there are more hatch marks in the image. It appears to be like a gray grid. If I go into the imagelist and delete all the images and re-add them, they show up fine again, but some time goes by and they begin to start showing hatch marks in them. I cannot figure out what I am doing that is causing the images in that list to "corrupt". Any help would be greatly appreciated!
thanks!
EDIT: The imagelist properties is set properly. Depth 32bit, image size 24,24 which is what all of the images are. (And the imagelist "choose images" when you click on an individual image the properties match, 32b, 24x24)
|
|
|
|
|
The ImageList has well documented problems. Google for .net framework imagelist problems. You will get loads of hits and may even find a solution to your problem. I never have found an entirely satisfactory one. The nearest I have got is to convert my images to icons (*.ico) but that doesn't always work.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
I have a Windows Forms Application and I have written a piece of code that makes sure that there will always only be one instance of a form open in my MDI app.
My code looks like this:
private static Forms.Employees.EmployeeForm _newEmployeeForm;
public static Forms.Employees.EmployeeForm GetChildInstance()
{
if(_newEmployeeForm == null || _newEmployeeForm.IsDisposed)
{
_newEmployeeForm = new EmployeeForm();
}
return _newEmployeeForm
}
My question is this, How can I make this code generic so that all my forms can inherit this functionality?
Thanks!
Illegal Operation
|
|
|
|
|
|
Illegal Operation wrote: My question is this, How can I make this code generic so that all my forms can inherit this functionality?
You need an easy method to instantiate forms and keep only one instance at a time, right? I'd try something like,
public static class FormsRepository
{
static Dictionary<Type, Form> cache = new Dictionary<Type, Form>();
public static T GetFormInstance<T>() where T : Form, new()
{
Type type = typeof(T);
T form = null;
if (cache.ContainsKey(type))
{
if (cache[type] == null || cache[type].IsDisposed)
cache[type] = new T();
form = (T)cache[type];
}
else
{
form = new T();
cache.Add(type, form);
}
return form;
}
} This code uses a Dictionary to keep the forms that are used. When you need an instance of Form2 , you can write like.
Form2 frm = FormsRepository.GetFormInstance<Form2>();
frm.Show(); Illegal Operation wrote: makes sure that there will always only be one instance of a form open in my MDI app.
If there will be only one instance of forms, why call it MDI?
|
|
|
|
|
Hey,
I learning now to work with processes on the computer, and i wanted to know how can i thake the Process and convert it into the orginal class.
for example
Take a opening IE running, and from the Process getting the IE command
like set website, or get for example a WindowsMediaPlayer that active, and switch the song.
There is a way to do that?
Thanks! Yahav.
Gindi Bar Yahav - Web & Software developer.
|
|
|
|
|
|
WhiteWolf19 wrote: just like the page below
This sounds like a homework assignment.
We are not going to do your homework for you. Try something and ask specific questions about what you don't understand.
only two letters away from being an asset
|
|
|
|
|
Out of interest I googled C# Ascii art - Loads of hits, including articles with code at CodeProject.
Hope that helped.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I have a class which has a dictionary and I don't want to reveal this information to the outside. So I simply made it a private member. I want people to enumerate through my class so I did the following:
public class CustomerCollection : IEnumerable<KeyValuePair<string, Customer>>
{
#region IEnumerable<KeyValuePair<string,Store>> Members
public IEnumerator<KeyValuePair<string, Customer>> GetEnumerator()
{
return this._districts.GetEnumerator();
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return this._districts.GetEnumerator();
}
#endregion
}
This works fine but during enumeration, the client has to write code as below:
foreach (KeyValuePair<string, Customer> c in this._customers) // _customers is an instance of CustomerCollection
{
c.Value.Name = "Whatever";
}
What should I do if I want the client to be able to do this:
foreach (Customer c in this._customers)
{
c.Name = "whatever";
}
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
Have CustomerCollection contain a list of Customer objects
So your code should look something like this.
NOTE: this is not tested and probably wont compile
<code>
public class Customer
{
public string Name{get; set;}
...
}
public class CustomerCollection : CollectionBase
{
public Customer this[int index]{
get{ return innerList[index];}
set{ innerList[index] = value;}
}
public void Add(Customer item){
innerList.Add(item);
}
}
</code>
If you inherit CollectionBase (System.Collections.Specialized i think) you don't to inherit or even implement IEnumerable because CollectionBase does all the dirty work for you.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
I don't want to inherit because I want to hide the interface of the inner collection. Also, I want this to be a readonly collection.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
I've never tried it, but it might work if you can provide an implicit conversion operator from Customer to KeyValuePair<string, Customer> although intellisense will still show as wanting a KeyValuePair so it wouldn't be intuitive.
You may need to wrap the dictionary a little more to provide a different enumerator.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
If you expose the Dictionary's value collection you will get this functionality.
Dictionary<string, Customer> dic;
ICollection<Customer> Customers {
get { return this.dic.Values; }
}
I think that's all you need as the value collection is enumerable.
Alan.
|
|
|
|
|
CodingYoshi wrote: What should I do if I want the client to be able to do this:
foreach (Customer c in this._customers)
{
c.Name = "whatever";
}
How about this?
public class CustomerCollection : IEnumerable<Customer>
{
public IEnumerator<Customer> GetEnumerator()
{
foreach(KeyValuePair<string,Customer> item in _districts)
yield return item.Value;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
|
|
|
|
|
Thanks! That is exactly what I am looking for. I will give that a try and let you know if it works; although, it looks as it should.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
could someone point out what I am doing wrong that the reportProgress method is not working.
BackgroundWorker bw = new BackgroundWorker();
public Control()
{
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
}
void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//do updates
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
if ((worker.CancellationPending == true))
{
e.Cancel = true;
}
else
{
//work code removed
totalnumbersoffiles = XmlFiles.Count;
for (int filecount = 0; filecount < XmlFiles.Count; filecount++)
{
//work code removed
bw.ReportProgress(filecount);
}
}
}
|
|
|
|
|
Not sure what's wrong with your code - this sample code below works though so compare the two.
public class Test
{
private BackgroundWorker backgroundWorker;
public Test()
{
backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
}
public void StartTest()
{
backgroundWorker.RunWorkerAsync();
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Console.WriteLine(e.ProgressPercentage);
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
backgroundWorker.ReportProgress(i);
}
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Console.WriteLine("Done");
}
}
Test t = new Test();
t.StartTest();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Planker wrote: totalnumbersoffiles = XmlFiles.Count;
for (int filecount = 0; filecount < XmlFiles.Count; filecount++)
{
//work code removed
bw.ReportProgress(filecount);
}
This looks odd to me.
|
|
|
|
|
instead of
bw.ReportProgress(fileCount)
write
worker.ReportProgress(fileCount+1)
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Hi,
I want to change Crystal Reports Details section(Section3) height in code behind with C# or VB.NET.
Help me...
|
|
|
|
|
Hello everybody,
first I want to tell you that I don't know C# - I'm programming in VB.NET which works for most things I need. Now I have the need to extend a working C# class with a method that converts an RGB Array to its rows, which I did in VB first and had it translated to C# in order to implement.... BUT: The translation from SharpDevelop, which seemed to work fine, is not recognized by the Visual Studio compiler.
Maybe someone of you could help me find what's wrong? Here's the translation from SD:
public int[] FromArray(Array RGBArray)
{
int[] returnValue = new int[imageHeight];
for (int i = 0; i <= returnValue.Length - 1; i++)
{
for (int j = 0; j <= imageWidth; j++)
{
returnValue[i] = SetRow(i, RGBArray(j));
}
}
return returnValue;
}
The compiler tells me "RGBArray is a Variable but is used like a Method"
Thank you for helping out,
Mick
|
|
|
|
|
Michael Schäuble wrote: returnValue[i] = SetRow(i, RGBArray(j));
The code spinet might should be:
<br />
returnValue[i] = SetRow(i, RGBArray.GetValue(i,j));<br />
RGBArray(j) is VB.NET style indexer,not C#.System.Array type doesn't have any indexers defined so to get a value an position j you shoud use GetValue method and to set value just call System.Array.SetValue(object,params[] indexes) method.
[EDIT]
Are you sure that j index is not outside of RGBArray?
Life is a stage and we are all actors!
modified on Tuesday, August 25, 2009 4:01 PM
|
|
|
|
|
Thank you for the support, Hristo!
You were right regarding 'other problems' in the code... I changed it to
public int[] FromArray(Array RGBArray)
{
int[] returnValue = new int[imageWidth];
for (int i = 0; i < imageHeight; i++)
{
for (int j = 0; j < imageWidth; j++)
{
returnValue[j] = (int) RGBArray.GetValue(j);
}
SetRow(i, returnValue);
}
return returnValue;
}
Would you agree with that?
modified on Tuesday, August 25, 2009 4:15 PM
|
|
|
|