private int scUpDown_SubClassedWndProc(ref Message m) { switch (m.Msg) { case CustomWin32.WM_PAINT: { //------------------------ // redraw IntPtr hDC = CustomWin32.GetWindowDC(scUpDown.Handle); Graphics g = Graphics.FromHdc(hDC); DrawIcons(g); g.Dispose(); CustomWin32.ReleaseDC(scUpDown.Handle, hDC); //------------------------ // return 0 (processed) m.Result = IntPtr.Zero; //------------------------ // validate current rect Rectangle rect = new Rectangle(); CustomWin32.GetClientRect(scUpDown.Handle, ref rect); CustomWin32.ValidateRect(scUpDown.Handle, ref rect); //------------------------ } return(1); } return(0); }
private void UpdateUpDown() { if (bUpDown) { if (CustomWin32.IsWindowVisible(scUpDown.Handle)) { Rectangle rect = new Rectangle(); CustomWin32.GetClientRect(scUpDown.Handle, ref rect); CustomWin32.InvalidateRect(scUpDown.Handle, ref rect, true); } } }
private void FindUpDown() { bool bFound = false; // find the UpDown control IntPtr pWnd = CustomWin32.GetWindow(this.Handle, CustomWin32.GW_CHILD); while (pWnd != IntPtr.Zero) { //---------------------------- // Get the window class name char[] className = new char[33]; int length = CustomWin32.GetClassName(pWnd, className, 32); string s = new string(className, 0, length); //---------------------------- if (s == "msctls_updown32") { bFound = true; if (!bUpDown) { //---------------------------- // Subclass it this.scUpDown = new SubClass(pWnd, true); this.scUpDown.SubClassedWndProc += new SubClass.SubClassWndProcEventHandler(scUpDown_SubClassedWndProc); //---------------------------- bUpDown = true; } break; } pWnd = CustomWin32.GetWindow(pWnd, CustomWin32.GW_HWNDNEXT); } if ((!bFound) && (bUpDown)) { bUpDown = false; } }
internal void DrawControl(Graphics g) { if (!Visible) { return; } Rectangle TabControlArea = this.ClientRectangle; Rectangle TabArea = this.DisplayRectangle; // fill client area RenderControlBackground(g, TabControlArea); // draw panel border int nDelta = SystemInformation.Border3DSize.Width; TabArea.Inflate(nDelta, nDelta); //RenderTabPanelBorder(g, TabArea); // clip region for drawing tabs Region rsaved = g.Clip; int nWidth = TabArea.Width + nMargin; if (bUpDown) { // exclude updown control for painting if (CustomWin32.IsWindowVisible(scUpDown.Handle)) { Rectangle rupdown = new Rectangle(); CustomWin32.GetWindowRect(scUpDown.Handle, ref rupdown); Rectangle rupdown2 = this.RectangleToClient(rupdown); nWidth = rupdown2.X; } } // draw tabs for (int i = 0; i < this.TabCount; i++) { DrawTab(g, this.TabPages[i], i); } g.Clip = rsaved; //---------------------------- //---------------------------- // draw background to cover flat border areas //覆盖tabpage和控件边框的空隙 //if (this.SelectedTab != null) //{ // TabPage tabPage = this.SelectedTab; // Color color = tabPage.BackColor; // Pen border = new Pen(color); // TabArea.Offset(1, 1); // TabArea.Width -= 2; // TabArea.Height -= 2; // g.DrawRectangle(border, TabArea); // TabArea.Width -= 1; // TabArea.Height -= 1; // g.DrawRectangle(border, TabArea); // border.Dispose(); //} //---------------------------- //如果边框是两条线,则这里就只需要覆盖底线和右边的竖线,根据实际观察得知 //if (this.SelectedTab != null) //{ // TabPage tabPage = this.SelectedTab; // Color color = tabPage.BackColor; // Pen border = new Pen(color); // g.DrawLine(border, new Point(TabArea.X + 2, TabArea.Bottom - 2) // , new Point(TabArea.Right - 2, TabArea.Bottom - 2)); // g.DrawLine(border, new Point(TabArea.Right - 2, TabArea.Bottom - 2) // , new Point(TabArea.Right - 2, TabArea.Y + 2)); // border.Dispose(); //} }