|
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
|
|
|
|
|
hi i am using like this..
opt_no=1;score=0;
foreach (Control rd in this.Controls)
{
string rdo= "radioButton"+opt_no";
if (rd.Name == rdo && rd is RadioButton)
{
// my code is here
rd.Checked=true; // the line gives an error
}
opt_no= opt_no+1;
}
it takes only that control which is designed into form. but i designed all radio buttons into flowLayoutPanel.
i have 100 question and each Que. has four option(means four Radio button which is created in a panel).i am checking score.
i am taking question no and ans from a table.
|
|
|
|
|
Ravindra Bisen wrote: each Que. has four option(means four Radio button which is created in a panel)
Sounds like a user-control to me
I are troll
|
|
|
|
|
Ravindra Bisen wrote: 50 radio buttons in a form
Why?
If you've got this many options, maybe a dropdown combo or a list would be a better idea? With either if these finding the selected item is easy.
Alternatively if you absolutly must have all the radio buttons, on the CheckedChange event catch the pressed button as it will be the object sender.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
The alternative is to have a class member RadioButton LastChecked and to give all RadioButtons the same CheckedChanged handler, which simply updates LastChecked=(RadioButton)sender; for the last one whose Checked property became true.
|
|
|
|
|
It may be cleaner to use LastChecked = sender as RadioButton instead, then just check if LastChecked is null. That way, you don't have to go through exception handlers if you get an InvalidCastException
|
|
|
|
|
as williamnw pointed out, try to chnage you design. 50 radio buttons is way too much. It can be replaced with drop down or list control.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
I need help with modifying the parts of the cosmos code such as process management,
process synchronisation, scheduling or deadlocks.
can anyone show me an example?
thanks.
|
|
|
|