Ok.
I see a lot of people writing post-creator applications, which is a great way to start writing programs.
Here is a little guidance for those just starting out to help you along the way.
Thebold, italic, underline, code, img, quote, etc... buttons are very simple:
Basically all that is saying is "if iv selected some text, wrap it in the desired tags, else just put the tags wherever the cursor is".
The same process can be repeated for every button, or if you feel daring, use the "object sender" as a reference and you can use one void for all of the buttons.
One thing that you dont see very often is a "preview post" button, but its a very nice feature and is relatively simple:
What that's doing is using a simple string.replace method for most of the string replacements and regex for the harder color.
Its all wrapped in a 600px div to make it look more like it would when a post is sent to a forum.
Its then saved as a "html" file and then executed, and thus viewed in your default browser.
You will need to add the "System.IO" namespace for the StreamWriters and also "System.Text.RegularExpressions" for the regex command.
And thats about it, nice and simple, and very useful to the user!
(Spaces have been added to the [TAGs] as not to get parsed
)
I see a lot of people writing post-creator applications, which is a great way to start writing programs.
Here is a little guidance for those just starting out to help you along the way.
Thebold, italic, underline, code, img, quote, etc... buttons are very simple:
Code:
private void boldButton_Click(object sender, EventArgs e)
{
if (myRichTextBox.SelectionLength > 0)
"[b ]" + myRichTextBox.SelectedText + "[/b ]";
else
myRichTextBox.SelectedText = "[b ][/b ]";
}
The same process can be repeated for every button, or if you feel daring, use the "object sender" as a reference and you can use one void for all of the buttons.
One thing that you dont see very often is a "preview post" button, but its a very nice feature and is relatively simple:
Code:
private void PreviewSelectedPostButton_Click(object sender, EventArgs e)
{
string thePost = postContents.Text;
if (thePost.Length == 0)
{
MessageBox.Show(
"The post cannot be empty.",
"Empty Post",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
// Line-Breaks
thePost = thePost.Replace("\n", "<br / >");
// BOLD
thePost = thePost.Replace("[b ]", "<b>");
thePost = thePost.Replace("[/b ]", "</b>");
// ITALIC
thePost = thePost.Replace("[i ]", "<i >");
thePost = thePost.Replace("[/i ]", "</i >");
// UNDERLINE
thePost = thePost.Replace("[u ]", "<u >");
thePost = thePost.Replace("[/u ]", "</u >");
// CODE box
thePost = thePost.Replace(
"[code ]",
"<br /><div style=\"color: #880000; font-size: 11px; line-height: 110%; font-family: verdana,arial,verdana,tahoma,sans-serif; font-size-adjust: none; font-variant: normal; font-weight: normal; background: #dedede none repeat scroll 0 0; margin-left: 10px; padding: 5px;\"> ");
thePost = thePost.Replace("[/code ]", "</div><br />");
// QUOTE box
thePost = thePost.Replace(
"[quote ]",
"<br /><div style=\"color: #333333; font-size: 11px; line-height: 110%; font-family: verdana,arial,verdana,tahoma,sans-serif; font-size-adjust: none; font-variant: normal; font-weight: normal; background: #eeeeee none repeat scroll 0 0; margin-left: 10px; padding: 5px;\"> ");
thePost = thePost.Replace("[/quote ]", "</div><br />");
// Images
thePost = thePost.Replace("[img ]", "<img src=\"");
thePost = thePost.Replace("[/img ]", "\" /> <br />");
// Colours
thePost = Regex.Replace(thePost, "\\[ color=(.*?)](.*?)\\[/color ]", "<font color=\"$1\">$2</font>");
string htmlPath = System.Environment.CurrentDirectory + "\\preview.html";
using (StreamWriter writer = new StreamWriter(htmlPath))
{
writer.WriteLine("<html><head><title>Multi-Poster Ultimate - Preview</title></head><body>");
writer.WriteLine("<table width=\"600px\" border=\"0\"><tr><td>");
writer.Write(thePost);
writer.WriteLine("</td></tr></table></body></html>");
}
System.Diagnostics.Process.Start(htmlPath);
}
Its all wrapped in a 600px div to make it look more like it would when a post is sent to a forum.
Its then saved as a "html" file and then executed, and thus viewed in your default browser.
You will need to add the "System.IO" namespace for the StreamWriters and also "System.Text.RegularExpressions" for the regex command.
And thats about it, nice and simple, and very useful to the user!
(Spaces have been added to the [TAGs] as not to get parsed