Example #1
0
        /// <summary>
        /// 构造函数初始化
        /// </summary>
        public SVObjTreeView()
        {
            this.Indent     = 20;
            this.ItemHeight = 20;
            this.Font       = new Font(this.Font.FontFamily, 11.0f);


            ///建立名称与控件的对应关系
            _nameDict = new Dictionary <String, Function1>();
            _nameDict.Add("SVButton", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_btnNode))
                {
                    cc.Nodes.Add(_btnNode);
                }

                SVButton button = (SVButton)c;
                //String text = String.Format("按钮-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _btnNode.Nodes.Add(node);
                _btnNode.Text = String.Format("按钮(计数:{0})", _btnNode.Nodes.Count);
            });

            _nameDict.Add("SVLabel", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_textNode))
                {
                    cc.Nodes.Add(_textNode);
                }

                SVLabel button = (SVLabel)c;
                //String text = String.Format("文本-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _textNode.Nodes.Add(node);
                _textNode.Text = String.Format("文本(计数:{0})", _textNode.Nodes.Count);
            });

            _nameDict.Add("SVAnalog", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_analogNode))
                {
                    cc.Nodes.Add(_analogNode);
                }

                SVAnalog button = (SVAnalog)c;
                //String text = String.Format("模拟量-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _analogNode.Nodes.Add(node);
                _analogNode.Text = String.Format("模拟量(计数:{0})", _analogNode.Nodes.Count);
            });

            _nameDict.Add("SVBinary", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_binaryNode))
                {
                    cc.Nodes.Add(_binaryNode);
                }

                SVBinary button = (SVBinary)c;
                //String text = String.Format("开关量-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _binaryNode.Nodes.Add(node);
                _binaryNode.Text = String.Format("开关量(计数:{0})", _binaryNode.Nodes.Count);
            });

            _nameDict.Add("SVCurve", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_curveNode))
                {
                    cc.Nodes.Add(_curveNode);
                }

                SVCurve button = (SVCurve)c;
                //String text = String.Format("趋势图-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _curveNode.Nodes.Add(node);
                _curveNode.Text = String.Format("趋势图(计数:{0})", _curveNode.Nodes.Count);
            });

            _nameDict.Add("SVIcon", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_iconNode))
                {
                    cc.Nodes.Add(_iconNode);
                }

                SVIcon button = (SVIcon)c;
                //String text = String.Format("静态图-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _iconNode.Nodes.Add(node);
                _iconNode.Text = String.Format("静态图(计数:{0})", _iconNode.Nodes.Count);
            });

            _nameDict.Add("SVLine", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_lineNode))
                {
                    cc.Nodes.Add(_lineNode);
                }

                SVLine button = (SVLine)c;
                //String text = String.Format("直线-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _lineNode.Nodes.Add(node);
                _lineNode.Text = String.Format("直线(计数:{0})", _lineNode.Nodes.Count);
            });

            _nameDict.Add("SVGif", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_gifNode))
                {
                    cc.Nodes.Add(_gifNode);
                }

                SVGif button = (SVGif)c;
                //String text = String.Format("动态图-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _gifNode.Nodes.Add(node);
                _gifNode.Text = String.Format("动态图(计数:{0})", _gifNode.Nodes.Count);
            });

            _nameDict.Add("SVHeartbeat", (cc, c) =>
            {
                if (!cc.Nodes.Contains(_heartNode))
                {
                    cc.Nodes.Add(_heartNode);
                }

                SVHeartbeat button = (SVHeartbeat)c;
                //String text = String.Format("心跳控件-(ID:{0})", button.Attrib.ID);
                String text = String.Format("ID:{0}", button.Attrib.ID);

                ObjTreeNode node = new ObjTreeNode();
                node.Text        = text;
                node.objControl  = c;
                _heartNode.Nodes.Add(node);
                _heartNode.Text = String.Format("心跳控件(计数:{0})", _heartNode.Nodes.Count);
            });

            this.AfterSelect    += new TreeViewEventHandler(SVObjTreeView_AfterSelect);
            this.NodeMouseClick += new TreeNodeMouseClickEventHandler(SVObjTreeView_NodeMouseClick);
        }
Example #2
0
        /// <summary>
        /// 通过变量名称来查找对应控件
        /// </summary>
        /// <param oldName="findString">变量名称</param>
        private void findStr(string findString)
        {
            if (String.IsNullOrWhiteSpace(findString))
            {
                return;
            }

            _findView.Clear();
            _findView.AppendText("---------------查找结果如下:-----------------\n");
            _findView.AppendText("\n");

            foreach (SVPageNode pageNode in _treeView.Nodes)
            {
                foreach (TreeNode classItem in pageNode.Nodes)
                {
                    foreach (SVPageNode item in classItem.Nodes)
                    {
                        SVPageWidget widget = item.Addtionobj as SVPageWidget;
                        if (widget == null)
                        {
                            continue;
                        }

                        foreach (var panel in widget.Controls)
                        {
                            //如果为按钮
                            if (panel is SVButton)
                            {
                                SVButton button = (SVButton)panel;
                                String   str    = button.Attrib.BtnVarText.VarName;
                                outputFindResult(button, str);

                                str = button.Attrib.EnVarText.VarName;
                                outputFindResult(button, str);
                            }

                            //如果为模拟量
                            if (panel is SVAnalog)
                            {
                                SVAnalog analog = (SVAnalog)panel;
                                String   str    = analog.Attrib.Variable.VarName;
                                outputFindResult(analog, str);
                            }

                            //如果为开关量
                            if (panel is SVBinary)
                            {
                                SVBinary binary = (SVBinary)panel;
                                String   str    = binary.Attrib.Variable.VarName;
                                outputFindResult(binary, str);
                            }

                            //动态图
                            if (panel is SVGif)
                            {
                                SVGif gif = (SVGif)panel;
                                foreach (var str in gif.Attrib.VarName)
                                {
                                    outputFindResult(gif, str);
                                }
                            }

                            //趋势图
                            if (panel is SVCurve)
                            {
                                SVCurve curve = (SVCurve)panel;
                                foreach (var str in curve.Attrib.Variable)
                                {
                                    outputFindResult(curve, str.Var.VarName);
                                }
                            }
                        }
                    }
                }
            }

            if (!_findView.isMatches())
            {
                _findView.AppendText("没有找到符合条件的相关内容!");
            }
        }