|
hi,
I know how to browse a file and read the data from the file into a richtextbox in windowsform but my problem is I am not able print each file as it is but I am able to print just as appending to each line using the following code:
code :
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "Open text file";
dlg.InitialDirectory = @"c:\";
dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
StreamReader sr = File.OpenText(dlg.FileName);
string s = sr.ReadLine();
StringBuilder sb = new StringBuilder();
while (s != null)
{
sb.Append(s);
s = sr.ReadLine();
}
sr.Close();
this.richTextBox1.Text = sb.ToString();
}
can you please help me to read file as it is with newline characters to richtexbox
Don't wait to hear a word of thanks from anybody when you help them instead ask them to help three other people and ask them to continue in chain.
|
|
|
|
|
veluru krishna wrote: while (s != null)
{
sb.Append(s);
sb.Append(Environment.NewLine);
s = sr.ReadLine();
}
|
|
|
|
|
How to OPEN and OVERWRITE a binary. Pls Give me Sample Coding.
K.Alex
|
|
|
|
|
Look at the System.IO.File[^] static class and the System.IO.FileStream[^] class.
Also, search the web for articles on how to do this; there are hundreds of tutorials and examples on how to do this.
|
|
|
|
|
Hi, I want to test my little text editor app on another computer but when I have sent things like this to friends over msn, they get an error, is there someway of bundling the framework with the program or is the only way to turn it into an installation type thing with the framework with it?
Thanks.
|
|
|
|
|
They can just download and install the framework. No, there's no way around it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hey Chris,
That's not 100% accurate
take a look at:
http://www.thinstall.com/solutions/net_virtual.php
--
If you think the chess rules are not fair, first beat Anand, Kasparov and Karpov then you can change them.
Moral is, don't question the work of others if you don't know the reason why they did it.
|
|
|
|
|
I know there are products which allow you to create a free standing exe, but pointing that out just muddies the waters. None of the solutions I know of are cheap, and really, I think they are a bad idea in any case.
|
|
|
|
|
Bundle your app with the .NET framework. Alternately, use the bootstrapper built-in to VS to generate a setup program that downloads and installs the .NET framework only if required.
|
|
|
|
|
Hi Code Project Team.
Someone know how set the progressbar layout to vertical direction?
Thanks in advanced.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
|
he he he I'm sorry, when I was looking for "Vertical ProgressBar" I'd write "Vertical ProgresssBar". Sorry.
I'd need the vertical progressbar because my form it's little limited of space, but I find space.
Anyway thanks.
SINCERELY.
ANTHONY ACUÑA
PREFERED PHRASE:
SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?
|
|
|
|
|
Hi,
I have an unmanged exe and I would somehow, like to have it run inside my form. I don't care how, but is it possible?
I just want my app to be a container, or to contain the other unmanaged app.
Any ideas?
/\ |_ E X E GG
|
|
|
|
|
You can probably hack this together by making your unmanaged app a child window in your managed app. I would not do this for production code ,tho.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Is it possible to render an event from a USB card reader is the card swiped is not magnetic?
Thanks
I am trying to display MsgBox.Tex = "Card is not Authorized"
|
|
|
|
|
oskardiazdeleon wrote: the card swiped is not magnetic?
Is there input data from the device when a non-magnetic card is swiped? If not then No.
led mike
|
|
|
|
|
|
Ok, in my text editor, when a user clicks new when the document hasn't been saved, it prompts the message:
MessageBox.Show("This document has not been saved, would you like to save this document?", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
But how do I now get returns from this function, so I can use an if statement such as:
if(WHATERVER GOES HERE == OK){Messagebox.Show("User clicked OK");
Thanks,
Any reply is appreciated.
|
|
|
|
|
MEssageBox.Show returns a DialogResult value. That's the return value you want.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
So if I used:
if(MessageBox.Show == DialogResult.OK)<br />
{<br />
MessageBox.Show("User selected OK");<br />
}<br />
that should work?
Hmm, how does the compiler know that MessageBox.Show in the if statement is the same as the one with the buttons?
Do I have to do something like:
MessageBox myBox = new MessageBox();<br />
myBox.Show(ALL THE CODE HERE);<br />
if(myBox == DialogResult.OK)<br />
{<br />
CODE HERE<br />
}
Should that work?
|
|
|
|
|
You can do something like this.
<br />
if (MessageBox.Show("Press Ok or Cancel", "Test", MessageBoxButtons.OKCancel) == DialogResult.OK)<br />
{<br />
MessageBox.Show("You pressed Ok");<br />
}<br />
else<br />
{<br />
MessageBox.Show("You pressed Cancel");<br />
}<br />
You cannot use new on MessageBox because its a static class (all functions are static and the constructor is private). Also since the MessageBox.Show function does not return unless the user press a button, there is no confusion for the compiler.
---
"Drawing on my superior command of language I said nothing."
|
|
|
|
|
Thanks, I'll try that after I finish my ICT Essay :P
And yeah, I realised you cannot use MessageBox as a normal class, using new etc.
Out of interest, why is this the case?
|
|
|
|
|
The way I think about it is like this:
We create normal classes (with constructor) because we might want to have multiple instances of that class at the same time. There is no need to create multiple instances of the MessageBox class because the only thing you use a MessageBox is to show it to the user and wait for a input. The MessageBox is a modal dialog and hence the application will have to sit and wait till user clicks a button. Once the user clicks the button the only information you will need is which button the user clicked (if there is more than one button). So the entire purpose for which MessageBox class exists is finished when we call the Show method and check its return value. Hence the natural way is to make it a static class so that its very easy for use (means write less code). User never needs to create an instance.
---
"Drawing on my superior command of language I said nothing."
|
|
|
|
|
Blekk wrote: And yeah, I realised you cannot use MessageBox as a normal class, using new etc.
That's because MessageBox
a) doesn't have any constructors
b) the Show method is declared static , which means that you don't need an instance of the class and call it directly like Class.Method
hope this helps,
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks Pradeep C and Greeeg, I now understand why you don't have to create an instance and you have both also made the whole concept of the C# language a little more clear.
There are still many things I don't really know at this stage, but probably should know, meh, I would rather find it out this way than reading through endless chapters of a book and then forgetting what it was at the end of the book.
Thanks.
|
|
|
|