|
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.
|
|
|
|
|
Please, try and ask a question that someone can answer. Read the top of the page post - what does it say - and then consider showing what you've tried. There will be one of two answers depending on your question:
Q. Why not work? rgnt!
A. Foff and die.
Q. I tried this [code example] and the following happened [output]. I expected [this]. Can anyone help?
A. Sure, change [bing] to [bang] and yall cookin ona BBQ.
Enjoy!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I wouldn't recommend it. Operating system development is a very complex subject; you need to understand boolean logic, assembly code and other complex topics just to get off the ground. To actually get something 'simple', like a mouse cursor, you'll need to be very familiar with sprite rendering techniques, how double-buffering is implemented, and how to make a mouse driver. With COSMOS, it's more complicated, as you'll need to understand how the IL2CPU compiler works. This is another subject which is difficult to understand
An example is difficult, if not impossible to give when it comes to an operating system. Unless you write the code yourself, and know the system intimately, you won't know how it integrates. This will make your debugging infinitely harder
|
|
|
|
|
But doesnt cosmos come with a source code? any existing source code that you can modify or u have to write the whole code if u need to???
thanks,
|
|
|
|
|
It comes with lots of source code. Modifying it isn't just a question of copying/pasting code and pressing F5 to see if it works.
Why not download the code and take a look at it?
--edit--
I forgot the HTML closing-tags again. Just corrected it
I are troll
|
|
|
|
|
It does. But it's going to be a lot harder to debug if you don't know how it works. This is not normal software development - you need to have good knowledge on how COSMOS works in terms of code, and how it gets compiled down to ASM. Generally, you need to have looked at the source code from the beginning to have that kind of knowledge
No, you don't have to write the whole code - that would take years! You could try to get an in-depth understanding of the code, then either do a fork, or contribute to the main project. But you shouldn't make an OS from somebody else's code. If you did that, it wouldn't really be 'your' code, and you would lack some of the basic skills necessary to make repairs (understanding the base infrastructure). Of course, if the COSMOS artists read the message board, I'd welcome any further comments
|
|
|
|
|
Hi I have load an image in the background but i would like to show HAND cursor in some area (e.g button on a background image). I am able to do it for whole form or background image but not for a part of it.
|
|
|
|
|
There is a Cursor property for almost every Windows control.
Lets a assume we have a Button control say button1 and we want to change its cursor then we will use the following code:
button1.Cursor = Cursors.Hand;
Hope it will help.
Don't believe in love...
|
|
|
|
|
There is a cursor property for almost every Windows control.
Lets assume you have a Button say button1 and you want to change its cursor to Hand now you will have to use following code:
button1.Cursor = Cursors.Hand;
Hope it will help.
Don't believe in love...
|
|
|
|
|
You asked this a little while ago.
DON'T do this!
VERY, VERY rude.
You are not giving sufficient information about your problem for anybody to give you an accurate answer.
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.”
|
|
|
|