469,619 Members | 1,963 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,619 developers. It's quick & easy.

UserControl withOut parent fom

Hello, Iīm trying to create a custom user control, but I didnīt wanted
to put it inside a form, I wanted it to an object by itīs own..

I first created my class derived from Form, set the style to none, but I
wanted to add the ability to drag and drop between my custom controls,
and looks like I canīt drag and drop one form over another

I looked that form derived from Control, but msdn says that I should use
UserControl to create classes derived from

I googleed, googled and googled but I couldnīt find nothing useful,
every place says that UserControls have a parent form, should I use
Control instead?

thanks in advance
marcel
Nov 17 '05 #1
4 2588
Hello Marcel,

I am not sure what did you want to do in the first place. Yes, a user
control must have a parent form, but it does not mean it has to be *derived*
from System.Windows.Forms.Form. All controls are child windows and the
form's window serves as their parent. If you want something like a tool
window, create a form instead and customize its appearance.

Please elaborate on what your task is, otherwise it is really difficult to
come up with a useful piece advice.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Marcel" <ma****@dogmagraphics.com.br> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
Hello, Iīm trying to create a custom user control, but I didnīt wanted to
put it inside a form, I wanted it to an object by itīs own..

I first created my class derived from Form, set the style to none, but I
wanted to add the ability to drag and drop between my custom controls, and
looks like I canīt drag and drop one form over another

I looked that form derived from Control, but msdn says that I should use
UserControl to create classes derived from

I googleed, googled and googled but I couldnīt find nothing useful, every
place says that UserControls have a parent form, should I use Control
instead?

thanks in advance
marcel


Nov 17 '05 #2
ok, sorry
what I imagine my tool would be is something like an icon, but bigger,
on the desktop, I would have floating objects and drag them around
why icons? well, transparency is one, with that I can also achieve non
rectangle shape, and I also need drag and drop between them, some would
be able to be dragged and some other to be dragged into

I was able to create a custom form, with all that, except that I need a
key color for transparency (not a big problem), and that Iīm not able to
do drag and move my form
Iīm moving my form detecting mouseDown and mouseMove, but looks like
that after a call to DoDragDrop() it doesnīt generate mouseMove anymore

thanks for the attention
marcel

Dmytro Lapshyn [MVP] wrote:
Hello Marcel,

I am not sure what did you want to do in the first place. Yes, a user
control must have a parent form, but it does not mean it has to be
*derived* from System.Windows.Forms.Form. All controls are child windows
and the form's window serves as their parent. If you want something like
a tool window, create a form instead and customize its appearance.

Please elaborate on what your task is, otherwise it is really difficult
to come up with a useful piece advice.

Nov 17 '05 #3
> I was able to create a custom form, with all that, except that I need a
key color for transparency (not a big problem), and that Iīm not able to
do drag and move my form
You can use regions instead of color-key based transparency (I did that for
a baloon tooltip-like form).
As for moving the form, it is somewhat tricky. You must handle the
WM_NCHITTEST Windows message (by overriding the WndProc method) and when the
mouse pointer is over an area that should work as the window caption, you
should tell the system that the result of the hit test is the caption (by
returning an appropriate result code - please refer to MSDN for more
details).

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"Marcel" <ma****@dogmagraphics.com.br> wrote in message
news:us*************@TK2MSFTNGP15.phx.gbl... ok, sorry
what I imagine my tool would be is something like an icon, but bigger, on
the desktop, I would have floating objects and drag them around
why icons? well, transparency is one, with that I can also achieve non
rectangle shape, and I also need drag and drop between them, some would be
able to be dragged and some other to be dragged into

I was able to create a custom form, with all that, except that I need a
key color for transparency (not a big problem), and that Iīm not able to
do drag and move my form
Iīm moving my form detecting mouseDown and mouseMove, but looks like that
after a call to DoDragDrop() it doesnīt generate mouseMove anymore

thanks for the attention
marcel

Dmytro Lapshyn [MVP] wrote:
Hello Marcel,

I am not sure what did you want to do in the first place. Yes, a user
control must have a parent form, but it does not mean it has to be
*derived* from System.Windows.Forms.Form. All controls are child windows
and the form's window serves as their parent. If you want something like
a tool window, create a form instead and customize its appearance.

Please elaborate on what your task is, otherwise it is really difficult
to come up with a useful piece advice.


Nov 17 '05 #4
mm, regions seems a bit too complicated, not sure if worth the trouble

I found this code on the net:

private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
protected override void WndProc(ref Message m)
{
if(m.Msg == WM_NCHITTEST)
m.Result = new IntPtr(HTCAPTION);
else
base.WndProc(ref m);
}

now it moves my window, but the drag and drop stops working.. :(

thanks again for the attention :)
marcel

Dmytro Lapshyn [MVP] wrote:
I was able to create a custom form, with all that, except that I need
a key color for transparency (not a big problem), and that Iīm not
able to do drag and move my form

You can use regions instead of color-key based transparency (I did that
for a baloon tooltip-like form).
As for moving the form, it is somewhat tricky. You must handle the
WM_NCHITTEST Windows message (by overriding the WndProc method) and when
the mouse pointer is over an area that should work as the window
caption, you should tell the system that the result of the hit test is
the caption (by returning an appropriate result code - please refer to
MSDN for more details).

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John | last post: by
reply views Thread by Gary Shell | last post: by
9 posts views Thread by Marcelo Cabrera | last post: by
reply views Thread by Arpan | last post: by
1 post views Thread by Tomaz Koritnik | last post: by
6 posts views Thread by MeowCow | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.