Winston Posted November 25, 2005 Posted November 25, 2005 How do i offer interactive design time support for custom made controls? I'm doing it in VS2K5, basically when i mean design time i mean like, when u hover over the control, any mouse events etc u have wired to the control will work, because the control imade when hovered it paints differently. Also, other design time support like, if u add a panel/user control inside the user controls, during design time in the IDE, users can seperately select the embedded panels/user controls to change it's propertys accordingly. Quote
Talyrond Posted November 28, 2005 Posted November 28, 2005 Not sure if this is what you are looking for: http://blogs.msdn.com/mharsh/ Quote
Winston Posted November 28, 2005 Author Posted November 28, 2005 Hmmmm not quite, what i'm looking for is, like say you create a new UserControl project, and inside this, you wire up Mouse events, so that it will change some boolean value or whatever, which will be detected in the paint event, so when you hover over the control the control should paint differently, however, these hover events don't appear to be active when the control is in design time, i.e. when you drag the control onto a new solutioon hovering over the item doesn't do anything. Quote
karimgarza Posted November 28, 2005 Posted November 28, 2005 Hi, What you mean is that you want to be able to see the behavior of the usercontrol you see at runtime at designtime too, right? The only behaviors that I have been able to see at design time are those related to OnPaint, Resize, Location change, etc. I have never seen one for the Mouse Hover event at design time. Have you seen any other third party controls that do this? Thanks, kmg Quote You're either a one or a zero. Alive or dead.
Winston Posted November 28, 2005 Author Posted November 28, 2005 Yes, ihave, lots of third party controls like toolbar ones, also, the given TabControl in provides this. Quote
karimgarza Posted November 29, 2005 Posted November 29, 2005 Yes' date=' ihave, lots of third party controls like toolbar ones, also, the given TabControl in provides this.[/quote'] What you need to do is to create a procedure to capture the control messages with: protected override void WndProc(ref Message m) I have a small sample that might help you. This code listens for mouse movements in the control at design time and paint the border of textbox red. I just didn't add the code to change it back to its original when the mojuse leaves the control. But this will give you an idea on how to capture messages for controls. using System; using System.ComponentModel; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Drawing; namespace WindowsApplication6 { class UserControl2 : System.Windows.Forms.TextBox { [DllImport("user32.dll")] static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); const int WM_NCCALCSIZE = 0x0083; const int WM_NCHITTEST = 0x0084; const int WM_NCPAINT = 0x0085; struct RECT { public Int32 left; public Int32 top; public Int32 right; public Int32 bottom; }; protected override void OnPaint(PaintEventArgs e) { base.OnPaint (e); IntPtr hDC = GetWindowDC(Handle); if (hDC.ToInt32() == 0) { return; } Graphics g = Graphics.FromHdc(hDC); Brush b = Brushes.Red; Pen p = new Pen(b,5); Rectangle r = new Rectangle(0,0,this.Size.Width,this.Size.Height); g.DrawRectangle(p,r); ReleaseDC(Handle,hDC); } protected override void WndProc(ref Message m) { switch(m.Msg) { case WM_NCHITTEST: { base.WndProc(ref m); IntPtr hDC = GetWindowDC(m.HWnd); if (hDC.ToInt32() == 0) { break; } Brush b; b = Brushes.Red; Graphics g = Graphics.FromHdc(hDC); Pen p = new Pen(b,5); Rectangle r = new Rectangle(0,0,this.Size.Width,this.Size.Height); g.DrawRectangle(p,r); m.Result = IntPtr.Zero; ReleaseDC(m.HWnd,hDC); return; } } base.WndProc(ref m); } } } I hope it helps, kmg Quote You're either a one or a zero. Alive or dead.
Winston Posted November 29, 2005 Author Posted November 29, 2005 That's alot of effort! lol i was anticipating theres a special way to achieve it, via turning on some attributes and overriding other specific methods :S, i would of thouight the IDE offers a better design time support for control designers. Quote
Winston Posted November 30, 2005 Author Posted November 30, 2005 Hmmm ok that code above works, yay, but how do i detect for mouse leave and mouse click? Quote
Winston Posted November 30, 2005 Author Posted November 30, 2005 Been trying to use these const int WM_MOUSEHOVER = 0x02A1; const int WM_MOUSELEAVE = 0x02A3; const int WM_NCMOUSEMOVE = 0x00A0; const int WM_NCLBUTTONDOWN = 0x00A1; but none of them work! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.