protected override Control GetEditControl(object instance) { _source = instance; if (_source != null) { _panelBody = new Panel(); _panelBody.Width = 800; _panelBody.Height = 500; Panel panelBottom = new Panel(); panelBottom.Height = 80; panelBottom.Dock = DockStyle.Bottom; _panelBody.Controls.Add(panelBottom); MedButton btnUp = new MedButton(); btnUp.Click += new EventHandler(btnUp_Click); panelBottom.Controls.Add(btnUp); btnUp.Text = "上移(&W)"; btnUp.Location = new System.Drawing.Point(10, 10); btnUp.Width = 60; MedButton btnDown = new MedButton(); btnDown.Click += new EventHandler(btnDown_Click); panelBottom.Controls.Add(btnDown); btnDown.Text = "下移(&S)"; btnDown.Location = new System.Drawing.Point(90, 10); btnDown.Width = 60; MedButton btnAdd = new MedButton(); btnAdd.Click += new EventHandler(btnAdd_Click); panelBottom.Controls.Add(btnAdd); btnAdd.Text = "添加(&A)"; btnAdd.Location = new System.Drawing.Point(170, 10); btnAdd.Width = 60; MedButton btnDelete = new MedButton(); btnDelete.Click += new EventHandler(btnDelete_Click); panelBottom.Controls.Add(btnDelete); btnDelete.Text = "删除(&D)"; btnDelete.Location = new System.Drawing.Point(250, 10); btnDelete.Width = 60; MedButton btnOK = new MedButton(); btnOK.Click += new EventHandler(btnOK_Click); panelBottom.Controls.Add(btnOK); btnOK.Text = "确定(&O)"; btnOK.Location = new System.Drawing.Point(410, 10); btnOK.Width = 60; _gird = new MedGridView(); _gird.Columns.Add("显示文本", "显示文本"); _gird.Columns.Add("字段名称", "字段名称"); _gird.Columns.Add("宽度", "宽度"); _listBox = new ListBox(); _propertyGrid = new PropertyGrid(); if (_source is MedGridView) { (_source as MedGridView).GetMedGridViewColumns(out _medGridViewColumns); } //else // if (_source is MedDevGrid) // { // (_source as MedDevGrid).GetMedGridViewColumns(out _medGridViewColumns); // } ResetList(); _panelBody.Controls.Add(_gird); _gird.Dock = DockStyle.Left; _gird.BringToFront(); _gird.Visible = false; _panelBody.Controls.Add(_listBox); _listBox.Dock = DockStyle.Left; _listBox.BringToFront(); _listBox.Width += 30; _listBox.SelectedIndexChanged += new EventHandler(listBox_SelectedIndexChanged); _panelBody.Controls.Add(_propertyGrid); _propertyGrid.Dock = DockStyle.Fill; _propertyGrid.BringToFront(); _propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged); return(_panelBody); } else { return(base.GetEditControl(instance)); } }
//Управление доступом к пунктам меню и панели управления private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { int level = treeView1.SelectedNode.Level; if (level == 0) { tsBtnAddQuestion.Enabled = false; tsBtnAddExam.Enabled = true; tsBtnRedact.Enabled = true; tsBtnDelete.Enabled = true; tsBtnPreview.Enabled = true; tsmiAddEx.Enabled = true; tsmiAddSub.Enabled = true; tsmiAddQuest.Enabled = false; tsmiDelEx.Enabled = false; tsmiDelSub.Enabled = true; tsmiDelQuest.Enabled = false; tsmiEditEx.Enabled = false; tsmiEditQuest.Enabled = false; tsmiEditSub.Enabled = true; tsmiViewSub.Enabled = true; tsmiViewQuest.Enabled = false; tsmiViewEx.Enabled = false; } else if (level == 1) { tsBtnAddExam.Enabled = false; tsBtnAddQuestion.Enabled = true; tsBtnRedact.Enabled = true; tsmiAddEx.Enabled = false; tsmiAddSub.Enabled = true; tsmiAddQuest.Enabled = true; tsmiDelEx.Enabled = true; tsmiDelSub.Enabled = false; tsmiDelQuest.Enabled = false; tsmiEditEx.Enabled = true; tsmiEditQuest.Enabled = false; tsmiEditSub.Enabled = false; tsmiViewSub.Enabled = false; tsmiViewQuest.Enabled = false; tsmiViewEx.Enabled = true; try { using (TestAppLibrary.TestAppContext db = new TestAppLibrary.TestAppContext()) { int count = db.Questions.Where(i => i.Exam.Id == ((TestAppLibrary.Exam)treeView1.SelectedNode.Tag).Id).Count(); if (count == ((TestAppLibrary.Exam)treeView1.SelectedNode.Tag).QuestionNumber) { tsBtnAddQuestion.Enabled = false; } } } catch (Exception e1) { MessageBox.Show(e1.Message); } } else if (level == 2) { tsBtnAddExam.Enabled = false; tsBtnAddQuestion.Enabled = false; tsBtnRedact.Enabled = true; tsmiAddEx.Enabled = true; tsmiAddSub.Enabled = false; tsmiAddQuest.Enabled = false; tsmiDelEx.Enabled = true; tsmiDelSub.Enabled = false; tsmiDelQuest.Enabled = false; tsmiEditEx.Enabled = false; tsmiEditQuest.Enabled = true; tsmiEditSub.Enabled = false; tsmiViewSub.Enabled = false; tsmiViewQuest.Enabled = true; tsmiViewEx.Enabled = false; } PropertyGrid prop = new PropertyGrid(); prop.SelectedObject = treeView1.SelectedNode.Tag; prop.Parent = splitContainer1.Panel2; prop.Dock = DockStyle.Fill; prop.BringToFront(); }