CommandEventArgs类学习

本文深入探讨了CommandEventArgs类在C#中的功能,包括其构造函数、属性及其在实际代码中的应用案例。通过示例代码解析,帮助开发者掌握如何使用此类进行事件处理。

1.CommandEvent类的作用——为Command事件提供数据

语法(C#)Public class CommandEventArgs: EventArgs;从中可以看出该类继承了EventArgs

2.构造函数

(1)CommandEventArgs(CommandEventArgs)——Initializes a new instance of the CommandEventArgs class with another CommandEventArgs object.

语法:

public CommandEventArgs(CommandEventArgs e )

(2)CommandEventArgs(String, Object)——Initializes a new instance of the CommandEventArgs class with the specified command name and argument.

语法:

public CommandEventArgs(string commandName,Object argument)

 

3.属性

 

(1)CommandArgument—— Gets the argument for the command.

 

(2)CommandName——Gets the name of the command.

 

<asp:LinkButton ID="ActiveButton" Text="Active" CommandName="show" CommandArgument="0" OnCommand="Select_Command" runat="server"/>

 

protected void Select_Command(object sender, CommandEventArgs e)
{

ListDataSource.SelectParameters["IsComplete"].DefaultValue =
e.CommandArgument.ToString();
if (e.CommandName == "show")
SearchText.Text = "";
ViewState["CurrentTab"] = e.CommandArgument;
}

 


object sender,在以上代码中sender指代的是——System.Web.UI.WebControls.LinkButton

 

CommandEventArgs e,e为CommandEventArgs的一个实例,用e.CommandArgument和e.CommandName来获取该对象的属性

 

转载于:https://www.cnblogs.com/January/archive/2011/10/23/2221715.html

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Windows; using Newtonsoft.Json.Linq; using System; using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace JavaScriptSamples { public class ChartCommands { private PaletteSet _chps = null; private static Document _curDoc = null; private bool _refresh = false; [DllImport( "AcJsCoreStub.crx", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "acjsInvokeAsync")] extern static private int acjsInvokeAsync( string name, string jsonArgs ); [CommandMethod("CHART")] public void ChartPalette() { // We're storing the "launch document" as we're attaching // various event handlers to it _curDoc = Application.DocumentManager.MdiActiveDocument; // Only attach event handlers if the palette isn't already // there (in which case it will already have them) var attachHandlers = (_chps == null); _chps = Utils.ShowPalette( _chps, new Guid("F76509E7-25E4-4415-8C67-2E92118F3B84"), "CHART", "D3.js Examples", GetHtmlPathChart() ); if (attachHandlers && _curDoc != null) { AddHandlers(_curDoc); Application.DocumentManager.DocumentActivated += OnDocumentActivated; _curDoc.BeginDocumentClose += (s, e) => { RemoveHandlers(_curDoc); _curDoc = null; }; // When the PaletteSet gets destroyed we remove // our event handlers _chps.PaletteSetDestroy += OnPaletteSetDestroy; } } [JavaScriptCallback("SelectObjectsOfType")] public string SelectObjectsOfType(string jsonArgs) { // Default result is an error var res = "{\"retCode\":1}"; var doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) return res; var ed = doc.Editor; //ed.SetImpliedSelection(new ObjectId[]{}); // Extract the DXF name to select from the JSON arguments var jo = JObject.Parse(jsonArgs); var dxfName = jo.Property("class").Value.ToString(); var expanded = (bool)jo.Property("expanded").Value; // We'll select all the entities of this class var tvs = new TypedValue[] { new TypedValue((int)DxfCode.Start, dxfName) }; // If the wedge is already expanded, we want to clear the // pickfirst set (so the default value is null) ObjectId[] ids = null; if (!expanded) { // Perform the selection var sf = new SelectionFilter(tvs); var psr = ed.SelectAll(sf); if (psr.Status != PromptStatus.OK) return res; // Get the results in our array ids = psr.Value.GetObjectIds(); } // Set or clear the pickfirst selection ed.SetImpliedSelection(ids); // Set the focus on the main window for the update to display // (this works fine when floating, less well when docked) Application.MainWindow.Focus(); // Return success return "{\"retCode\":0}"; } [JavaScriptCallback("GetObjectCountData")] public string GetObjectData(string jsonArgs) { var doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) return "{\"retCode\":1}"; // Initialize the JSON string to return the count information var sb = new StringBuilder("{\"retCode\":0, \"result\":"); sb.Append("{\"sortOrder\":\"value-desc\",\"content\":["); using ( var tr = doc.TransactionManager.StartOpenCloseTransaction() ) { bool first = true; var ms = (BlockTableRecord)tr.GetObject( SymbolUtilityServices.GetBlockModelSpaceId(doc.Database), OpenMode.ForRead ); // Use LINQ to count the objects in the modelspace, // grouping the results by type (all done via ObjectIds, // no need to open the objects themselves) var q = from ObjectId o in ms group o by o.ObjectClass.DxfName into counts select new { Count = counts.Count(), Group = counts.Key }; // Serialize the results out to JSON foreach (var i in q) { if (!first) sb.Append(","); first = false; sb.AppendFormat( "{{\"label\":\"{0}\",\"value\":{1}}}", i.Group, i.Count ); } tr.Commit(); } sb.Append("]}}"); return sb.ToString(); } private void OnDocumentActivated( object s, DocumentCollectionEventArgs e ) { if (_chps != null && e.Document != _curDoc) { // We're going to monitor when objects get added and // erased. We'll use CommandEnded to refresh the // palette at most once per command (might also use // DocumentManager.DocumentLockModeWillChange) // The document is dead... RemoveHandlers(_curDoc); // ... long live the document! _curDoc = e.Document; AddHandlers(_curDoc); if (_curDoc != null) { // Refresh our palette by setting the flag and running // a command (could be any command, we've chosen REGEN) _refresh = true; _curDoc.SendStringToExecute( "_.REGEN ", false, false, false ); } else { acjsInvokeAsync("refpie", "{}"); } } } private void AddHandlers(Document doc) { if (doc != null) { if (doc.Database != null) { doc.Database.ObjectAppended += OnObjectAppended; doc.Database.ObjectErased += OnObjectErased; } doc.CommandEnded += OnCommandEnded; } } private void RemoveHandlers(Document doc) { if (doc != null) { if (doc.Database != null) { doc.Database.ObjectAppended -= OnObjectAppended; doc.Database.ObjectErased -= OnObjectErased; } doc.CommandEnded -= OnCommandEnded; } } private void OnObjectAppended(object s, ObjectEventArgs e) { _refresh = true; } private void OnObjectErased(object s, ObjectErasedEventArgs e) { _refresh = true; } private void OnCommandEnded(object s, CommandEventArgs e) { // Invoke our JavaScript functions to refresh the palette if (_refresh && _chps != null) { acjsInvokeAsync("refpie", "{}"); _refresh = false; } } private void OnPaletteSetDestroy(object s, EventArgs e) { // When our palette is closed, detach the various // event handlers if (_curDoc != null) { RemoveHandlers(_curDoc); _curDoc = null; } } private static Uri GetHtmlPathChart() { return new Uri(Utils.GetHtmlPath() + "chart.html"); } } }检查我这段代码
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值