Custom Control
-
I would like to make the following custom control. A button, that opens a drop down list. Essentially, a combo box, but I don't want the appearance of a combo box. I want a button. My initial problem is this. The drop down list may appear outside of its parent's bounds. Imagine a thin panel on the top of a form (like a toolbar) with this control attached to it. The control may have to draw the drop down list ON TOP OF the other controls immediately beneath the toolbar. I'm used to something like css (position: absoloute). I guess the MainMenu does this. Do I need to custom draw the drop down list control? Suggestions? -Luther
-
I would like to make the following custom control. A button, that opens a drop down list. Essentially, a combo box, but I don't want the appearance of a combo box. I want a button. My initial problem is this. The drop down list may appear outside of its parent's bounds. Imagine a thin panel on the top of a form (like a toolbar) with this control attached to it. The control may have to draw the drop down list ON TOP OF the other controls immediately beneath the toolbar. I'm used to something like css (position: absoloute). I guess the MainMenu does this. Do I need to custom draw the drop down list control? Suggestions? -Luther
Why not just use a
ContextMenu
, which is already supported? Just start tracking theContextMenu
in the coordinate space of the container of theButton
so that it aligns properly with theButton
in question. See theControl.PointToClient
method to convert coordinate spaces back and forth. Because theButton.Location
is already in the coordinate space of the container, you could also just add theHeight
andWidth
appropriately, saving you a lot of work. TheContextMenu
control will also extend past the bounds of the container. Otherwise, you can use a simple popup Window (with theWS_POPUP
style when you consider the native implementation of most controls in the .NET BCL). This is all theContextMenu
is when you get the heart of it.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Why not just use a
ContextMenu
, which is already supported? Just start tracking theContextMenu
in the coordinate space of the container of theButton
so that it aligns properly with theButton
in question. See theControl.PointToClient
method to convert coordinate spaces back and forth. Because theButton.Location
is already in the coordinate space of the container, you could also just add theHeight
andWidth
appropriately, saving you a lot of work. TheContextMenu
control will also extend past the bounds of the container. Otherwise, you can use a simple popup Window (with theWS_POPUP
style when you consider the native implementation of most controls in the .NET BCL). This is all theContextMenu
is when you get the heart of it.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Thanks Heath. Ddynamically placing the context menu might be just fine. If I wanted more control over the look of the popup window, I may try the WS_POPUP window approach as well. But, are you implying that I may have to use some native calls. I've written simple windows programs before - but I'm not exactly sure if thats what you mean. Would I be on the right track to do this natively by - creating a WS_POPUP window and writing a wndproc to catch mouseover, mouse out and click events? I've seen several posts that link to native DLLs and use SendMessage, etc, so I think I could work this out. But, I just want to be sure that I'm not missing something ... like, creating a panel in C# and somehow makeing it visible and invisible lower than the button I am using to trigger it. I've tried this - and at first attempt, the panel always shows up UNDERNEATH the controls lower in the client area. I'm betting I can get that final idea could work if I could somehow make change the panel's z order to higher than the controls lower in the client area. The hypothetical problem I can think of is that the controls lower in the client area don't attach to the same parent, and so, maybe this is recursive so I need to trace back until the parents attach to the same form or root panel, and makes sure the popup menu parent is at a higher z index ... If you have more time, your suggestions are greatly appreciated. For now, I'm off. Thanks, -Luther
-
Thanks Heath. Ddynamically placing the context menu might be just fine. If I wanted more control over the look of the popup window, I may try the WS_POPUP window approach as well. But, are you implying that I may have to use some native calls. I've written simple windows programs before - but I'm not exactly sure if thats what you mean. Would I be on the right track to do this natively by - creating a WS_POPUP window and writing a wndproc to catch mouseover, mouse out and click events? I've seen several posts that link to native DLLs and use SendMessage, etc, so I think I could work this out. But, I just want to be sure that I'm not missing something ... like, creating a panel in C# and somehow makeing it visible and invisible lower than the button I am using to trigger it. I've tried this - and at first attempt, the panel always shows up UNDERNEATH the controls lower in the client area. I'm betting I can get that final idea could work if I could somehow make change the panel's z order to higher than the controls lower in the client area. The hypothetical problem I can think of is that the controls lower in the client area don't attach to the same parent, and so, maybe this is recursive so I need to trace back until the parents attach to the same form or root panel, and makes sure the popup menu parent is at a higher z index ... If you have more time, your suggestions are greatly appreciated. For now, I'm off. Thanks, -Luther
A
Panel
won't work because it's a child window and nothing more. You have to use a popup window because it must be able to extend beyond its container's bounds. You could use aForm
, but there's just too much overhead, IMO. Yes, what I was talking about was good ol' Win32 programming. Fortunately, .NET can help even there. Remember that all the controls inSystem.Windows.Forms
are just wrappers of Common Controls. There's even classes likeNativeWindow
that can give you a wrapper to a native window. It wouldn't be too difficult to do. I'm sure there's examples out there, too, although good, specific keywords might be hard to determine.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
A
Panel
won't work because it's a child window and nothing more. You have to use a popup window because it must be able to extend beyond its container's bounds. You could use aForm
, but there's just too much overhead, IMO. Yes, what I was talking about was good ol' Win32 programming. Fortunately, .NET can help even there. Remember that all the controls inSystem.Windows.Forms
are just wrappers of Common Controls. There's even classes likeNativeWindow
that can give you a wrapper to a native window. It wouldn't be too difficult to do. I'm sure there's examples out there, too, although good, specific keywords might be hard to determine.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Perfect. You just saved me a night. Thanks for the direction. -Luther