Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

custom border for textbox on a tranaparent form problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sk - 15 Sep 2004 08:06 GMT
Hello,
I have a text box with custom border,

I am attaching the code for my control below.
Basically my derived control draws custom border in WM_NCPAINT message.

This control works fine when placed on a .net form. But when i change the
opacity of the form to anything other than 100%. I see black border on the
right and bottom side of the control.
Upon debugging I found that the GetWindowDC() call in wm_ncpaint do not
return the full control area, the portion which appears black is already
clipped.

interestingly native textbox control works fine.

Any solutions to the problem?
How can one change the size of the drawable area of the control.

Thanking you
SK

The code looks like something like this
namespace MyNameSpace

{

class MyTextBox1 : 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);

//Debug.WriteLine("WM_NCPAINT: hWnd = "+Handle.ToString()+"WParam =
"+m.WParam.ToString());

IntPtr hDC = GetWindowDC(Handle);

if (hDC.ToInt32() == 0)

{

Debug.WriteLine("Couldn't get hDC:"+Marshal.GetLastWin32Error().ToString());

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);

Debug.WriteLine("WM_NCPAINT: "+r.Top+","+r.Left+" -"+r.Bottom+","+r.Right);

g.DrawRectangle(p,r);

ReleaseDC(Handle,hDC);

}

protected override void WndProc(ref Message m)

{

switch(m.Msg)

{

case WM_NCPAINT:

{

base.WndProc(ref m);

Debug.WriteLine("WM_NCPAINT: hWnd = "+m.HWnd.ToString()+"WParam =
"+m.WParam.ToString());

//Region rgn = Region.FromHrgn(m.WParam);

IntPtr hDC = GetWindowDC(m.HWnd);

if (hDC.ToInt32() == 0)

{

Debug.WriteLine("Couldn't get hDC:"+Marshal.GetLastWin32Error().ToString());

break;

}

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);

Debug.WriteLine("WM_NCPAINT: "+r.Top+","+r.Left+" -"+r.Bottom+","+r.Right);

g.DrawRectangle(p,r);

m.Result = IntPtr.Zero;

ReleaseDC(m.HWnd,hDC);

return;

}

}

base.WndProc(ref m);

}

}

}
Sk - 15 Sep 2004 10:02 GMT
In contiuation with the message I find that
g.VisibleClipBounds rectangle returned when the transparency is set is
different than when the form is opaque. the reactangle returned in this case
is equal to the size of the client area.

But i found this little wierd.

Is there any way to increase the visibleClipBounds. graphics methods like
resetClip is not helping.

> Hello,
> I have a text box with custom border,
[quoted text clipped - 86 lines]
>
> Debug.WriteLine("WM_NCPAINT:
"+r.Top+","+r.Left+" -"+r.Bottom+","+r.Right);

> g.DrawRectangle(p,r);
>
[quoted text clipped - 44 lines]
>
> Debug.WriteLine("WM_NCPAINT:
"+r.Top+","+r.Left+" -"+r.Bottom+","+r.Right);

> g.DrawRectangle(p,r);
>
[quoted text clipped - 15 lines]
>
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.