質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Q&A

解決済

1回答

429閲覧

【C♯超初心者】WPFのツールボックスで配置したTextBoxを横80文字ほどで改行させたい

napo

総合スコア7

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

0グッド

0クリップ

投稿2018/01/22 12:08

クリップボードからデータを取得し文字数を表示するプログラムを教えてもらったのですが起動はでき、ボタンを押すとクリップボードにある文字を表示もできるのですが、横1行だけにしか表示されません。長い文章などは起動しているウィンドウを横に拡大するとちゃんと表示されています。WPFのツールボックスで配置したTextBoxを横80文字ほどで改行させたいです。

###該当のソースコード
C♯ .NET Framwork 4.6.1 windowsフォームアプリケーション VisualStudio2017

【Foem1.cs】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ButtonTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e) { textBox1.Text = ""; { //クリップボードからデータを取得する IDataObject data = Clipboard.GetDataObject(); //取得した文字列をセットする textBox1.Text = (string)data.GetData(DataFormats.Text); } } }

}

【Form1.Designer.cs】

namespace ButtonTest
{
partial class Form1
{
/// <summary>
/// 必要なデザイナー変数です。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary> /// 使用中のリソースをすべてクリーンアップします。 /// </summary> /// <param name="disposing">マネージ リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows フォーム デザイナーで生成されたコード /// <summary> /// デザイナー サポートに必要なメソッドです。このメソッドの内容を /// コード エディターで変更しないでください。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(21, 50); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(0, 12); this.label1.TabIndex = 1; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(12, 41); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(518, 19); this.textBox1.TabIndex = 2; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(542, 428); this.Controls.Add(this.textBox1); this.Controls.Add(this.label1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox1; }

}

どこまでソースを貼ればよいのか分からず、非常に見にくいですがよろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

WPF とありますが、ソースを見ると明らかに Windows Forms です。
この二つは混同してはいけません。

80 文字とありますが、テキストを編集してもいいのであればできます。
そうでなければ無理です。

文字数関係なく文字幅で折り返すならこちら。
10.文字列を折り返して表示する

投稿2018/01/22 12:16

Zuishin

総合スコア28660

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問