|
If you mean that you want to get the string that was originally split from the array, you will either have to write a method to do that, or you can use my handy-dandy string parsing class, available here[^] on CodeProject.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Have you had any good/bad experiences with Chilkat's .NET components? I'm specifically interested in their IMAP SDK but may go whole hog and buy their bundle (all components) if the general response is positive.
http://www.chilkatsoft.com/[^]
Thanks,
/ravi
|
|
|
|
|
Never used them or heard of them, Ravi.
|
|
|
|
|
Bummer - I was hoping they would be known to the CP community.
Their customer list, online docs, FAQ and free lifetime upgrade policy (they've been around since 2000) seem appealing. Too bad they're not as well known as I thought they'd be. Maybe it's the weekend.
/ravi
|
|
|
|
|
Hallo
i'd need to write a loop which iterate through the variables whose names start with a specific string: i.e.
for every variable whose name starts with "PATH_.." [or Left(name,5) == "PATH_"]
perform a file.exists check
or, again
for every variable whose name starts with "IMG_.."
do this: imgArray[variable_name] = variable_value
(imgArray being a pre defined Hashtable)
To be clearer, in PHP variable names can be obtained through the syntax $$variable, where $variable returns the variable value only.
In other words, i would like to automatically do a collection of variables grouped by particular strings in their names.
Is it possible?
|
|
|
|
|
To give the whole look, i'll try to explain what i want to do.
In the application, according to the user's choice, the main form backgroundImage changes, and is programmantically choosen among several external images whose paths are specified as user settings in the app.config: they are 10-15, number could change, those paths names all start with "PATH_".
So first of all i'd like to check if those files exists.
And then i'd like to change the main form background image at runtime according the current operation.
Maybe there's a different way to reach this?
|
|
|
|
|
Hi,
Operating on the names of variables is not possible in general; you can use reflection to operate
on the members (data fields, properties, methods, ...) of an object. But that is somewhat advanced stuff,
and not necessary for what you need.
I understand you will get the paths one by one from somewhere (app.config), and want to perform some
operations on them; hence I suggest you collect them in a Collection, probably a List< string> is
appropriate. You might first check the file existence, and only then insert the path name in the list.
Or you could insert the images themselves in the list; that would take more memory, but might better suits
your needs. Or you could create a little class that describes an image, holding its path name,
its image (initially null, until it is required, hence acting like a cache), and possibly some metadata.
|
|
|
|
|
Dear all,
I developed one application which collect the list of files in a directory after a comparison.
At the beginning I add the result into a datagridview but it seems I take too much virtual memory, for around 5 millions of file comparison.
I tried to write the list inside a text file but still the same problem.
So what I want to have is that how/what shoud I do to write the list of files after comparison directly into a text file (or list view) without taking too much memory.
Thanks for your reply
some piece of code would be appreciated.
|
|
|
|
|
It would appears that you're adding each filename to a list of some kind. If you don't want to use all that memory, you can't do that. Just write the information to the file as you find it, then don't add it to a collection of any kind.
|
|
|
|
|
Hi,
when you store all the file names somewhere (DataGridView, Array, List, ...) is does not scale well,
i.e. it works fine for small amounts, but starts to behave badly for large amounts; and disks could
hold millions of files. So try and avoid the need to have them all at once.
Example: say you want to compare the contents of two disks; there is NO need to first collect a list
of all the files, simply come up with a way to enumerate the files one by one in a predictable order,
now apply this same order to both disks. When they contain A+B+C+D+E+F+G and C+A+K+B+L you can't compare
them sequentially unless you enumerate in an ordered fashion, i.e. A+B+C+D+E+F+G and A+B+C+K+L,
these are easily comparable.
It you must have them all at once, try to keep the data to a minimum; for files and folders that
means don't hold the full path for each, just keep the name and a pointer to its parent. This may
save a factor of 2 to 5, which might be sufficient for your current needs, but again it does not
scale well, sooner or later you will run into trouble again.
|
|
|
|
|
Firstly, thanks for your prompt reply.
[Dave Kreskowiak]
Yeah this is what I want I think write the information directly as I find it, but I don't know how to make it.
[Luc Pattyn]
So you mean that I'll always get into trouble everytime I make my comparison ?
Let me explain to you first what my program do.
I have two servers with disk capacity around 7 To each.
The first one change everytime, 'cause it is like a transaction server, and second one is just for backing up the first one.
Let's say transaction server = 1A and backup server = 1B
Once someone made a transaction into 1A, it should be backed up to 1B but no need to delete files from 1B directly. Need to wait about two weeks and after that I should make a purge.
So my application is about purging files. Means that it compares first all files of the two servers and then lists those files before delete. It's at this level I'm into a trouble, making the comparison and then list all files.
So which solution should I adopt correctly ? Writing files directly inside a text file (by splitting if up to a specific size) or using a dictionnary or list... something like that. Or if have other solution I would appreciate it.
for information: my app is made with C# .NET 3.5
Thank you so much
|
|
|
|
|
AFAIK I already gave the complete answer. The key word is SORT.
One more detail, which should be obvious by now: use GetFiles/GetDirectories without implicit recursion, do the recursion yourself!
|
|
|
|
|
Yes, you're right. I'm going to change my app now.
It's more quick than before after sorting the file list with just a few number of files.
Many thanks for your help

|
|
|
|
|
hi,
I have and application which has 2 forms. The firts form has a textbox and a button which clicked opens a second form, which has just one button which clicked calls a method in the first form. The problem is, that the textbox doesn't update. There are no excpetion, when I set a break point the program goes into the line which updates the textbox but nothing happens. What is wrong?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void add()
{
textBox1.Text = "Test";
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.add();
}
}
|
|
|
|
|
You are instantianting a new Form1, this is not the existing Form1 that opened your second form. When the first form opens the second, it should provide a reference to itself that you can then use in the second form. Optionally, you can check the Owner/ParentForm properties or something like that, depending on how you show the second form.
public partial class Form2 :
Form
{
private Form1 _parentForm;
public Form2()
{
InitializeComponent();
}
public Form2(Form1 parentForm)
{
InitializeComponent();
this._parentForm = parentForm;
}
private void button1_Click(object sender, EventArgs e)
{
if (this._parentForm != null)
{
this._parentForm.Add();
}
}
In this example, your Form1 code is supposed to do something like:
Form2 form = new Form2(this);
form.Show();
Jean-Christophe Grégoire
|
|
|
|
|
Jean-Christophe Grégoire wrote: it should provide a reference to itself
Although this works and is a common method - it should not be encouraged. Form2 shouldn't know anything about Form1 and no method on it should be tied to an instance of a control that it hasn't created itself.
If it needs to broadcast information, it should use an event/delegate - in the same way that every other control does
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)
|
|
|
|
|
I certainly do agree, I didn't want to bother him
Jean-Christophe Grégoire
|
|
|
|
|
This should really be done with a delegate/event. I prefer using events for stuff like this. Form2 needs a new event that it can raise, and make you Form1 instance subscribe to it after it has instanciated it. If using an event you'll need a class derived from EventArgs to pass the data back.
This is the sort of idea.
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.ReadyToUpdate += new EventHandler<Form2.MyEventArgs>(frm2_ReadyToUpdate);
frm2.Show();
}
void frm2_ReadyToUpdate(object sender, Form2.MyEventArgs e)
{
textBox1.Text = e.Text;
}
}
}
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public event EventHandler<MyEventArgs> ReadyToUpdate;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OnReadyToUpdate(new MyEventArgs("Test"));
Close();
}
protected virtual void OnReadyToUpdate(MyEventArgs e)
{
EventHandler<MyEventArgs> eh = ReadyToUpdate;
if (eh != null)
eh(this, e);
}
public class MyEventArgs : EventArgs
{
public MyEventArgs(string text)
{
m_Text = text;
}
private string m_Text;
public string Text
{
get { return m_Text; }
}
}
}
}
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)
|
|
|
|
|
Hi guys wonder if i can get a bit of help. I'm in the process of writing a word search style game in c#. I've managed to draw a grid and being able to highlight a cell within that grid. However where i'm getting stuck is creating the grid of letters. At the moment this is all purely aesthetic, there is no logic behind it yet. So any ideas on how to create a grid of letters to go into my drawn grid, would be most helpful.
Say i have a 5x5 grid what i want to be able to do is place a letter in each of those grid cells, so something like this:
a b c d e
a b c d e
a b c d e
a b c d e
a b c d e
I hope this makes sense and someone has an idea. I've included my code to draw my gridlines and highlight a cell in that grid below!
Regards
Vince
public partial class GUI : Form<br />
{<br />
private int gridWidth = 600;<br />
private int gridHeight = 600;<br />
private int squareSize = 20;<br />
private int maxCol = 60;<br />
private int maxRow = 60;<br />
private Color customColor;<br />
private Boolean[,] cellSelected = new Boolean[60, 60];<br />
<br />
public GUI()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void pictureBox1_Paint(object sender, PaintEventArgs e)<br />
{<br />
Graphics gfx = e.Graphics;<br />
this.customColor = Color.LightSlateGray;<br />
<br />
Pen myPen = new Pen(this.customColor);<br />
for (int i = 0; i <= this.gridWidth; i = i + this.squareSize)<br />
{<br />
gfx.DrawLine(myPen, 0, i, this.gridHeight, i);<br />
}<br />
for (int i = 0; i <= this.gridWidth; i = i + this.squareSize)<br />
{<br />
gfx.DrawLine(myPen, i, 0, i, this.gridHeight);<br />
}<br />
<br />
int cellRow = 0;<br />
while (cellRow < this.maxRow)<br />
{<br />
int cellCol = 0;<br />
while (cellCol < this.maxCol)<br />
{<br />
if (this.cellSelected[cellCol, cellRow] == true)<br />
{<br />
this.customColor = Color.FromArgb(100,100,100);<br />
<br />
SolidBrush myBrush = new SolidBrush(customColor);<br />
gfx.FillRectangle(myBrush, (cellCol * this.squareSize) + 1, (cellRow * this.squareSize) + 1, this.squareSize - 1, this.squareSize - 1);<br />
myBrush.Dispose();<br />
}<br />
cellCol++;<br />
}<br />
cellRow++;<br />
}<br />
}<br />
<br />
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
int xMouseCoordinate = e.X / this.squareSize;<br />
int yMouseCoordinate = e.Y / this.squareSize;<br />
this.cellSelected[xMouseCoordinate, yMouseCoordinate] = true;<br />
pictureBox1.Refresh();<br />
}<br />
<br />
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
if (e.X > 0 && e.Y > 0 && e.X < pictureBox1.Width && e.Y < pictureBox1.Height && e.Button == MouseButtons.Left)<br />
{<br />
double xMouseCoord = (e.X - 1) / this.squareSize;<br />
double yMouseCoord = (e.Y - 1) / this.squareSize;<br />
int xMouseCoordinate = (int)System.Math.Ceiling(xMouseCoord);<br />
int yMouseCoordinate = (int)System.Math.Ceiling(yMouseCoord);<br />
this.cellSelected[xMouseCoordinate, yMouseCoordinate] = true;<br />
pictureBox1.Refresh();<br />
}<br />
if (e.X > 0 && e.Y > 0 && e.X < pictureBox1.Width && e.Y < pictureBox1.Height && e.Button == MouseButtons.Right)<br />
{<br />
double xMouseCoord = (e.X - 1) / this.squareSize;<br />
double yMouseCoord = (e.Y - 1) / this.squareSize;<br />
int xMouseCoordinate = (int)System.Math.Ceiling(xMouseCoord);<br />
int yMouseCoordinate = (int)System.Math.Ceiling(yMouseCoord);<br />
this.cellSelected[xMouseCoordinate, yMouseCoordinate] = false;<br />
pictureBox1.Refresh();<br />
}<br />
}<br />
}
|
|
|
|
|
You can draw text using the .DrawString method. That would go in the _Paint handler;
int cellRow = 0;
while (cellRow < this.maxRow)
{
int cellCol = 0;
while (cellCol < this.maxCol)
{
if (this.cellSelected[cellCol, cellRow] == true)
{
this.customColor = Color.FromArgb(100, 100, 100);
SolidBrush myBrush = new SolidBrush(customColor);
gfx.FillRectangle(myBrush, (cellCol * this.squareSize) + 1, (cellRow * this.squareSize) + 1, this.squareSize - 1, this.squareSize - 1);
gfx.DrawString("X", this.Font, Brushes.Wheat, new Point(cellCol * this.squareSize, cellRow * this.squareSize));
myBrush.Dispose();
}
else
{
gfx.DrawString("X", this.Font, Brushes.Green, new Point(cellCol * this.squareSize, cellRow * this.squareSize));
}
cellCol++;
}
cellRow++;
I are troll
|
|
|
|
|
Hi eddy thats useful thanks, however i want to be able to set the letters myself, as at the moment this will paint an x in every cell. So say i want to have the word "hello" in the grid somewhere surrounded by random letters. The random letter thing, i think i've got an idea in, but without hard coding the actual word in, i'm not sure how to place the word in the grid somewhere?
|
|
|
|
|
Don't do that like that, compute the letters list where you want, give it to your "grid container" UserControl which it is supposed to know the list of "letter controls" that it contains. Loop in your letters list and give a letter to each sub-control. Each sub-control is supposed to have a stupid Text property, in which you can set the value of a label that would be docked full in your sub-control.
Really, don't put all this useless complexity like that.
Jean-Christophe Grégoire
|
|
|
|
|
Hi Jean-Christophe, i'm only quite new to C# and programming as a whole and i'm not really understanding what your meaning. Maybe a good see what you mean with some pseudo code or just initial code to get me on my way?
|
|
|
|
|
Okay sorry, give me some more time and I will mail you a sample project
Jean-Christophe Grégoire
|
|
|
|
|
Thank you Jean-Christophe, i really appreciate your help. I think once i see what your meaning i will be able to get a grasp of it!
Many thanks
|
|
|
|
|