richtextboxコントロールを持つIDEのような(非編集可能な)プログラムを設計しようとしています。基本的には、ユーザーが+/-ボタンをクリックするたびにRTBの左側に配置されたツリービューが必要になります。展開可能な折りたたみ可能な範囲は、中括弧がどこにあっても定義されます。複雑なツリービューデザイン
int main()
{
if (...)
{
if (...)
{
}
}
else
{
}
}
私は一番上のカーリーブラケットをクリックした場合、それはメイン関数内のすべてを崩壊してしまう:RTBでたとえば私のようなものを持っていた場合。基本的には、中括弧の中に含まれているものは折りたたまれているものです。要約すると、Visual Studioの展開/折りたたみコード関数に非常によく似たものを設計しようとしていますが、if/else関数でも同様です。
私はブラケットマッチングアルゴリズムを知っていて、どのブラケットペアが一致するかを知るためにスタックを実装しました(タプルのリストに格納されている行番号)。
私が主に抱いている問題は、実際のツリービューを設計する方法です。ツリービューは線形にする必要があります。ノードは別のノードの上に追加されません。私は、実際に別のノードの上に子ノードを追加することなく、展開/折りたたみボタンを追加することができるアプローチを認識していません。
また、+/-ボタンと単一の垂直線を除いて、ツリービューノードは編集不可、非表示、クリック不可にする必要があります。
最後に、これは上記の要件を満たしていれば、RTBの垂直スクロールイベントが正しくツリービューをスクロールする必要があると仮定しています。つまり、ツリービューの折りたたみ/展開セクションは、RTBに表示されるコードの部分に基づいて更新されます。ここで
は、私は木を初期化するために使用していたコードのセクションです:私はこれは本当に必要なことが、念のためではないと考えているが、ここで
public partial class LogicSimulationViewerForm : Form
{
private List<Tuple<string,Boolean>> visibleLines = new List<Tuple<string,Boolean>>();
private List<Tuple<int, int>> collapseRange = new List<Tuple<int, int>>();
private void TreeInit()
{
TreeNode tn;
Stack<int> openBracketLine = new Stack<int>();
int i = 0;
TreeLogicCode.Nodes.Clear();
foreach (string s in rtbLogicCode.Lines)
{
visibleLines.Add(Tuple.Create(s, true));
if (s == "{")
{
openBracketLine.Push(i);
}
else if (s == "}")
{
collapseRange.Add(Tuple.Create(openBracketLine.Pop(),i));
}
i++;
}
}
は、Designer.scのソースコードです:
namespace DDCUI
{
partial class LogicSimulationViewerForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.TreeLogicCode = new System.Windows.Forms.TreeView();
this.labelLogicCode = new System.Windows.Forms.Label();
this.rtbLogicCode = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// TreeLogicCode
//
this.TreeLogicCode.Dock = System.Windows.Forms.DockStyle.Left;
this.TreeLogicCode.Location = new System.Drawing.Point(50, 0);
this.TreeLogicCode.Name = "TreeLogicCode";
this.TreeLogicCode.Scrollable = false;
this.TreeLogicCode.Size = new System.Drawing.Size(40, 600);
this.TreeLogicCode.TabIndex = 4;
//
// labelLogicCode
//
this.labelLogicCode.BackColor = System.Drawing.Color.LightGray;
this.labelLogicCode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelLogicCode.Dock = System.Windows.Forms.DockStyle.Left;
this.labelLogicCode.ForeColor = System.Drawing.SystemColors.ControlText;
this.labelLogicCode.Location = new System.Drawing.Point(0, 0);
this.labelLogicCode.Margin = new System.Windows.Forms.Padding(3);
this.labelLogicCode.Name = "labelLogicCode";
this.labelLogicCode.Padding = new System.Windows.Forms.Padding(3);
this.labelLogicCode.Size = new System.Drawing.Size(50, 600);
this.labelLogicCode.TabIndex = 3;
this.labelLogicCode.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// rtbLogicCode
//
this.rtbLogicCode.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtbLogicCode.Location = new System.Drawing.Point(90, 0);
this.rtbLogicCode.Name = "rtbLogicCode";
this.rtbLogicCode.Size = new System.Drawing.Size(510, 600);
this.rtbLogicCode.TabIndex = 5;
this.rtbLogicCode.Text = "";
this.rtbLogicCode.VScroll += new System.EventHandler(this.rtbLogicCode_VScroll);
//
// LogicSimulationViewerForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(600, 600);
this.Controls.Add(this.rtbLogicCode);
this.Controls.Add(this.TreeLogicCode);
this.Controls.Add(this.labelLogicCode);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "LogicSimulationViewerForm";
this.Text = "LogicSimulationViewerForm";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TreeView TreeLogicCode;
private System.Windows.Forms.Label labelLogicCode;
private System.Windows.Forms.RichTextBox rtbLogicCode;
}
}
この問題を解決するためのガイダンスは本当にありがとうございます。前もって感謝します。
残念ながら、上記の問題の説明は、クライアントがプログラムに求めていたものです。私はScantillaを開こうとしましたが、私のマシンではコンパイルされないので、ここで私は助けに来ました。 – l46kok
DLLをツールボックスに追加してフォームをドラッグするだけでコンパイルする必要はありません。 – MMK
実際に私が開発しているプログラムは、商用目的であり、ライセンスのために言及したオープンソースプロジェクトを使用できないようです。 – l46kok