本文整理汇总了C#中System.Windows.Forms.RichTextBox.LoadFile方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.LoadFile方法的具体用法?C# RichTextBox.LoadFile怎么用?C# RichTextBox.LoadFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.LoadFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
/// <summary>
/// 从 rtf 文件中读取文本
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string Read(string fileName)
{
using (var rtb = new RichTextBox())
{
rtb.LoadFile(fileName);
return rtb.Text;
}
}
示例2: ImportFile
public static void ImportFile(RichTextBox richTextBox1)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "RTF Files|*.rtf|txt Files|*.txt|所有文件|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
openFileDialog1.FileName = openFileDialog1.FileName;
if (openFileDialog1.FileName != "")
{
if (Path.GetExtension(openFileDialog1.FileName) == ".rtf")
{
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
}
else
{
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
}
}
}
}
示例3: ShowHelpAbout
protected override void ShowHelpAbout()
{
try
{
var assem = Assembly.GetAssembly(typeof(SledAboutService));
var version = assem.GetName().Version.ToString();
var title =
SledUtil.TransSub(Resources.Resource.HelpAboutTitleWithVersion, version);
using (Image image = m_mainForm.Icon.ToBitmap())
{
{
//
// WWS version
//
using (var richTextBox = new RichTextBox())
{
richTextBox.BorderStyle = BorderStyle.None;
richTextBox.ReadOnly = true;
using (var strm = assem.GetManifestResourceStream(Resources.Resource.HelpAboutAssemblyPath))
{
if (strm != null)
richTextBox.LoadFile(strm, RichTextBoxStreamType.RichText);
using (var dialog =
new AboutDialog(
title,
ApplicationUrl,
richTextBox,
image,
null,
true))
{
dialog.ShowDialog(m_mainForm);
}
}
}
}
}
}
catch (Exception ex)
{
SledOutDevice.OutLine(
SledMessageType.Error,
SledUtil.TransSub(Localization.SledHelpAboutErrorException, ex.Message));
}
}
示例4: ShowHelpAbout
/// <summary>
/// Shows the About dialog box</summary>
/// <remarks>Derived classes should copy this method and customize it.
/// It is recommended to display the ATF version number to aid in diagnosing
/// problems. (Pass in 'true' to AboutDialog's constructor or use AtfVersion.)</remarks>
protected override void ShowHelpAbout()
{
RichTextBox richTextBox = new RichTextBox();
richTextBox.BorderStyle = BorderStyle.None;
richTextBox.ReadOnly = true;
Stream textFileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
"TimelineEditorSample.Resources.About.rtf");
richTextBox.LoadFile(textFileStream, RichTextBoxStreamType.RichText);
string appURL = "https://github.com/SonyWWS/ATF/wiki";
AboutDialog dialog = new AboutDialog(
Localizer.Localize("Timeline Editor Sample"), appURL, richTextBox, null, null, true);
dialog.ShowDialog();
}
示例5: DownloadRtfFile
internal static void DownloadRtfFile(string url, RichTextBox rtb)
{
using (WebClient client = new WebClient())
{
client.Proxy = null;
using (Stream stream = client.OpenRead(url))
{
using (MemoryStream mStream = new MemoryStream())
{
stream.CopyTo(mStream);
mStream.Position = 0;
rtb.LoadFile(mStream, RichTextBoxStreamType.RichText);
}
}
}
}
示例6: BuildIndex
private void BuildIndex(string resourceName, byte[] resourceContent)
{
RichTextBox richTextBox = new RichTextBox();
richTextBox.LoadFile(new MemoryStream(resourceContent), RichTextBoxStreamType.RichText);
string plainText = richTextBox.Text;
string[] words = plainText.ToLower().Split(
m_delimeters, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in words)
{
// filter out links
if (word.Contains('#'))
continue;
// filter out blacklisted words
if (m_keywordBlacklist.ContainsKey(word))
continue;
// filter out numbers
int dummyInteger;
if (int.TryParse(word, out dummyInteger))
continue;
float dummyFloat;
if (float.TryParse(word, out dummyFloat))
continue;
double dummyDouble;
if (double.TryParse(word, out dummyDouble))
continue;
List<string> resourceNames = null;
if (m_contentIndex.ContainsKey(word))
resourceNames = m_contentIndex[word];
else
{
resourceNames = new List<string>();
m_contentIndex[word] = resourceNames;
}
if (!resourceNames.Contains(resourceName))
resourceNames.Add(resourceName);
}
}
示例7: ProcessTemplate
private Dictionary<String, MemoryStream> ProcessTemplate()
{
MemoryStream plantillaStream = new MemoryStream();
Dictionary<String, MemoryStream> listStream = new Dictionary<String, MemoryStream>();
//Extraemos la plantilla
//Se modifican las fechas una sola vez en la plantilla
using (richText = new RichTextBox())
{
richText.LoadFile(invitacionUri);
SearchAndReaplaceRTF("[[Fecha Invitacion]]", wordDateInfo.FechaInvitacion.ToString(FORMAT_DATE));
SearchAndReaplaceRTF("[[Fecha Mediacion]]", wordDateInfo.FechaMediacion.ToString(FORMAT_DATE));
SearchAndReaplaceRTF("[[Hora Mediacion]]", String.Format("{0} a {1}", wordDateInfo.HoraInicio.ToString(FORMAT_HOUR_INITIAL),
wordDateInfo.HoraFinal.ToString(FORMAT_HOUR_FINAL)));
richText.SaveFile(plantillaStream, RichTextBoxStreamType.RichText);
}
foreach (WordInfo info in wordList)
{
MemoryStream memoryFile = new MemoryStream();
using (richText = new RichTextBox())
{
plantillaStream.Position = 0;
richText.LoadFile(plantillaStream, RichTextBoxStreamType.RichText);
SearchAndReaplaceRTF("[[NOMBRE]]", info.Nombre);
SearchAndReaplaceRTF("[[DIRECCION]]", info.DireccionCompleta);
SearchAndReaplaceRTF("[[CREDITO]]", info.Credito.ToString());
richText.SaveFile(memoryFile, RichTextBoxStreamType.RichText);
}
listStream.Add(info.Nombre, memoryFile);
}
return listStream;
}
示例8: Log
/// <summary>
/// Write a new log entry with the specified category and priority.
/// </summary>
/// <param name="log">The log item to log.</param>
public void Log(ILog log)
{
if (log == null) { throw new ArgumentException("log"); }
if (DateTime.Now.Date != this.logDate)
{
this.logDate = DateTime.Now.Date;
this.fileName = string.Format(ConstLogFileNameFormat, this.logDate.ToString("yyyy-MM-dd"));
}
using (RichTextBox output = new RichTextBox())
{
output.Rtf = String.Empty;
if (File.Exists(this.fileName))
output.LoadFile(this.fileName, RichTextBoxStreamType.RichText);
output.Select(output.Text.Length, 0);
output.SelectedRtf = FormatLogRTF(log) + Environment.NewLine;
output.SaveFile(this.fileName, RichTextBoxStreamType.RichText);
}
}
示例9: listView_DrawSubItem
private void listView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex == 1)
{
using (var ms = new MemoryStream())
{
using (var sw = new StreamWriter(ms))
{
sw.Write(e.SubItem.Text);
sw.Flush();
ms.Seek(0, SeekOrigin.Begin);
var rtb = new RichTextBox();
{
rtb.BorderStyle = BorderStyle.None;
rtb.LoadFile(ms, RichTextBoxStreamType.RichText);
rtb.Location = e.SubItem.Bounds.Location;
rtb.Size = e.SubItem.Bounds.Size;
rtb.Parent = sender as Control;
var bmp = new Bitmap(128, 32);
rtb.DrawToBitmap(bmp, rtb.DisplayRectangle);
//bmp.Save("test.bmp");
e.Graphics.DrawImageUnscaledAndClipped(bmp, e.SubItem.Bounds);
//e.DrawBackground();
//e.Graphics.DrawString(rtb.Text, SystemFonts.DefaultFont, SystemBrushes.ControlText, e.SubItem.Bounds);
}
}
}
}
else
{
e.DrawBackground();
e.DrawText();
}
}
示例10: Main
private static void Main(string[] args)
{
try
{
var filePaths = Directory.GetFiles(Environment.CurrentDirectory, "*.rtf");
foreach (var filePath in filePaths)
{
Console.WriteLine(String.Format("Processing file: {0}", Path.GetFileName(filePath)));
var sourceFilePath = Path.Combine(@"C:\Users\Nicx\Dropbox\Transfer\", Path.GetFileName(filePath));
var destinationFilePath = Path.Combine(@"C:\Users\Nicx\Dropbox\Transfer\", Path.GetFileNameWithoutExtension(filePath) + ".txt");
var tempFilePath = Path.GetTempFileName();
var text = File.ReadAllText(sourceFilePath);
text = Regex.Replace(text, "\\\\ls-[0-9]+\\\\.*?\\{\\\\listtext\\t\\\\'95\\t\\}", "- "); // Swap out bullets
text = Regex.Replace(text, "\\\\ls-[0-9]+\\\\.*?\\{\\\\listtext\\t(.*)\\t\\}", "$1 "); // Swap out numeric lists
File.WriteAllText(tempFilePath, text);
var rtfControl = new RichTextBox();
rtfControl.LoadFile(tempFilePath);
File.Delete(tempFilePath);
var outputText = rtfControl.Text.Replace("\n", Environment.NewLine);
File.WriteAllText(destinationFilePath, outputText);
File.Delete(sourceFilePath);
Console.Write("...done.");
}
Console.WriteLine("File successfully processed.");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
}
}
示例11: InitializeMyComponent
// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
void InitializeMyComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager("SharpPrivacyTray", System.Reflection.Assembly.GetExecutingAssembly());
this.Icon = (System.Drawing.Icon)resources.GetObject("menuAbout");
this.rtbAbout = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// rtbAbout
//
rtbAbout.Dock = DockStyle.Fill;
rtbAbout.DetectUrls = true;
rtbAbout.LoadFile(Application.StartupPath + "/readme.rtf");
rtbAbout.ReadOnly = true;
rtbAbout.LinkClicked += new LinkClickedEventHandler(this.rtbAbout_LinkClicked);
//
// CreatedForm
//
this.ClientSize = new System.Drawing.Size(520, 309);
this.Text = "About SharpPrivacy...";
this.Controls.Add(rtbAbout);
this.ResumeLayout(false);
}
示例12: DocumentPanel
public DocumentPanel(string fileName)
{
InitializeComponent();
_fileName = fileName;
TabText = _fileName;
if (PlatformSupport.Platform == PlatformType.Windows)
{
Icon = Properties.Resources.document_properties;
// SharpDevelop text editor is Windows only.
var txtDocument = new TextEditorControl {Dock = DockStyle.Fill, IsReadOnly = true, Name = "txtDocument"};
Controls.Add(txtDocument);
txtDocument.SetHighlighting("SMI"); // Activate the highlighting, use the name from the SyntaxDefinition node.
txtDocument.LoadFile(_fileName);
}
else
{
var txtDocument = new RichTextBox {Dock = DockStyle.Fill, Name = "txtDocument", ReadOnly = true};
Controls.Add(txtDocument);
txtDocument.LoadFile(_fileName, RichTextBoxStreamType.PlainText);
}
}
示例13: toolStripHelp_Click
private void toolStripHelp_Click(object sender, EventArgs e)
{
Form helpWindow = new Form();
helpWindow.Height = 600;
helpWindow.Width = 600;
helpWindow.Text = "ProfessionBuddy Guide";
RichTextBox helpView = new RichTextBox();
helpView.Dock = DockStyle.Fill;
helpView.ReadOnly = true;
#if DLL
helpView.Rtf = HighVoltz.Properties.Resources.Guide;
#else
helpView.LoadFile(Path.Combine(PB.PluginPath, "Guide.rtf"));
#endif
helpWindow.Controls.Add(helpView);
helpWindow.Show();
}
示例14: initText
public static void initText(eObject obj, Panel panel)
{
int Left = obj.x1*Constant.cardWidth/100;
int Top = obj.y1*Constant.cardHeight/100;
int Width = (obj.x2-obj.x1)* Constant.cardWidth/100;
int Height = (obj.y2-obj.y1)*Constant.cardHeight/100;
string textToDisplay = obj.data;
RichTextBox txtText=new RichTextBox();
try
{
txtText.LoadFile(Constant.ePath + textToDisplay, RichTextBoxStreamType.RichText);
}
catch (Exception e)
{
MessageBox.Show("file not found");
}
txtText.Location = new System.Drawing.Point(Left, Top);
txtText.ReadOnly = true;
txtText.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
txtText.Size = new System.Drawing.Size(Width, Height);
txtText.TabStop = false;
txtText.BorderStyle = System.Windows.Forms.BorderStyle.None;
txtText.BackColor = System.Drawing.Color.White;
txtText.DetectUrls = false;
panel.Controls.Add(txtText);
}
示例15: parseRtf
public static string parseRtf(Stream fileStream)
{
RichTextBox rtb = new RichTextBox();
rtb.LoadFile(fileStream, RichTextBoxStreamType.RichText);
return rtb.Text;
}