|
I am wanting to draw anchors at the middle point of each listview item of the list view that the control host is inheriting. I was having trouble getting the anchor points to line up exactly with the hosted listview item, so I inherited and was able to get it to work.
Below is the code. Thanks in advance
Inheriting Class -----------------------------
using System; using System.Collections.Generic; using System.Text;
namespace Prototype { public class TestClass : MindFusion.Diagramming.WinForms.ControlHost { private System.Windows.Forms.ColumnHeader columnHeader1; public System.Windows.Forms.ListView listView1;
public TestClass(MindFusion.Diagramming.WinForms.FlowChart flow) : base(flow) { System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("One"); System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("Two"); System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("Three"); System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("Four"); System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("Five"); System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("6"); System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem("7"); System.Windows.Forms.ListViewItem listViewItem8 = new System.Windows.Forms.ListViewItem("8"); System.Windows.Forms.ListViewItem listViewItem9 = new System.Windows.Forms.ListViewItem("9"); System.Windows.Forms.ListViewItem listViewItem10 = new System.Windows.Forms.ListViewItem("99"); this.listView1 = new System.Windows.Forms.ListView(); this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.listView1.BackColor = System.Drawing.SystemColors.MenuHighlight; this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1}); // this.listView1.Dock = System.Windows.Forms.DockStyle.Fill; this.listView1.FullRowSelect = true; this.listView1.GridLines = true; this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { listViewItem1, listViewItem2, listViewItem3, listViewItem4, listViewItem5, listViewItem6, listViewItem7, listViewItem8, listViewItem9, listViewItem10}); this.listView1.Location = new System.Drawing.Point(0, 0); this.listView1.Name = "listView1"; this.listView1.Size = new System.Drawing.Size(400, 170); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; // // columnHeader1 // this.columnHeader1.Text = "Name"; this.columnHeader1.Width = 220;
this.Control = this.listView1;
this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(listView1_MouseClick); }
void listView1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { this.Selected = true; }
} }
Use of Class --------------------------------------------
TestClass host = new TestClass(this.flowChart1); host.Resize(300, 250); host.HandlesStyle = HandlesStyle.EasyMove; host.CtrlMouseAction = HostMouseAction.PassToControl; host.AllowIncomingArrows = true; host.AllowIncomingArrows = true; host.Locked = false; host.IgnoreLayout = true;
Console.WriteLine("Box Diff: " + Convert.ToString( host.BoundingRect.Y - host.listView1.Location.Y));
AnchorPattern anchor = new AnchorPattern(); float pos = 0; int diff = 4;
foreach (ListViewItem item in host.listView1.Items) {
pos = (item.Bounds.Y + diff) + (item.Bounds.Height / 2); pos = pos / (host.BoundingRect.Height); //determine if item is visible if ((item.Bounds.Y + (item.Bounds.Height)) < host.BoundingRect.Height) { AnchorPoint point = new AnchorPoint(100,pos * 100,true, true, MarkStyle.Circle, Color.Red); point.ToolTip = item.Text; point.Tag = item; anchor.Points.Add(point); Console.WriteLine("Point: " + Convert.ToString((pos * 100)) + " Anchor: " + point.Y.ToString()); } else { Console.WriteLine("Not visible"); }
}
host.AnchorPattern = anchor;
this.flowChart1.ZoomToFit(); }
|