Disabling Copy/Paste in a Textbox control in C#

 

Hi,

I have a user control that pops up much like intelisense in visual studio to
display a range of navigable options when a key combo is pressed within a
textbox. I have called the user control within the parent form and
programmatically called it using the following code within the parent form.

MyUserControl control1 = new MyUserControl;
control1.BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(control1);
control1.Focus();
control1.BringToFront();
control1.Show();

How do I go about making my new popup control resizeable?

the only options I have under BorderStyle is FixedSingle and Fixed3D.

thanks
skoya


From:  Stoitcho Goutsev (100) [C# MVP] - view profile
Date:  Fri, Nov 25 2005 4:53 am
Email:  "Stoitcho Goutsev /(100/) [C# MVP]" <1...@100.com>
Groups:  microsoft.public.dotnet.framework.windowsforms
Not yet rated
Rating:
 
show options

Hi,

What is the base class for your control? It seems not to be UserControl
because it doesn't have BorderStyle property.

However this is not important because control's doesn't support sizable
borders anyways.
The easies way would be to use form instead of control. Modify the form
border (remove the caption and stuff. Set the FormBorderStyle to *Sizable*
then show the form (control) using the following code:

 Form2 f2 = new Form2();
   f2.TopLevel = false;
   f2.Size = new Size(200,200);
   this.Controls.Add(f2);
   f2.Show();

The key here is setting f2.TopLevel to *false*. When do that the form
becomes normal control rather that top-level window.

The problem here is with the 3D look of the form. This cannot be controlled
and the control's visual appearance doesn't make sense.

Next solution that came up in my mind is to override CreateParams property
and adding resizable border to some normal control. Unfortunately resizable
border comes with 3D look and there is nothing we can do about it.

So the solution is to use thin (non resizable) border and process the
WM_NCHITTEST.

The following is sample control that inherits from panel and can be resized.
I've implemented only resizing by grabbing the bottom border it needs to be
implemented in the same way for the other possible grab regions (corners,
left and right border as well as top border if make sense)

class SizablePanel: Panel
 {

  private const int WM_NCHITTEST = 0x0084;
  private const int HTBOTTOM = 15;

  public SizablePanel()
  {
   this.BorderStyle = BorderStyle.FixedSingle;
  }

  protected override void WndProc(ref Message m)
  {
   base.WndProc (ref m);

   if(m.Msg == WM_NCHITTEST)
   {
    Point pos = new Point((int)m.LParam);
    pos = this.PointToClient(pos);
    if(pos.Y > this.Height - 10)
     m.Result = new IntPtr(HTBOTTOM);

   }

  }

 }

What is the base class for your control? It seems not to be UserControl
because it doesn't have BorderStyle property.

However this is not important because control's doesn't support sizable
borders anyways.
The easies way would be to use form instead of control. Modify the form
border (remove the caption and stuff. Set the FormBorderStyle to *Sizable*
then show the form (control) using the following code:

 Form2 f2 = new Form2();
   f2.TopLevel = false;
   f2.Size = new Size(200,200);
   this.Controls.Add(f2);
   f2.Show();

The key here is setting f2.TopLevel to *false*. When do that the form
becomes normal control rather that top-level window.

The problem here is with the 3D look of the form. This cannot be controlled
and the control's visual appearance doesn't make sense.

Next solution that came up in my mind is to override CreateParams property
and adding resizable border to some normal control. Unfortunately resizable
border comes with 3D look and there is nothing we can do about it.

So the solution is to use thin (non resizable) border and process the
WM_NCHITTEST.

The following is sample control that inherits from panel and can be resized.
I've implemented only resizing by grabbing the bottom border it needs to be
implemented in the same way for the other possible grab regions (corners,
left and right border as well as top border if make sense)

class SizablePanel: Panel
 {

  private const int WM_NCHITTEST = 0x0084;
  private const int HTBOTTOM = 15;

  public SizablePanel()
  {
   this.BorderStyle = BorderStyle.FixedSingle;
  }

  protected override void WndProc(ref Message m)
  {
   base.WndProc (ref m);

   if(m.Msg == WM_NCHITTEST)
   {
    Point pos = new Point((int)m.LParam);
    pos = this.PointToClient(pos);
    if(pos.Y > this.Height - 10)
     m.Result = new IntPtr(HTBOTTOM);

   }

  }

 }

HTH

Stoitcho Goutsev (100) [C# MVP]

"sdfsdfds" <sdfsd ...@sddfs.com> wrote in message

news:%23hYxTWP8FHA.1000@tk2msftngp13.phx.gbl...

 

- Show quoted text -

From:  sdfsdfds - view profile
Date:  Fri, Nov 25 2005 7:44 pm
Email:  "sdfsdfds" <sdfsd...@sddfs.com>
Groups:  microsoft.public.dotnet.framework.windowsforms
Not yet rated
Rating:
 
show options

Thats superb it turns out that I only need HTRIGHTBOTTOM for now...

Also the code works with UserControl class also not just Panel.

thanks a lot for your help.

private const int WM_NCHITTEST = 0x0084;

private const int HTBOTTOM = 15;

private const int HTBOTTOMRIGHT = 17;

private const int HTRIGHT = 11;

protected override void WndProc(ref Message m)

{

base.WndProc(ref m);

if (m.Msg == WM_NCHITTEST)

{

Point pos = new Point((int)m.LParam);

pos = this.PointToClient(pos);

//if (pos.Y > this.Height - 10)

// m.Result = new IntPtr(HTBOTTOM);

if (pos.X > this.Width - 10 && pos.Y > this.Height - 10)

{

m.Result = new IntPtr(HTBOTTOMRIGHT);

return;

 

}

// if (pos.X > this.Width - 10)

// m.Result = new IntPtr(HTRIGHT);

 

}
}

"Stoitcho Goutsev (100) [ C# MVP]" <1 ...@100.com> wrote in message
news:epC1sjT8FHA.1248@TK2MSFTNGP14.phx.gbl...

 

- Show quoted text -

From:  Stoitcho Goutsev (100) [C# MVP] - view profile
Date:  Fri, Nov 25 2005 10:28 pm
Email:  "Stoitcho Goutsev /(100/) [C# MVP]" <1...@100.com>
Groups:  microsoft.public.dotnet.framework.windowsforms
Not yet rated
Rating:
 
show options

It is going to work with any control because it exploits windows message
that is common for all windows. I just used a panel because it has this
BorderStyle property. I don't see the UserControl to expose such a property.
Nevertheless, border can be added (theoretically) to any control via
overriding CreateParams property.

--

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值