티스토리 뷰

ZedGrph 디자이너에서 번개모양을 클릭하여  ContextMenuBuilder 이벤트를 자동으로 추가한다.

디자이너를 사용하지 않을경우 다음 코드를 추가한다.

 

zedGraphControl1.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler( MyContextMenuBuilder );

 

 

 

불필요한 항목을 삭제하거나 수정할 때 
private void MyContextMenuBuilder( ZedGraphControl control, ContextMenuStrip menuStrip, Point mousePt,ZedGraphControl.ContextMenuObjectState objState)
{
   foreach( ToolStripMenuItem item in menuStrip.Items )
   {
      if ( (string) item.Tag == "set_default" )
      {
         // remove the menu item
         menuStrip.Items.Remove( item );
         // or, just disable the item with this
         //item.Enabled = false; 

         break;
      }
   }
}

The item.Tag information was added after ZedGraph release version 4.3. This Tag information is actually the stringID information used internally to identify the localized strings to accomodate multiple languages. The following stringID's are used:

StringIDMenu Item
copyCopy
page_setupPage Setup...
printPrint...
save_asSave Image As...
set_defaultSet Scale to Default
show_valShow Point Values
undo_allUndo All Zoom/Pan
unzoomUn-Zoom, Un-Pan, Undo Scroll


:

 

 

새로운 항목을 추가할 때 

To add a brand new item to the context menu, your code would look something like this:

private void MyContextMenuBuilder( ZedGraphControl control, ContextMenuStrip menuStrip, Point mousePt,ZedGraphControl.ContextMenuObjectState objState )
{   
   // create a new menu item
   ToolStripMenuItem item = new ToolStripMenuItem();
   // This is the user-defined Tag so you can find this menu item later if necessary
   item.Name = "my_special_tag";
   item.Tag = "my_special_tag";
   // This is the text that will show up in the menu
   item.Text = "Do Something Special";
   // Add a handler that will respond when that menu item is selected
   item.Click += new System.EventHandler( DoSomethingSpecial );
   // Add the menu item to the menu
   menuStrip.Items.Add( item );
}

And the handler that responds when the menu item is selected would look something like this (this presumes that your ZedGraphControl is called zedGraphControl1):

 protected void DoSomethingSpecial( object sender, System.EventArgs e )
{
   // do something here.  For example, remove all curves from the graph
   zedGraphControl1.GraphPane.CurveList.Clear();
   zedGraphControl1.Refresh();
}

 

 

 

 

해당 내용 전문보기 : http://zedgraph.dariowiz.com/index43d0.html?title=Edit_the_Context_Menu

댓글
댓글쓰기 폼
공지사항
Total
135,130
Today
14
Yesterday
201
«   2019/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
글 보관함