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:
StringID | Menu Item |
---|---|
copy | Copy |
page_setup | Page Setup... |
Print... | |
save_as | Save Image As... |
set_default | Set Scale to Default |
show_val | Show Point Values |
undo_all | Undo All Zoom/Pan |
unzoom | Un-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
'컴퓨터 > C#' 카테고리의 다른 글
[C#] C#에서 C++ DLL 사용하기 (1) | 2015.06.15 |
---|---|
[C#] string to DateTime (0) | 2015.02.26 |
[C#] Directory.GetFiles (0) | 2014.12.31 |
[C#] Array 배열 다루기 (생성, 복사, 부분 복사) (0) | 2014.11.05 |
[C#] Text 파일 쓰기 (0) | 2014.11.03 |