mousehover on toolpalette... almost there but what am i doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear experts,
I've been working on some code (mostly copy & paste form multiple sites) and almost got it to work the way i want it, or better said got it in a way that I understand how to add things myself and got it working the way I want, only one thing that I can't get to work (hope it's some dumb mistake cause it took me lots of time to understand the pasted codes enough to get it work for as far as it does now). So in other words please don't tell me I have to set everything up on a total different way 🙏
anyhow this is the code i got:
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Windows; using System; using System.Collections.Generic; using System.Drawing; using System.Reflection; using WinForms = System.Windows.Forms; namespace ModelessDialogs { public class Commands { //zodat die niet crasht als je palletcommand doet terwijl pallet er al is? private static PaletteSet _ps = null; //palet laden [CommandMethod("PC")] public void PaletteCcommands() { if (_ps == null) { var doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) return; var ed = doc.Editor; var bs = new List<WinForms.Button>(); // buttons WinForms.Button b = new WinForms.Button(); b.Click += new EventHandler(b_Click); b.Text = "testttest"; b.SetBounds(50, 50, 50, 50); b.MouseHover += b_MouseHover; bs.Add(b); WinForms.Button c = new WinForms.Button(); c.Click += new EventHandler(b_Click); c.Text = "testttest"; c.SetBounds(50, 150, 50, 50); c.MouseHover += b_MouseHover; bs.Add(c); // Create a user control var uc = new WinForms.UserControl(); uc.Controls.AddRange(bs.ToArray()); //paletteset maken _ps = new PaletteSet("PC", new Guid("87374E16-C0DB-4F3F-9271-7A71ED921566")); _ps.Add("CMDPAL", uc); _ps.DockEnabled = (DockSides)(DockSides.Left | DockSides.Right); _ps.Size = new Size(400, 500); } _ps.Visible = true; } private void b_Click(object sender, EventArgs e) { DisplayMessage("dit was de test hij doet het"); } // Helper function to display a message and post a command prompt // (if there's an active document available) private static void DisplayMessage(string str, bool postPrompt = true) { var doc = Application.DocumentManager.MdiActiveDocument; if (doc == null) return; doc.Editor.WriteMessage("\n{0}\n", str); if (postPrompt) doc.Editor.PostCommandPrompt(); } // mousehovers private void b_MouseHover(object sender, EventArgs e) { System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip(); ToolTip1.SetToolTip(b, "text voor mousehover button"); } } }
the part that isn't working is the mousehover. in the last line, the b stays 'unknown'. how can i possibly solve this?
Next to that I would really appreciate some explanation about why i have to add the buttons to a button list before inserting it to the palette. Because, if I don't do this, the buttons don't show up the way they should (not taking the given size for example but filling up the full pallette, or starting new tabs).
And I would also like to know why the background color of the pallet doesn't automatically adjust to the colors of the autocadenvironment (for example the x-ref manager or properties manager does do that).
Thanks for any thought about any of these questions!