[Mono-winforms-list] TreeView - selected node is hide

Rafael Teixeira monoman at gmail.com
Thu Oct 13 15:30:25 EDT 2005


I have a patch pending approval for more than a month now to correct
some miscalculations on the rectangle-size (it is not using the font
metrics to do it currently) that may cause this behaviour as it wraps
text incorrectly, when the rectangle is to small.

An update version of the patch for TreeView.cs is attached. See if it helps.

Regards,

On 10/12/05, Pavel Bansky <levap at bansky.net> wrote:
> Hello Mono folks,
>
> I found strange behaivor of TreeView under KDE. Selected node is hiden
> under 'selection' so you can't see the text. Seems like rectangle around
> selected item is filled with colour. Here is the screenshot
> http://bansky.net/treeview.png
>
> have a nice day
>
> Pavel
>
>
> Code goes here:
>
> using System;
> using System.Drawing;
> using System.Windows.Forms;
>
> namespace TreeViewTest
> {
>
>         public class MyNode : TreeNode
>         {
>                 public string filename;
>         }
>
>         public class MainForm : Form
>         {
>                 private System.Windows.Forms.StatusBar statusBar1;
>                 private System.Windows.Forms.TreeView treeView1;
>                 private System.Windows.Forms.Button btnAdd;
>                 public MainForm()
>                 {
>                 this.btnAdd = new System.Windows.Forms.Button();
>                 this.treeView1 = new System.Windows.Forms.TreeView();
>                 this.statusBar1 = new System.Windows.Forms.StatusBar();
>                 this.SuspendLayout();
>
>                 this.btnAdd.Location = new System.Drawing.Point(8, 8);
>                 this.btnAdd.Name = "btnAdd";
>                 this.btnAdd.Text = "button1";
>                 this.btnAdd.Click += new System.EventHandler(this.BtnAddClick);
>
>                 this.treeView1.ImageIndex = -1;
>                 this.treeView1.Location = new System.Drawing.Point(104, 8);
>                 this.treeView1.Name = "treeView1";
>                 this.treeView1.ItemHeight = 20;
>                 this.treeView1.Size = new System.Drawing.Size(121, 192);
>                 this.treeView1.AfterSelect += new
> System.Windows.Forms.TreeViewEventHandler(this.TreeView1AfterSelect);
>
>                 this.statusBar1.Location = new System.Drawing.Point(0, 223);
>                 this.statusBar1.Name = "statusBar1";
>                 this.statusBar1.Size = new System.Drawing.Size(240, 22);
>                 this.statusBar1.Text = "statusBar1";
>
>                 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
>                 this.ClientSize = new System.Drawing.Size(240, 245);
>                 this.Controls.Add(this.statusBar1);
>                 this.Controls.Add(this.btnAdd);
>                 his.Controls.Add(this.treeView1);
>                 this.Name = "MainForm";
>                 this.Text = "MainForm";
>                 this.ResumeLayout(false);
>                 }
>
>                 [STAThread]
>                 public static void Main(string[] args)
>                 {
>                         Application.Run(new MainForm());
>                 }
>
>                 void BtnAddClick(object sender, System.EventArgs e)
>                 {
>                         MyNode mn = new MyNode();
>                         mn.Text = "Some_file";
>                         mn.filename = "some_name.txt";
>                         treeView1.Nodes.Add(mn);
>                 }
>
>                 void TreeView1AfterSelect(object sender,
> System.Windows.Forms.TreeViewEventArgs e)
>                 {
>                         MyNode mn = (MyNode)treeView1.SelectedNode;
>                         statusBar1.Text = mn.filename;
>                 }
>
>         }
> }
>
>
> --
> __________________________________________________________
>
> Pavel Bánský
> levap at bansky.net                        I write code...
> __________________________________________________________
>
> _______________________________________________
> Mono-winforms-list maillist  -  Mono-winforms-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-winforms-list
>


--
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes.
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
It hurts!
-------------- next part --------------
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51682)
+++ ChangeLog	(working copy)
@@ -1,3 +1,6 @@
+2005-10-13  Rafael Teixeira <rafaelteixeirabr at hotmail.com>
+	* TreeView.cs: correct calculations of node bounds
+
 2005-10-13  Peter Dennis Bartok  <pbartok at novell.com>
 
 	* XplatUI.cs, XplatUIDriver.cs, XplatUIOSX.cs: Added 
Index: TreeView.cs
===================================================================
--- TreeView.cs	(revision 51682)
+++ TreeView.cs	(working copy)
@@ -78,6 +78,7 @@
 		private int used_height;
 		
 		private int update_stack;
+		private StringFormat string_format;
 
 		private TreeViewEventHandler on_after_check;
 		private TreeViewEventHandler on_after_collapse;
@@ -94,12 +95,15 @@
 		private int open_node_count = -1;
 
 		private long handle_count = 1;
-
 		#endregion	// Fields
 
 		#region Public Constructors	
 		public TreeView ()
 		{
+			string_format = new StringFormat();
+			string_format.Alignment = StringAlignment.Center;
+			string_format.LineAlignment = StringAlignment.Center;
+
 			base.background_color = ThemeEngine.Current.ColorWindow;
 			base.foreground_color = ThemeEngine.Current.ColorWindowText;
 
@@ -1031,14 +1035,12 @@
 			UpdateNode(edit_node);
 		}
 
-		[MonoTODO("When Graphics.MeasureString starts to work correctly use it")]
 		private void UpdateNodeBounds (TreeNode node, int x, int y, int item_height, Graphics dc)
 		{
-//			SizeF size = dc.MeasureString (Text, Font, ClientSize.Width, new StringFormat ());
-//		int width = (int) size.Width + 3;
 			Font font = node.NodeFont;
 			if (node.NodeFont == null)
 				font = Font;
+			SizeF size = dc.MeasureString (node.Text, font, 0, string_format);
 			int width = (int)(node.Text.Length * font.Size * 0.85);
 			node.UpdateBounds (x, y, width, item_height);
 		}
@@ -1055,9 +1057,6 @@
 		 
 		private void DrawStaticNode (TreeNode node, Graphics dc)
 		{
-			StringFormat format = new StringFormat ();
-			format.LineAlignment = StringAlignment.Center;
-
 			if (!full_row_select)
 				DrawSelectionAndFocus(node, dc, node.Bounds);
 
@@ -1068,7 +1067,7 @@
 					ThemeEngine.Current.ColorHighlightText : node.ForeColor);
 			dc.DrawString (node.Text, font,
 					ThemeEngine.Current.ResPool.GetSolidBrush (text_color),
-					node.Bounds, format);
+					node.Bounds, string_format);
 		}
 
 		private void DrawNode (TreeNode node, Graphics dc, Rectangle clip, ref int depth, int item_height, int max_height)


More information about the Mono-winforms-list mailing list