全て
| カテゴリ未分類
| 通常
| 数学
| 投資
| 副業
| 転職・就職
| ブログ
| 株Stock
| VBA
| SharePoint
| REST API
| RenderListDataAsStream
| PowerAutomateDesktop
| Graph API
| PowerApps
| PowerAutomate
| PowerFx
| OfficeScriptオフィススクリプト
| PowerAutomate日時Excel日時相互関係
| PowerShell
| Dataverse
| UiPath
| OneDrive
| LINQ
| VB.NET
| C#.NET
| WPFC#.NET
| Git
カテゴリ:C#.NET
C# WPF で RichTextBox のテキストを取得するためには、RichTextBox の内容を操作する方法を利用します。以下は、RichTextBox のテキストを取得するためのサンプルコードです。 ```csharp using System.Windows; using System.Windows.Controls; namespace WpfApp { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { // RichTextBox のテキストを取得します string text = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text; MessageBox.Show(text); } } } ``` XAML ファイルには、RichTextBox と Button を配置しておきます。 ```xml <Window x:Class="WpfApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="450" Width="800"> <Grid> <RichTextBox x:Name="richTextBox" HorizontalAlignment="Left" VerticalAlignment="Top" Height="200" Width="300"/> <Button Content="Get Text" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="320,10,0,0" Click="Button_Click"/> </Grid> </Window> ``` この例では、ボタンがクリックされると、RichTextBox の内容が取得されてメッセージボックスに表示されます。 TextRange クラスを使用して、RichTextBox の内容を取得しています。 お気に入りの記事を「いいね!」で応援しよう
Last updated
2024.05.03 16:37:43
[C#.NET] カテゴリの最新記事
|