当前位置: 首页>>代码示例>>C#>>正文


C# TextRange.CanSave方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextRange.CanSave方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.CanSave方法的具体用法?C# TextRange.CanSave怎么用?C# TextRange.CanSave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextRange的用法示例。


在下文中一共展示了TextRange.CanSave方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Window_Closing

 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     TextPointer start = this._rtb.Document.ContentStart,
                 end = this._rtb.Document.ContentEnd;
     TextRange tr = new TextRange(start, end);
     tr.Select(start, end);
     if (tr.CanSave(DataFormats.Xaml))
     {
         FileInfo fi = new FileInfo("proba.xaml");
         if (fi.Exists)
             fi.Delete();
         FileStream fs = fi.Create();
         tr.Save(fs, DataFormats.Xaml);
         fs.Flush();
         fs.Close();
     }
 }
开发者ID:jithuin,项目名称:infogeezer,代码行数:17,代码来源:LinkRichTextView.xaml.cs

示例2: Paste_RequestNavigate

 private void Paste_RequestNavigate(object sender, RequestNavigateEventArgs e)
 {
     TextPointer start = this._rtb.Document.ContentStart,
                 end = this._rtb.Document.ContentEnd;
     TextRange tr = new TextRange(start, end);
     tr.Select(start, end);
     MemoryStream ms;
     StringBuilder sb = new StringBuilder();
     foreach (String dataFormat in _listOfFormats)
     {
         if (tr.CanSave(dataFormat))
         {
             ms = new MemoryStream();
             tr.Save(ms, dataFormat);
             ms.Seek(0, SeekOrigin.Begin);
             sb.AppendLine(dataFormat);
             foreach (char c in ms.ToArray().Select<byte, char>((b) => (char)b))
             {
                 sb.Append(c);
             }
             sb.AppendLine();
         }
         //_tb.Text = sb.ToString();
     }
 }
开发者ID:jithuin,项目名称:infogeezer,代码行数:25,代码来源:LinkRichTextView.xaml.cs

示例3: Format

        internal string Format(CharPosition start, CharPosition end)
        {
            Paragraph paragraph = new Paragraph();
            for (int lineIndex = start.CharacterY; lineIndex <= end.CharacterY; ++lineIndex)
            {
                string lineContent = textBuffer.GetLineContent(lineIndex);
                if (string.IsNullOrEmpty(lineContent))
                    continue;

                int charStart = 0, lineLength = lineContent.Length;
                if (lineIndex == start.CharacterY) // Starting line.
                    charStart = start.CharacterX;
                if (lineIndex == end.CharacterY) // Ending line.
                    lineLength = end.CharacterX;

                for (int charIndex = charStart; charIndex < lineLength; ++charIndex)
                {
                    CodeFragment fragment = null;
                    int fragmentWidth = codeFragmentManager.GetFragment(
                        charIndex, lineIndex, out fragment);

                    if (null == fragment)
                    {
                        // We have encountered a whitespace character (e.g. space, tab, etc),
                        // scan forward until we get a non-whitespace character, then flush
                        // whatever we have found (whitespaces) into the paragraph at one go.
                        //
                        int startIndex = charIndex;
                        while (charIndex < lineLength)
                        {
                            fragmentWidth = codeFragmentManager.GetFragment(
                                charIndex, lineIndex, out fragment);

                            if (fragmentWidth > 0 && (null != fragment))
                            {
                                string text = lineContent.Substring(startIndex, charIndex - startIndex);
                                FormatFragment(null, text, paragraph);
                                break;
                            }

                            charIndex = charIndex + 1;
                        }

                        if (charIndex >= lineLength)
                        {
                            // If there was no fragment at the time we reached the
                            // end of line, then flush out the remaining whitespaces,
                            // if there is any.
                            //
                            if (null == fragment && (startIndex < charIndex))
                            {
                                FormatFragment(null, lineContent.Substring(startIndex,
                                    charIndex - startIndex), paragraph);
                            }

                            break; // Reach the end of line.
                        }
                    }

                    int offsetToNextChar = fragmentWidth - 1;
                    if ((charIndex + fragmentWidth) > (lineLength - 1))
                    {
                        fragmentWidth = (lineLength - 1) - charIndex;
                        offsetToNextChar = fragmentWidth - 1;
                    }

                    // Initialize the text store.
                    string textContent = string.Empty;
                    textContent = lineContent.Substring(charIndex,
                        ((fragmentWidth == 0) ? 1 : fragmentWidth));

                    FormatFragment(fragment, textContent, paragraph);
                    if (fragmentWidth > 0)
                        charIndex += offsetToNextChar;
                }
            }

            FlowDocument flowDocument = new FlowDocument();
            flowDocument.TextAlignment = TextAlignment.Left;
            flowDocument.FontSize = 11;
            flowDocument.FontFamily = new FontFamily("Consolas");
            flowDocument.FlowDirection = FlowDirection.LeftToRight;
            flowDocument.TextAlignment = TextAlignment.Left;
            flowDocument.Blocks.Add(paragraph);

            TextRange range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
            if (range.CanSave(DataFormats.Rtf))
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    range.Save(stream, DataFormats.Rtf);
                    stream.Flush();
                    return (Encoding.UTF8.GetString(stream.ToArray()));
                }
            }

            return string.Empty;
        }
开发者ID:samuto,项目名称:designscript,代码行数:98,代码来源:RichTextFormatter.cs

