UserControl withOut parent fom

M

Marcel

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
 
D

Dmytro Lapshyn [MVP]

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.
 
M

Marcel

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
 
D

Dmytro Lapshyn [MVP]

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).
 
M

Marcel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top