当前位置:编程学习 > C#/ASP.NET >>

请大家帮忙看看,谢谢

把这段C#代码变成VB.NET代码,应该怎么搞,谢谢
        [DllImport("user32.dll")]
        private static extern IntPtr GetWindowDC(IntPtr hWnd);
        [DllImport("user32.dll")]
        private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);

        private const int WM_NCPAINT = 0x0085;
        private const int WM_NCACTIVATE = 0x0086;
        private const int WM_NCLBUTTONDOWN = 0x00A1;
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            Rectangle vRectangle = new Rectangle((Width - 75) / 2, 3, 75, 25);
            switch (m.Msg)
            {
                case WM_NCPAINT:
                case WM_NCACTIVATE:
                    IntPtr vHandle = GetWindowDC(m.HWnd);
                    Graphics vGraphics = Graphics.FromHdc(vHandle);
                    vGraphics.FillRectangle(new LinearGradientBrush(vRectangle,
                        Color.Pink, Color.Purple, LinearGradientMode.BackwardDiagonal),
                        vRectangle);

                    StringFormat vStringFormat = new StringFormat();
                    vStringFormat.Alignment = StringAlignment.Center;
                    vStringFormat.LineAlignment = StringAlignment.Center;
                    vGraphics.DrawString("About", Font, Brushes.BlanchedAlmond,
                        vRectangle, vStringFormat);

                    vGraphics.Dispose();
                    ReleaseDC(m.HWnd, vHandle);
                    break;
                case WM_NCLBUTTONDOWN:
                    Point vPoint = new Point((int)m.LParam);
                    vPoint.Offset(-Left, -Top);
                    if (vRectangle.Contains(vPoint))
                        MessageBox.Show(vPoint.ToString());
                    break;
            }
        }
--------------------编程问答-------------------- 除了把每行的分号去掉

override改成Overrides
类型的定义改成Dim ... As ...

switch ... case
改成
select ... case

等等

还有API的定义修改下,其它没什么要改的了。

Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Integer) As Integer 
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer --------------------编程问答-------------------- 老大,IntPtr vHandle = GetWindowDC(m.HWnd);这个我改成Dim vhandle As IntPtr = GetWindowDC(m.HWnd)为什么是错误的

ReleaseDC(m.HWnd, vHandle)也是错误的 --------------------编程问答-------------------- 成了。谢谢老大,你上面已经给我答案了 --------------------编程问答-------------------- 用IntPtr需要调用ToInt32() --------------------编程问答-------------------- 除
补充:.NET技术 ,  VB.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,