示例4: Save

        public void Save(TextRange storyText, string storyFileName)
        {
            // Data format for the story file.
            string dataFormat = DataFormats.Rtf;

            // Absolute path to the application folder
            string appLocation = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                App.ApplicationFolderName);

            // Absolute path to the stories folder
            string storiesLocation = Path.Combine(appLocation, Const.StoriesFolderName);

            // Fully qualified path to the new story file
            storyFileName = GetSafeFileName(storyFileName);
            string storyAbsolutePath = Path.Combine(storiesLocation, storyFileName);

            try
            {
                // Create the stories directory if it doesn't exist
                if (!Directory.Exists(storiesLocation))
                    Directory.CreateDirectory(storiesLocation);

                // Open the file for writing the richtext
                using (FileStream stream = File.Create(storyAbsolutePath))
                {
                    // Store the relative path to the story
                    this.relativePath = Path.Combine(Const.StoriesFolderName, storyFileName);

                    // Save the story to disk
                    if (storyText.CanSave(dataFormat))
                        storyText.Save(stream, dataFormat);
                }
            }
            catch
            {
                // Could not save the story. Handle all exceptions
                // the same, ignore and continue.
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:40,代码来源:Story.cs

示例5: MenuItemSpeichern_Click

        private void MenuItemSpeichern_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (SaveTxtChanges())
                {
                    SaveFileDialog save = new SaveFileDialog();
                    save.Filter = "Earthdawncharakterarchiv (*.edz)|*.edz";
                    if (save.ShowDialog() == true)
                    {
                        Directory.CreateDirectory(save.FileName.Replace(save.SafeFileName, "") + "\\TmpED\\");
                        using(ZipArchive zip = ZipFile.Open(save.FileName, ZipArchiveMode.Update))
                        {
                            ZipArchiveEntry bin = zip.GetEntry("Charakterdaten.bin");
                            ZipArchiveEntry xaml = zip.GetEntry("Charakternotizen.xaml");
                            if (bin != null)
                            {
                                bin.Delete();
                            }
                            if (xaml != null)
                            {
                                xaml.Delete();
                            }

                            FileStream sfs = new FileStream(save.FileName.Replace(save.SafeFileName, "") + "\\TmpED\\Charakterdaten.bin", FileMode.Create, FileAccess.ReadWrite);
                            BinaryFormatter formatter = new BinaryFormatter();
                            formatter.Serialize(sfs, aktChar);
                            sfs.Close();
                            zip.CreateEntryFromFile(save.FileName.Replace(save.SafeFileName, "") + "\\TmpED\\Charakterdaten.bin", "Charakterdaten.bin");

                            FileStream nfs = new FileStream(save.FileName.Replace(save.SafeFileName, "") + "\\TmpED\\Charakternotizen.xaml", FileMode.Create, FileAccess.ReadWrite);
                            TextRange rng = new TextRange(Notizen.ContentStart, Notizen.ContentEnd);
                            if (rng.CanSave(DataFormats.Xaml))
                            {
                                rng.Save(nfs, DataFormats.Xaml);
                            }
                            nfs.Close();
                            zip.CreateEntryFromFile(save.FileName.Replace(save.SafeFileName, "") + "\\TmpED\\Charakternotizen.xaml", "Charakternotizen.xaml");
                        }
                        Directory.Delete(save.FileName.Replace(save.SafeFileName, "") + "\\TmpED\\", true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            } 
        }
开发者ID:knotho,项目名称:EDCharBogen,代码行数:48,代码来源:MainWindow.xaml.cs

示例6: OnClick_SaveScript

        //public event ScriptParsedHandler OnScriptParsed;
        //private void ScriptParsed()
        //{
        //    if (OnScriptParsed != null)
        //        OnScriptParsed(this, new ScriptParsedEventArgs());
        //}

        //public event ModelChangedHandler OnModelChangedByScript;
        //private void ModelChangedByScript(XbimModel newModel)
        //{
        //    if (OnModelChangedByScript != null)
        //        OnModelChangedByScript(this, new ModelChangedEventArgs(newModel));
        //}


        private void OnClick_SaveScript(object sender, RoutedEventArgs e)
        {
            string dataFormat = "Text";
            TextRange txtRange = new TextRange(ScriptText.Document.ContentStart, ScriptText.Document.ContentEnd);
            string script = txtRange.Text.Trim();
            if (String.IsNullOrEmpty(script))
            {
                System.Windows.MessageBox.Show("There is no script to save.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog();
            dlg.AddExtension = true;
            dlg.DefaultExt = ".bql";
            dlg.Filter = "Building Query Language|*.bql";
            dlg.FilterIndex = 0;
            dlg.Title = "Set file name of the script";
            dlg.OverwritePrompt = true;
            dlg.ValidateNames = true;
            dlg.FileOk += delegate(object s, System.ComponentModel.CancelEventArgs eArg)
            {
                var name = dlg.FileName;
                FileStream file = null;
                try
                {
                    file = new FileStream(name, FileMode.Create);
                    if (txtRange.CanSave(dataFormat))
                    {
                        txtRange.Save(file, dataFormat);
                    }

                    this.Title = "BQL Console - " + System.IO.Path.GetFileName(name);
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(string.Format("Saving script to file failed with message : {0}.", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    if (file != null)
                        file.Close();
                }
            };
            dlg.ShowDialog();
        }
开发者ID:bnaand,项目名称:xBim-Toolkit,代码行数:59,代码来源:MainWindow.xaml.cs


注:本文中的System.Windows.Documents.TextRange.CanSave方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。