How can I catch the event when I change the container inside a palette? Is it possible? If yes how can I do that? Any help regarding this issue will be appreciated.
Regards
Zakir
Could you be more specific on what you want to know?
What container inside a Palette? A palette is a Windows Form UserControl (assume you use Win Form UserControl, not WPF). So, do you mean a GroupBox, a Panel... as a container? How do you change the container?
Whatever you do, you can bubble up the controls' (text box, panel...whatever) events up to the UserControl and to the PalletteSet level and handles the events at PalletteSet level. Of course, you'd derive your custom PaletteSet from PaletteSet (if you use Acad2009 or later).
Norman Yuan
Thanks for your reply. Sorry that my question was not so clear. I have a paletteset where there are 2 user control forms like below screen shot. My question is if I change from 'ACAD Mode' to 'EPD Mode' or vice versa, Can I catch that event?
PaletteSet has a event PaletteActivated that you can use:
void MyPaletteSet_PaletteActivated(object sender, PaletteActivatedEventArgs e) { MessageBox.Show("Palette \"" + e.Activated.Name + "\" is activated!"); }
This event was not available in earlier version of Acad .NET API (Acad2008 or earlier?), just in case you still work with older AutoCAD version.
There is also a method to programmatically activate particular palette, rather than activate a palette by user selecting palette tab:
PaletteSet.Activate(int index)
Norman Yuan
I have the same question but unable to implement the advice given.
I need to catch the event of a container becoming active within a paletteset.
Is it a handler that I need to add in the PaletteClass Initialize Sub?
The last three subroutines have 0 references.
Not entirely sure what the first two do but if they have something to do with the state of the palette on loading and closeing AutoCAD it would would be great if I could get them working also.
Public Sub Initialize() Implements IExtensionApplication.Initialize 'add anything that needs to be instantiated on startup End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate 'handle closing down a link to a database/etc. End Sub Private Shared Sub ps_Load(ByVal sender As Object, ByVal e As PalettePersistEventArgs) Dim a As Double = CType(e.ConfigurationSection.ReadProperty("DETAIL", 22.3), Double) End Sub Private Shared Sub ps_Save(ByVal sender As Object, ByVal e As PalettePersistEventArgs) e.ConfigurationSection.WriteProperty("DETAIL", 32.3) End Sub Private Shared Sub ps_PaletteActivated(ByVal sender As Object, ByVal e As PaletteActivatedEventArgs) MsgBox("Palette """ & e.Activated.Name & """ is activated!") End Sub
YOu did not show all the code where your PaletteSet is created. Thus I am not sure if you actually added PaletteActivated event handler. If you did, there is no reason the code in ps_PaletteActibated(...) event handler not being executed.
Also, you SHOULD ALWAYS derive your PaletteSet from PaletteSet class and separate IExtensionApplication from the PaletteSet class, as good practice.
Following is a simplified code sample in C#, which should be easily mind-converted to VB.NET.
The custom PaletteSet:
using System; using System.Windows.Forms; using Autodesk.AutoCAD.Windows; namespace PaletteSetEvents { public class MyPaletteSet : PaletteSet { public MyPaletteSet(): base("","", new Guid("AD334445-936A-47D7-8CF1-B4AFC5562D53")) { Style = PaletteSetStyles.ShowCloseButton | PaletteSetStyles.ShowTabForSingle | PaletteSetStyles.ShowAutoHideButton; Size = new System.Drawing.Size(500, 500); MinimumSize = new System.Drawing.Size(400, 400); PaletteA = new MyPalatteA(); Add("Palette A", PaletteA); PaletteB = new MyPaletteB(); Add("Palette B", PaletteB); Activate(0); PaletteActivated += MyPaletteSet_PaletteActivated; } private void MyPaletteSet_PaletteActivated(object sender, PaletteActivatedEventArgs e) { MessageBox.Show(e.Activated.Name); } public MyPalatteA PaletteA { private set; get; } public MyPaletteB PaletteB { private set; get; } } }
The CommandClass, which can also be made as IExtensionApplication, so that you can "New" the _ps variable in Initialize() on loading up:
using Autodesk.AutoCAD.Runtime; using CadApp = Autodesk.AutoCAD.ApplicationServices.Application; [assembly: CommandClass(typeof(PaletteSetEvents.MyCommands))] namespace PaletteSetEvents { public class MyCommands { private static MyPaletteSet _ps = null; [CommandMethod("ShowMyPs", CommandFlags.Session)] public static void RunMyCommand() { var doc = CadApp.DocumentManager.MdiActiveDocument; var ed = doc.Editor; if (_ps==null) { _ps = new MyPaletteSet(); } _ps.Visible = true; ed.WriteMessage("\n"); } } }
The attached video clip shows the PaletteActivated event handler works as expected:
Norman Yuan
Norman,Thankyou.
I really need to switch to C#.
I can see it's painful responding to questions.
The code converter I use converts
PaletteActivated += MyPaletteSet_PaletteActivated;
to
PaletteActivated += AddressOf MyPaletteSet_PaletteActivated
when it should be
AddHandler ps.PaletteActivated, AddressOf ps_PaletteActivated