|
Whoops. I missed that one. Follow the instructions at this link
|
|
|
|
|
Hi,
you need a imgArray = new System.Windows.Forms.PictureBox[NumOfFiles]; inside GetPicture4() and none of it inside ARR().
And I strongly suggest you buy a tutorial book on C# and study it. It is the only efficient way to make real progress.
|
|
|
|
|
I tried this code snippet:
private List<string> GetPicture4(string Folder)
{
imgArray = new System.Windows.Forms.PictureBox[NumOfFiles];
DirectoryInfo dir = new DirectoryInfo(Folder);
List<string> str = new List<string>();
FileInfo[] files = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
NumOfFiles = files.Count();
imgExtension = new string[NumOfFiles];
for (int i = 0; i < NumOfFiles; i++)
{
ARR(i, files[i].FullName);
str.Add(files[i].FullName);
}
return str;
}
and after i remode this line
imgArray = new System.Windows.Forms.PictureBox[NumOfFiles];
from the Arr Method but i receive always this error "Index was outside the bounds of the array."
Really sorry maybe i misundertood your advice if yes please be patient i try my best.
Thanks a lot
P.S. i will buy a book as soon as possible,i need improve my English too
|
|
|
|
|
ascotravel wrote: imgArray = new System.Windows.Forms.PictureBox[NumOfFiles];
What do you think is the value of NumOfFiles at this point?
|
|
|
|
|
Okay Luc ,
I work out it after read an article about array ,i removed the method ARR() and i organize the code in the GetPicture4() creating the right loop and removing the messy code wrote down in past.
Thanks for your patience and sorry for my stupidity
Have a good work.
Nice Regards
|
|
|
|
|
How can I create Objects and make them resize them selves according to the Form.
Objects like text Boxes Buttons and more.
Is this is a property?
Thanks for your help
|
|
|
|
|
Look into the Anchor and Dock properties
|
|
|
|
|
Can anyone tell me why do we create DLL files for our project? What is the use of it?
|
|
|
|
|
Because sometimes they may contain support functions. Since they would just contain those particular functions, they're unlikely to contain an entry point, and this would mean that a DLL would be your only option AFAIK
|
|
|
|
|
I need to start with Crystal report Programaticlly, Can anyone help me?
|
|
|
|
|
|
Hello! I want to load a 3,8 MB big file with about 650 000 lines of text (a level file) and write all text to a textbox. But the program crashes when I try to do that! What should I do?
string filetext = String.Empty;
StreamReader tr = new StreamReader(openFileDialog1.FileName);
filetext = tr.ReadToEnd();
tr.Close();
filetext = filetext.Replace("\0", Environment.NewLine);
StringReader sr = new StringReader(filetext);
int counter = 0;
string line = "";
StringBuilder sb = new StringBuilder();
while ((line = sr.ReadLine()) != null)
{
if (line.Length > 0)
{
counter++;
sb.Append(line);
sb.Append(Environment.NewLine);
}
}
richTextBox1.Text = sb.ToString();
|
|
|
|
|
Your program doesn't crash. You simply haven't told it to update the UI thread. Also, you're dumping the text to the RichTextBox all at once. Put that method in a separate Thread, with IsBackground set to true. Also, why are you going through line by line? You've got the file contents, replaced the nulls (which you don't actually need to do - StreamReader stops on a null character), why do you need to append it, line by line, to a StringBuilder?
What you could do is this:
- New thread
- New StreamReader
- Call the SuspendLayout method of the RichTextBox
- Read line by line. Append each line to the RichTextBox
- Call the ResumeLayout method of the RichTextBox
- Close and dispose the StreamReader
|
|
|
|
|
Yes, but the file contains lots of nulls here and there and I want to remove them and display the file's whole text without nulls. And I think it should go faster if I use the string builder.
I have no idea how to do with Threads, can you post a example, please?
The new code:
string filetext = String.Empty;
string line = String.Empty;
StreamReader tr = new StreamReader(openFileDialog1.FileName);
richTextBox1.SuspendLayout();
while ((line = tr.ReadLine()) != null)
{
if (line.Length > 0)
{
line = line.Replace("\0", Environment.NewLine);
richTextBox1.AppendText(line);
richTextBox1.AppendText(Environment.NewLine);
}
}
richTextBox1.ResumeLayout();
tr.Close();
tr.Dispose();
|
|
|
|
|
You cannot display the whole file text without nulls if you read it through a StreamReader. The instant that a StreamReader comes across a null character, it stops reading. It assumes that the file has ended. If you wanted something a little more complex, then you'd have to implement your own
Your original code would not go faster with a StringBuilder, because you've already got everything in a String. Instantiating a StringBuilder would have only slowed it down in this situation, because you had to get the full string, then read it line by line (creating more Strings) into a StringBuilder, thereupon to convert the StringBuilder into the original String to set the RichTextBox's Text property
A Thread is relatively simple to do. It's set up like this
System.Threading.Thread th = new System.Threading.Thread(new Action(() =>
{
})) { IsBackground = true };
th.Start();
IsBackground makes it terminate with your application. You'll also have to use Invoke in order to make thread-safe UI calls. Look into the Action<T> and Func<T> for information about that
|
|
|
|
|
You can't just move Control operations to another thread, that will only result in lots of illegal cross-thread exceptions and/or a hanging GUI.
If your text is line oriented, i.e. you don't want any word wrapping, then a ListBox would be much better at showing the text. It does not need concatenated text lines, it accepts each line as a separate item, and therefore it does not slow down quadratically with the text size.
All it takes is myListBox.Items.Add(line);
|
|
|
|
|
Hi,
I embedded some files in the assembly, html(text) images(gif, jpg, png).
What i want to do is extract all the files to a tmp directory.
I had SUCCESS in getting all the files to tmp directory. I open the text files..PERFECT. but images are not right, it says corrupt. How do I get the images extracted correctly from embedded resource and save it to disk.
Following is my piece of code.
private void button1_Click(object sender, EventArgs e)
{
Assembly _assembly;
Stream _imageStream;
StreamReader _StreamReader;
StreamWriter _StreamWriter;
string dirpath = Application.StartupPath + "\\help";
string[] resourceNames = this.GetType().Assembly.GetManifestResourceNames();
foreach (string resourceName in resourceNames)
{
if (resourceName.Contains(".help"))
{
MessageBox.Show(resourceName);
try
{
if (!Directory.Exists(dirpath))
{
DirectoryInfo di = Directory.CreateDirectory(dirpath);
di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
di.CreateSubdirectory("images");
}
string filename = Application.StartupPath + "\\help\\";
if (resourceName.Contains(".images")) filename = filename + "images\\";
string[] filenamearray = resourceName.Split('.');
int length = filenamearray.Length;
filename = filename + filenamearray[length - 2] + "." + filenamearray[length-1];
string read = null;
_assembly = Assembly.GetExecutingAssembly();
_StreamReader = new StreamReader(_assembly.GetManifestResourceStream(resourceName));
_StreamWriter = new StreamWriter(filename);
while ((read = _StreamReader.ReadLine()) != null)
{
_StreamWriter.WriteLine(read);
}
_StreamWriter.Close();
_StreamReader.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Thanks a lot for you precious time and knowledge,
Regards,
Karmendra
|
|
|
|
|
images contain binary data, not text, so StreamReader/Writer aren't the right classes, and ReadLine()/WriteLine() aren't the right methods to use here.
Use BinaryReader/Writer or alternatively recreate then save the image using Image.FromStream() and Image.Save().
|
|
|
|
|
That's so much right thanks so much Luc.
Observations: You always reply my questions, thanks again for that.
|
|
|
|
|
Hi every body,
I have to forms, each form has a tree that is exactly the same with the other, the best way is to use one tree control for both form, but I realize that when you add a control to another parent, the former parent will remove it from it's Controls' list.
You have any idea to solve my problem?
Thanks a lot!
Regards.
|
|
|
|
|
A Control can only be visible once, it has at most one Parent, and resides in at most one Controls collection. So it is fine to move a Control around in some cases:
- from one tab page to the next when these pages belong to the same TabControl (hence at most one of them is showing),
- from one modal dialog to the next (at most one of them showing again)
but you can't reuse a Control in general. You would have to have two Controls, and use code to keep them synchronized.
modified on Saturday, April 11, 2009 1:25 PM
|
|
|
|
|
Pity
It's a MDI application, user can even move the MDI forms around and align them parallely to work together. Now I have many troubles synchronize them. Anyway, thanks for you answers, I can use them in some other cases.
|
|
|
|
|
A control can have only one parent. There's nothing stopping you form removing the control from one parent's Controls collection and adding it to another though.
|
|
|
|
|
I have 50 radio buttons in a form. can i use a loop to check which radio button is checked ?
|
|
|
|
|
Yup. You'd typical loop through the Control -collection of the form, checking if the Control is a radioButton , and if it is, downcast it to a RadioButton and read the value.
--edit--
Forgot to close one of the <code> tags
I are troll
|
|
|
|