<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      如何設置Winform控件的ClientRectangle

             最近學習制作WinForm控件,自己動手寫控件的時候才發現System.Windows.Forms.Control 竟然沒有提供默認的border繪制。記得以前用API做控件的時候,只需要設置空間窗口的WS_BORDER 風格就可以。遍尋無方,只有自己繪制了,這里有出現一個,如果border在客戶區,那么在OnPaint方法里不得不每次都要考慮Border所占用的區域,而且,如果從這個類派生的話,將無法獲得準確的客戶區。
            現在要解決的問題就是如何重新設置客戶區的矩形區域的尺寸,查看了一下Control類的ClientRectangle屬性:
      public Rectangle ClientRectangle { get; }是個只讀屬性,看來是不能通過這個屬性達到目的了。再查找Control類的文檔,也沒有這方面的說明,沒有辦法,只能用API搞定了。可以通過計算非客戶區尺寸來設置客戶區尺寸,Border在非客戶繪制。下面就是主要的代碼,就是通過重載WndProc方法,捕捉WM_NCCALCSIZE消息,實現自己的邏輯。
           
      protected override void WndProc(ref Message m)
      {
      switch (m.Msg)
      {
      case (int)WinAPI_WM.WM_NCCALCSIZE:
      if (m.WParam.ToInt32() == 0)
      {
      WinAPI_RECT rc 
      = (WinAPI_RECT)m.GetLParam(typeof(WinAPI_RECT));
      rc.Left 
      += 1;
      rc.Top 
      += 1
      rc.Right 
      -= 1
      rc.Bottom 
      -= 1;
      Marshal.StructureToPtr(rc, m.LParam, 
      true);
      m.Result 
      = IntPtr.Zero;
      }

      else
      {
      WinAPI_NCCALCSIZE_PARAMS csp;
      csp 
      = (WinAPI_NCCALCSIZE_PARAMS)m.GetLParam(typeof(WinAPI_NCCALCSIZE_PARAMS));
      csp.rgrc0.Top 
      += 1
      csp.rgrc0.Bottom 
      -= 1;
      csp.rgrc0.Left 
      += 1
      csp.rgrc0.Right 
      -= 1;

      Marshal.StructureToPtr(csp, m.LParam, 
      true);
      //Return zero to preserve client rectangle
      m.Result = IntPtr.Zero;
      }

      break;
      case (int)WinAPI_WM.WM_NCPAINT:
      {
      m.WParam 
      = NCPaint(m.WParam);
      break;
      }

      }


      base.WndProc(ref m);
      }


      public IntPtr NCPaint(IntPtr region)
      {
      IntPtr hDC 
      = GetWindowDC(this.Handle);
      if (hDC != IntPtr.Zero)
      {
      Graphics grTemp 
      = Graphics.FromHdc(hDC);

      int ScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
      int ScrollBarHeight = SystemInformation.HorizontalScrollBarHeight;

      WINDOWINFO wi 
      = new WINDOWINFO();
      wi.cbSize 
      = (uint)Marshal.SizeOf(wi);

      //得到當前控件的窗口信息
      GetWindowInfo(Handle, ref wi);

      wi.rcClient.Right
      --;
      wi.rcClient.Bottom
      --;


      //獲得當前控件的區域
      Region UpdateRegion = new Region(new Rectangle(wi.rcWindow.Top,wi.rcWindow.Left,wi.rcWindow.Right-wi.rcWindow.Left,wi.rcWindow.Bottom-wi.rcWindow.Top));

      //獲得客戶區以外的區域
      UpdateRegion.Exclude(new Rectangle(wi.rcClient.Top, wi.rcClient.Left, wi.rcClient.Right - wi.rcClient.Left, wi.rcClient.Bottom - wi.rcClient.Top));

      if (IsHScrollVisible && IsVScrollVisible)
      {
      UpdateRegion.Exclude(Rectangle.FromLTRB
      (wi.rcClient.Right 
      + 1, wi.rcClient.Bottom + 1,
      wi.rcWindow.Right, wi.rcWindow.Bottom));
      }


      //得到當前區域的句柄
      IntPtr hRgn = UpdateRegion.GetHrgn(grTemp);

      //For Painting we need to zero offset the Rectangles.
      Rectangle WindowRect = new Rectangle(wi.rcWindow.Top, wi.rcWindow.Left, wi.rcWindow.Right - wi.rcWindow.Left, wi.rcWindow.Bottom - wi.rcWindow.Top);

      Point offset 
      = Point.Empty - (Size)WindowRect.Location;

      WindowRect.Offset(offset);

      Rectangle ClientRect 
      = WindowRect;

      ClientRect.Inflate(
      -1-1);

      //Fill the BorderArea
      Region PaintRegion = new Region(WindowRect);
      PaintRegion.Exclude(ClientRect);
      grTemp.FillRegion(SystemBrushes.Control, PaintRegion);

      //Fill the Area between the scrollbars
      if (IsHScrollVisible && IsVScrollVisible)
      {
      Rectangle ScrollRect 
      = new Rectangle(ClientRect.Right - ScrollBarWidth,
      ClientRect.Bottom 
      - ScrollBarHeight, ScrollBarWidth + 2, ScrollBarHeight + 2);
      ScrollRect.Offset(
      -1-1);
      grTemp.FillRectangle(SystemBrushes.Control, ScrollRect);
      }


      //Adjust ClientRect for Drawing Border.
      ClientRect.Inflate(22);
      ClientRect.Width
      --;
      ClientRect.Height
      --;

      //Draw Outer Raised Border
      ControlPaint.DrawBorder3D(grTemp, WindowRect, Border3DStyle.Raised,
      Border3DSide.Bottom 
      | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);

      //Draw Inner Sunken Border
      ControlPaint.DrawBorder3D(grTemp, ClientRect, Border3DStyle.Sunken,
      Border3DSide.Bottom 
      | Border3DSide.Left | Border3DSide.Right | Border3DSide.Top);

      ReleaseDC(Handle, hDC);

      grTemp.Dispose();

      return hRgn;

      }


      RefreshScrollBar();
      return region;
      }


      posted @ 2006-11-29 22:44  綸巾客  閱讀(7931)  評論(14)    收藏  舉報
      主站蜘蛛池模板: 色九月亚洲综合网| 思思久99久女女精品| 国产一级区二级区三级区| 久久精品国产亚洲AⅤ无码| 人妻va精品va欧美va| 日韩高清在线亚洲专区国产| 久热伊人精品国产中文| 白白发布视频一区二区视频| 熟妇的奶头又大又长奶水视频| 日本极品少妇videossexhd| 亚洲人妻一区二区精品| 免费中文熟妇在线影片| 国产高清无遮挡内容丰富| 国产一区日韩二区三区| 午夜无码免费福利视频网址| 玩弄美艳馊子高潮无码| 9色国产深夜内射| 成人做受120秒试看试看视频| av无码精品一区二区乱子| 国产男人的天堂在线视频| 噜噜噜噜私人影院| 久久国内精品自在自线91| 免费无码肉片在线观看| 无码人妻精品一区二区三区下载| 一区二区三区四区五区自拍| 亚洲中文字幕第一页在线| 97久久精品午夜一区二区| 久久精品欧美日韩精品| 视频一区视频二区亚洲视频| 国产免费一区二区不卡| 在线高清免费不卡全码| 久久99久久99精品免视看动漫| 777久久精品一区二区三区无码 | 国产剧情91精品蜜臀一区| 国产人妻精品午夜福利免费| 成全高清在线播放电视剧| 亚洲欧美高清在线精品一区二区| 337p西西人体大胆瓣开下部| 亚洲国产精品男人的天堂| 少妇又爽又刺激视频| 久久国产精品波多野结衣av|