|
You could set it so it can only save as .htm(L)
|
|
|
|
|
I've used this in the past:
<pre> public string ToHTML(RichTextBox Box)
{
string sReturn;
long lColour;
bool bBold;
bool bItalic;
string sFont;
long lSize;
long lOldSelStart;
long lOldSelLength;
long a;
//Initial box setup
{
lOldSelStart = Box.SelStart;
lOldSelLength = Box.SelLength;
Box.SelStart = 0;
Box.SelLength = 1;
}
//Initial text
sReturn = "<html>";
//Inital paramaters
lColour = Box.SelColor;
bBold = Box.SelBold;
bItalic = Box.SelItalic;
sFont = Box.SelFontName;
lSize = Box.SelFontSize;
//Initial font setup
sReturn = sReturn + "<font size=\"" + Box.SelFontSize + "\" face=\"" + Box.SelFontName + "\" color=\"" + Box.SelColor + "\">";
//Initial bold setup
if (Box.SelBold == true)
{
sReturn = sReturn + "<b>";
}
//Initial italic setup
if (Box.SelItalic == true)
{
sReturn = sReturn + "<i>";
}
//Append new character
sReturn = sReturn + Strings.Mid(Box.Text, 1, 1);
for (a = 2; a <= Strings.Len(Box.Text); a++) {
//Set up reading paramater
{
Box.SelStart = a - 1;
Box.SelLength = 1;
}
//Check for updated font tage
if (Box.SelColor != lColour | Box.SelFontName != sFont | Conversion.Int(Box.SelFontSize) != lSize)
{
sReturn = sReturn + "</font><font size=\"" + Box.SelFontSize + "\" face=\"" + Box.SelFontName + "\" color=\"" + Box.SelColor + "\">";
}
//Check for changed boldness
if (Box.SelBold != bBold)
{
if (Box.SelBold == false)
{
sReturn = sReturn + "</b>";
}
else
{
sReturn = sReturn + "<b>";
}
}
//Check for changed italics
if (Box.SelItalic != bItalic)
{
if (Box.SelItalic == false)
{
sReturn = sReturn + "</i>";
}
else
{
sReturn = sReturn + "<i>";
}
}
sReturn = sReturn + Strings.Mid(Box.Text, a, 1);
//Update paramaters
lColour = Box.SelColor;
bBold = Box.SelBold;
bItalic = Box.SelItalic;
sFont = Box.SelFontName;
lSize = Box.SelFontSize;
}
//Check ending bold and italic
if (bBold == true) sReturn = sReturn + "</b>";
if (bItalic == true) sReturn = sReturn + "</i>";
//Terminate HTML
sReturn = sReturn + "</font></html>";
//Restore box values
{
Box.SelStart = lOldSelStart;
Box.SelLength = lOldSelLength;
}
return sReturn;
//Return value
}
</pre>
|
|
|
|
|
how can i get to know if a file is still copying?
thank you
|
|
|
|
|
Surely if you call
System.IO.File.Copy synchronously you'll know when it finishes when the call returns?
Regards,
Rob Philpott.
|
|
|
|
|
sorry that isn't what i want because i am not the coppier.
the file will be copied by someone else and i will work with the file.
but i must get to know if the file was copied completely before i work with it
|
|
|
|
|
If you try the following code
try{
System.IO.File.OpenWrite("MyFile.txt");
} catch (System.IO.IOException ex) {
System.Windows.Forms.MessageBox.Show("File is locked");
}
This will throw an error because the file is locked if it is still copying.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Simple and to the point 'The Man from U.N.C.L.E.'
Thanks and Regards,
Aby
|
|
|
|
|
isn't there a possibility without throwing an exception?
|
|
|
|
|
Hey All,
I've been playing with the textbox in C#. I cannot seem to get it so that uppercase characters and lowercase characters take up the same amount of space in the box. For example like in the textbox here on CP to enter messages:
this line aligns perfectly with
THIS LINE ALIGNS PERFECTLY
They both align perfectly regardless of case. In my textbox, if I use uppercase on one line and lowercase on the next line, the uppercase line takes up a lot more space and they do not line up.
TIA!
|
|
|
|
|
...the two lines lign up perfect in the textbox here to enter in the message, but when it is displayed it is displaying exactly like I am talking about in my application.
|
|
|
|
|
Have you tried using a font like Lucida Console?
(Fixed width font - every character uses the same width)
|
|
|
|
|
Incredibly cool, that worked!!!! Thanks! Do you know how to tell (other than trying them one by one) which fonts are fixed width?
Again, thanks a lot!
|
|
|
|
|
You can retrieve a fixed width font family using System.Drawing.FontFamily family = System.Drawing.FontFamily.GenericMonospace.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
i'm looking for a method that searches for a string in another string;
for example i have str and i have strap and if i search for str in strap , the method is supposed to return a value(where the string was found), but if i search for stp in strap, it's supposed to return null. Can you name this method??
rzvme
|
|
|
|
|
Hi there,
I believe the method that you are looking for is String.IndexOf(). IndexOf() will not return null, but will return -1 if it does not find the substring.
String sMyString = "strap";
int iPosition = sMyString.IndexOf("str"); // iPosition will equal 0 (start of the string)
iPosition = sMyString.IndexOf("stp"); // iPosition will equal -1 (not found)
On another note, just to let you know. If you are just looking for a substring within a string and you don't care about the position it was found in, you could use String.Contains() ...
<br />
String sMyString = "strap";<br />
if (sMyString.Contains("str"))<br />
{<br />
MessageBox.Show("STR WAS FOUND IN " + sMyString);<br />
}<br />
|
|
|
|
|
|
This question is more about programming methedology than anything else.
The question is simpily which is better out of the following programming methods:
This is a C# project.
There are five different classes in the project.
There are 2 classes that that need to be used by other classes. There may be more classes used by others in the future.
Communications method 1:
Any class that needs to use another class, simpilly calls methods from the other class. The class methods are called from are passed into the first class when it is instanced.
e.g.
Class A = class that writes to files.
Class B = class that needs to use files.
so when creating class B
private B beta = new B(A);
Communications method 2:
There is an overall Communications class.
Every class that needs to call upon methods in another class is required to use the comms class to do so.
e.g.
Class A = class that writes to files.
Class B = class that needs to use files.
Class C = the communications class.
so while in class B,
c.comms(<class to="" talk="" id="">,<items passed="" in="">);
Which would you use?
Or would you use something else?
(If this is the wrong place, feel free to tell me)
Munty
|
|
|
|
|
How about letting any class just create objects from the class that it needs?
---
b { font-weight: normal; }
|
|
|
|
|
The 2 classes may not need be as tightly bound as you may think.
There is really no reason to combine them.
In .NET there are 2 separate classes that may have similar purpose as yours and are separate:
StreamReader and StreamWriter.
|
|
|
|
|
Munty
What you are stumbling towards is a controller class, which is commonly used as part of an MVC (Model/View/Controller) pattern. This means that whenever you need to do something, you call the controller and let it decide how to accomplish the task.
Suppose, for instance, that class A is responsible for writing to a file and that class B can only read from the file when it is closed. Now, you could end up coding this so that you write to the file and then, when you need to read the file, you will have to check to see if the file is closed or not. This is fairly simple, and you could place the code to check the file handle in class B or in the code that is calling class A.
Unfortunately, this means that you have an implicit dependency in class A on class B, which means that every time that you want to change the behaviour of B, you have to change the behaviour of A. This is OK(ish) if you have the code to both A and B, but if somebody else has coded them, this is not great.
A better method is to move the controlling logic into the controller class C. This way, you have decoupled the dependencies.
In short - read up about patterns. They will serve you well.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete,
At the moment, what actually happens is something like this:
Class A, B and C are seperate mainly for UI reasons (They cover totally different areas of the project)
Class A, B, C all need to edit files. All have roughly similar requirements, so I moved all the file editing things into Class D, so I wouldnt have to copy and paste a couple of hundred lines around.
Class D is what you use to open up the GUIs for classes A, B and C.
The reason behind my question is that last night I suddenly thought that it would be better if I had a dedicated communications class, incase I needed to edit anything (e.g. add methods, change methods, etc).
Anyways enough of the background.
Two more things to ask:
1) Any thing you recommend as reading materials?
2) Do you see anything majorly wrong with the communications acting something like this?:
Communications Class and all other classes are instanced by a master class.
Class A calls:
Controler.talk(ID<s>,Object)
Controller class:
gets object. depending on ID does different thing to object.
e.g. converts object to String[]
sends modified object (e.g. String[]) to method in specific class (as identified by ID)
waits for response from method. (If method is not void)
Returns response as object.
--
Yeah it does mean forcing conversions from Object to whatever you need both in the communications class, and when it's returned to the original class, but it seems the best way to do it to me, rather than having a bunch of methods in the communications class that take in different sets of variables.
Edit:
Oops, accidentially made it strikethrough.
-- modified at 11:34 Thursday 26th October, 2006
|
|
|
|
|
I don't see anything wrong with this approach - hence my comments about the MVC pattern. Basically, this is the pattern you seem to be following with all commands, etc, routed through the controller. The controller is responsible for updating the model and informing the view(s) that it needs to change.
I would recommend the classic GoF (Gang of Four) book on patterns and then search amazon for a book on C# patterns.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks for answering my questions.
Gah! The GoF book is expensive on Amazon, but ah well, it has been cut by 34% and it will probably be useful next year too.
Munty
|
|
|
|
|
Seeing that you live in the UK, you could always try Computer Manuals
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|