/// <summary> /// Get font text metrics points. /// </summary> /// <param name="g"></param> /// <param name="hFont"></param> /// <param name="fontName"></param> /// <param name="fontSize"></param> /// <param name="retPoint"></param> public static void GetTextMetrics(Graphics g, IntPtr hFont, string fontName, int fontSize, out PointF retPoint) { retPoint = new PointF(); int dpiX = (int)g.DpiX; // create the handle of DC IntPtr hdc = g.GetHdc(); IntPtr hFontOld = (IntPtr)NativeWindowCommon.SelectObject(hdc, hFont); NativeWindowCommon.TEXTMETRIC tm; NativeWindowCommon.GetTextMetrics(hdc, out tm); retPoint.X = tm.tmAveCharWidth; retPoint.Y = tm.tmHeight; if (SpecialTextSizeFactoring && dpiX == 120) //defect 117706 { //please, create an infrastructure for this if you need to add another font ... if (fontName == "Microsoft Sans Serif" && fontSize == 8 && retPoint.X == 6) { //For 100% resolution we got tm.tmAveCharWidth = 5 (average char width) //For 125% resolution we got tm.tmAveCharWidth = 6 and in prepareUOMConversion we use this data as factor for calculating all magic sizes for all controls and form. //So, the difference between 125% resolution and 100% resolution is 6/5 = 1.2, i.e 120% which is not enough //Here we manually set factor retPoint.X = 5 * 1.275F; } } NativeWindowCommon.SelectObject(hdc, hFontOld); // release the resources g.ReleaseHdc(hdc); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case NativeWindowCommon.WM_VSCROLL: case NativeWindowCommon.WM_HSCROLL: //keep all FitToMDI children at location 0,0 even after scroll foreach (var item in mdiClient.MdiChildren) { TagData tagData = item.Tag as TagData; if (tagData != null && (tagData.WindowType == WindowType.FitToMdi || tagData.IsMDIClientForm)) { item.Location = new Point(); } } mdiClient.Invalidate(); break; case NativeWindowCommon.WM_PAINT: using (Graphics gr = Graphics.FromHwnd(mdiClient.Handle)) { //Paint the mdiClient its children, background image, border etc. ControlRenderer.PaintMgPanel(mdiClient, gr); NativeWindowCommon.ValidateRect(mdiClient.Handle, IntPtr.Zero); } return; default: break; } base.WndProc(ref m); }
/// <summary>return the size of the string according to the font</summary> /// <param name="font"></param> /// <param name="str"></param> /// <param name="control"></param> /// <returns></returns> public static Size GetTextExt(Font font, String str, Control control) { Size size = new Size(); if (control != null && str != null) { #if PocketPC Form form = (Form)((control is Form)? control : control.TopLevelControl); using (Graphics g = form.CreateGraphics()) { // Mobile does not support GetTextExtentPoint32 or similar functions SizeF sizef = g.MeasureString(str, font); size.Width = (int)Math.Ceiling(sizef.Width); size.Height = (int)Math.Ceiling(sizef.Height); } #else using (Graphics g = control.CreateGraphics()) { IntPtr hdc = g.GetHdc(); IntPtr hFont = FontHandlesCache.GetInstance().Get(font).FontHandle; IntPtr hFontOld = (IntPtr)NativeWindowCommon.SelectObject(hdc, hFont); NativeWindowCommon.SIZE nativeSize = new NativeWindowCommon.SIZE(); NativeWindowCommon.GetTextExtentPoint32(hdc, str, str.Length, out nativeSize); size.Width = nativeSize.cx; //(int)Math.Ceiling(size.cx); size.Height = nativeSize.cy; //(int)Math.Ceiling(size.cy); NativeWindowCommon.SelectObject(hdc, hFontOld); g.ReleaseHdc(hdc); } #endif } return(size); }
/// <summary> /// paint header background /// </summary> /// <param name="pcust"></param> /// <param name="rect"></param> internal virtual void PaintBackGround(NativeCustomDraw.NMCUSTOMDRAW pcust, NativeWindowCommon.RECT rect) { if (TitleBrush != IntPtr.Zero) { NativeWindowCommon.FillRect(pcust.hdc, ref rect, TitleBrush); } }
/// <summary> /// lock window draw if thumb drag in process /// </summary> public void LockWindowDrawOnThumbDrag() { if (_isThumbDrag) { NativeWindowCommon.LockWindowUpdate(this.Handle); } }
protected Boolean CheckClickSequence(Message m) { Boolean rc = false; // In Win10, WM_IME_CHAR just after WM_IME_ENDCOMPOSITION should be ignored. // In Win7, it must be processed. // To distinguish, WM_REFLECT_WM_COMMAND/EN_CHANGE is checked. switch (m.Msg) { case NativeWindowCommon.WM_IME_STARTCOMPOSITION: shouldIgnoreNextImeChar = false; break; case NativeWindowCommon.WM_IME_ENDCOMPOSITION: shouldIgnoreNextImeChar = true; break; case NativeWindowCommon.WM_REFLECT_WM_COMMAND: if ((ENNOTIFY)NativeWindowCommon.HiWord((int)m.WParam) == ENNOTIFY.EN_CHANGE) { shouldIgnoreNextImeChar = false; } break; case NativeWindowCommon.WM_IME_CHAR: rc = shouldIgnoreNextImeChar; shouldIgnoreNextImeChar = false; break; } return(rc); }
/// <summary> return true if currently editing composition string in IME /// </summary> /// <param name="control"> /// </param> /// <returns> bool /// </returns> public bool IsEditingCompStr(Control control) { bool ret = false; if (control is TextBoxBase) { IntPtr hWnd = control.Handle; if (hWnd == IntPtr.Zero) { return(ret); } int hIMC = NativeWindowCommon.ImmGetContext(hWnd); if (hIMC == 0) { return(ret); } if (NativeWindowCommon.ImmGetCompositionString(hIMC, NativeWindowCommon.GCS_COMPSTR, null, 0) > 0) { ret = true; } NativeWindowCommon.ImmReleaseContext(hWnd, hIMC); } return(ret); }
/// <summary> /// Draw the text. /// </summary> /// <param name="hdc"></param> /// <param name="color"></param> /// <param name="rect"></param> /// <param name="topOffset"></param> /// <param name="orientation"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="contentAlignment"></param> /// <param name="flags"></param> public static void DrawText(IntPtr hdc, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text, ContentAlignment contentAlignment, int flags, bool rightToLeft) { NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT); NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color)); #if !PocketPC // QCR #439182 & 430913: the font is used for a control before even being initialized. // TODO: We need a better fix that avoids calling get_Font() for logical controls that are not initialized properly. if (fontDescription == null) { fontDescription = new FontDescription(Control.DefaultFont); } #endif NativeWindowCommon.RECT rc = new NativeWindowCommon.RECT(); rc.left = rect.Left; rc.right = rect.Right; rc.top = rect.Top + topOffset; rc.bottom = rect.Bottom; #if !PocketPC if (orientation != 0) { PrintRotatedText(hdc, fontDescription, orientation, text, rect, contentAlignment, rc, rightToLeft); } else #endif { IntPtr hFont = fontDescription.FontHandle; NativeWindowCommon.SelectObject(hdc, hFont); NativeWindowCommon.DrawText(hdc, text, text.Length, ref rc, flags); } }
/// <summary> /// /// </summary> /// <param name="hdc"></param> /// <param name="fontDescription"></param> /// <param name="orientation"></param> /// <param name="text"></param> /// <param name="rectangle"></param> /// <param name="contentAlignment"></param> /// <param name="rect"></param> internal static void PrintRotatedText(IntPtr hdc, FontDescription fontDescription, int orientation, string text, Rectangle rectangle, ContentAlignment contentAlignment, NativeWindowCommon.RECT rect, bool rightToLeft) { IntPtr hFont; Point point; // get the original font and its LOGFONT NativeWindowCommon.LOGFONT logfont = fontDescription.LogFont; // Set the rotation angle logfont.lfEscapement = logfont.lfOrientation = orientation; // create the new, rotated font hFont = NativeWindowCommon.CreateFontIndirect(logfont); NativeWindowCommon.SelectObject(hdc, hFont); point = CalculateStartCoordinates(hdc, rectangle, orientation, text, contentAlignment); uint fuOptions = NativeWindowCommon.ETO_CLIPPED; if (rightToLeft) { fuOptions = NativeWindowCommon.ETO_RTLREADING; } NativeWindowCommon.ExtTextOut(hdc, point.X, point.Y, fuOptions, ref rect, text, (uint)text.Length, null); NativeWindowCommon.DeleteObject(hFont); }
void inputPanel_EnabledChanged(object sender, System.EventArgs e) { Size changeFormSizeTo; if (Bounds != inputPanel.VisibleDesktop) { if (inputPanel.Enabled || previousSize == null) { // remember the form's size before the soft keyboard was opened previousSize = Size; changeFormSizeTo = inputPanel.VisibleDesktop.Size; } else { // use the size from before the soft keyboard was opened - the VisibleDesktop ignores // the menu bar size changeFormSizeTo = previousSize; } // Set the new size. The .Net way of changing the bounds does not work in this case, // so lets do it via win32 functions NativeWindowCommon.SetWindowPos(Handle, IntPtr.Zero, 0, 0, changeFormSizeTo.Width, changeFormSizeTo.Height, NativeWindowCommon.SWP_NOMOVE | NativeWindowCommon.SWP_NOZORDER); } }
/// <summary> /// /// </summary> /// <param name="inputChar"></param> /// <param name="checkText"></param> /// <returns></returns> public static bool IsMatchToHebMnemonicForText(char inputChar, string checkText) { bool isMatchToHebMnemonic = false; // get the accelerator of the control char acc = GetAcclerator(checkText); // If this Hebrew char if (IsUnicodeHeb(acc)) { // get the scan code of the char long scanCodeOfAccelarator = GuiHebChar2ScanCode((long)acc); if (scanCodeOfAccelarator != 0) { char charInEngOgAccelarator = (char)NativeWindowCommon.MapVirtualKey((uint)scanCodeOfAccelarator, NativeWindowCommon.MAPVK_VSC_TO_VK); inputChar = Char.ToUpper(inputChar); if (inputChar.Equals(charInEngOgAccelarator)) { isMatchToHebMnemonic = true; } } } return(isMatchToHebMnemonic); }
/// <summary> /// Update UIState of the control with NativeWindowCommon.UISF_HIDEFOCUS /// </summary> /// <param name="ctrl"></param> /// <param name="set"></param> private static void UpdateUIstate(Control ctrl, bool set) { int UIS_l = set ? NativeWindowCommon.UIS_SET : NativeWindowCommon.UIS_CLEAR; int wParam = NativeWindowCommon.MakeLong(UIS_l, NativeWindowCommon.UISF_HIDEFOCUS); NativeWindowCommon.SendMessage(ctrl.Handle, NativeWindowCommon.WM_UPDATEUISTATE, wParam, 0); ctrl.Invalidate(ctrl.ClientRectangle); }
public virtual void Dispose() { NativeWindowCommon.DeleteObject(HeaderDividerPen); if (TitleBrush != IntPtr.Zero) { NativeWindowCommon.DeleteObject(TitleBrush); } }
/// <summary> /// Returns the font text metrics for true type and non true type fonts assigned to control according to mgFont. /// </summary> /// <param name="control"></param> /// <param name="mgFont"></param> /// <returns></returns> public static PointF GetFontMetricsByMgFont(Control control, MgFont mgFont) { PointF retPoint; lock (_metricsMgFontCache) { if (!_metricsMgFontCache.TryGetValue(mgFont, out retPoint)) { #if PocketPC // In PocketPC, Panels don't have CreateGraphics. We go up the parents // tree until we find a non-panel one. while (control is Panel) { control = control.Parent; } #endif using (Graphics g = control.CreateGraphics()) { int dpiY = (int)g.DpiY; NativeWindowCommon.LOGFONT nativeLogFont = new NativeWindowCommon.LOGFONT(); nativeLogFont.lfFaceName = mgFont.TypeFace; nativeLogFont.lfHeight = -NativeWindowCommon.MulDiv(mgFont.Height, dpiY, 72); // Set the rotation angle nativeLogFont.lfEscapement = nativeLogFont.lfOrientation = mgFont.Orientation; nativeLogFont.lfItalic = Convert.ToByte(mgFont.Italic); nativeLogFont.lfStrikeOut = Convert.ToByte(mgFont.Strikethrough); nativeLogFont.lfUnderline = Convert.ToByte(mgFont.Underline); if (mgFont.Bold) { nativeLogFont.lfWeight = (int)NativeWindowCommon.FontWeight.FW_BOLD; } else { nativeLogFont.lfWeight = (int)NativeWindowCommon.FontWeight.FW_NORMAL; } nativeLogFont.lfCharSet = (byte)mgFont.CharSet; IntPtr hFont = NativeWindowCommon.CreateFontIndirect(nativeLogFont); // use the font in the DC GetTextMetrics(g, hFont, mgFont.TypeFace, mgFont.Height, out retPoint); //Release the resources. nativeLogFont = null; NativeWindowCommon.DeleteObject(hFont); } _metricsMgFontCache.Add(mgFont, retPoint); } } return(retPoint); }
/// <summary> /// Invalidates the non client area of the rich text box control. /// </summary> private void InvalidateNC() { NativeWindowCommon.SetWindowPos(this.Handle, IntPtr.Zero, 0, 0, 0, 0, NativeWindowCommon.SWP_NOMOVE | NativeWindowCommon.SWP_NOSIZE | NativeWindowCommon.SWP_NOZORDER | NativeWindowCommon.SWP_NOACTIVATE | NativeWindowCommon.SWP_DRAWFRAME); }
/// <summary> /// Draw the text supporting clipping according to ClipRegion. /// </summary> /// <param name="g"></param> /// <param name="color"></param> /// <param name="rect"></param> /// <param name="topOffset"></param> /// <param name="orientation"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="contentAlignment"></param> /// <param name="flags"></param> public static void ClipSupportingDrawText(Graphics g, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text, ContentAlignment contentAlignment, int flags, bool rightToLeft) { IntPtr region = IntPtr.Zero; IntPtr currentclippedRegion = g.Clip.GetHrgn(g); bool IsRegionInfinite = g.Clip.IsInfinite(g); IntPtr hdc = g.GetHdc(); NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT); NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color)); // Text rectangle as clip Region IntPtr clipRegion = NativeWindowCommon.CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom); // If Text starts above control, it needs to clip if (topOffset < 0) { // if current graphics is already clipped, then we need to merge with current text rectangle clip if (!IsRegionInfinite) { NativeWindowCommon.CombineRgn(currentclippedRegion, currentclippedRegion, clipRegion, NativeWindowCommon.RGN_AND); } } if (IsRegionInfinite) { // If there is no clip region on graphics, set text rectangle as clip region region = clipRegion; } else if (currentclippedRegion != IntPtr.Zero) { // use intersected region as clip region region = currentclippedRegion; } // Select resultant clipped region on DC if (region != IntPtr.Zero) { NativeWindowCommon.SelectClipRgn(hdc, region); } if (clipRegion != IntPtr.Zero) { NativeWindowCommon.DeleteObject(clipRegion); } // Draw text DrawText(hdc, color, rect, topOffset, orientation, fontDescription, text, contentAlignment, flags, rightToLeft); // release objects g.ReleaseHdc(hdc); if (currentclippedRegion != IntPtr.Zero) { g.Clip.ReleaseHrgn(currentclippedRegion); } }
// Our wndproc private int formWindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { // Do not activate this form - leave it hidden if (msg == NativeWindowCommon.WM_ACTIVATE) { Hide(); return(0); } return(NativeWindowCommon.CallWindowProc(_origFormWndProc, hwnd, msg, wParam, lParam)); }
/// <include file="doc\FormDocumentDesigner.uex" path='docs/doc[@for="FormDocumentDesigner.OnDesignerDeactivate"]/*'> /// <devdoc> /// Called by the host when we become inactive. Here we update the /// title bar of our form so it's the inactive color. /// </devdoc> private void OnDesignerDeactivate(object sender, EventArgs e) { Control control = Control; if (control != null && control.IsHandleCreated) { NativeWindowCommon.SendMessage(control.Handle, NativeWindowCommon.WM_NCACTIVATE, 0, 0); NativeWindowCommon.RedrawWindow(control.Handle, IntPtr.Zero, IntPtr.Zero, NativeWindowCommon.RedrawWindowFlags.RDW_FRAME); } }
/// <summary> /// get control for currently focused window /// </summary> /// <returns></returns> public static Control GetFocusedControl() { Control focusControl = null; IntPtr focusHandle = NativeWindowCommon.GetFocus(); if (focusHandle != IntPtr.Zero) { // returns null if handle is not to a .NET control focusControl = Control.FromHandle(focusHandle); } return(focusControl); }
/// <summary> /// unlock window draw if thumb drag in process or has ended /// </summary> /// <returns></returns> public bool UnlockWindowDrawOnThumbDrag() { if (_isThumbDrag) { NativeWindowCommon.LockWindowUpdate(IntPtr.Zero); return(true); } else { return(false); } }
/// <summary> implement ControlPaint.DrawFocusRectangle /// </summary> /// <param name="graphics"></param> /// <param name="rectangle"></param> internal static void DrawFocusRectangle(Graphics graphics, Rectangle rectangle) { IntPtr hdc = graphics.GetHdc(); RECT rc = new RECT(); rc.left = rectangle.Left; rc.top = rectangle.Top; rc.right = rectangle.Right; rc.bottom = rectangle.Bottom; NativeWindowCommon.DrawFocusRect(hdc, ref rc); graphics.ReleaseHdc(hdc); }
/// <summary> /// Callback method for the handling of messages to be sent to/from the folder browser dialog. /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="lParam"></param> /// <param name="lpData"></param> /// <returns></returns> private int FolderBrowserDialog_BrowseCallbackProc(IntPtr hwnd, int msg, IntPtr lParam, IntPtr lpData) { switch (msg) { case NativeWindowCommon.BFFM_INITIALIZED: // We get in here when the dialog is first displayed. If an initial directory // has been specified we will make this the selection now, and also make sure // that directory is expanded. if (this.selectedPath.Length != 0) { NativeWindowCommon.SendMessage(hwnd, NativeWindowCommon.BFFM_SETSELECTIONW, 1, this.selectedPath); } break; case NativeWindowCommon.BFFM_SELCHANGED: { IntPtr pidl = lParam; if (pidl != IntPtr.Zero) { StringBuilder sb = new StringBuilder(MAX_PATH * Marshal.SystemDefaultCharSize); bool flag = NativeWindowCommon.SHGetPathFromIDList(pidl, sb); NativeWindowCommon.SendMessage(hwnd, NativeWindowCommon.BFFM_ENABLEOK, 0, flag ? 1 : 0); } if (!doneScrolling) { IntPtr hbrowse = NativeWindowCommon.FindWindowEx(hwnd, IntPtr.Zero, "SHBrowseForFolder ShellNameSpace Control", null); IntPtr htree = NativeWindowCommon.FindWindowEx(hbrowse, IntPtr.Zero, "SysTreeView32", null); IntPtr htis = NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_GETNEXTITEM, NativeWindowCommon.TVGN_CARET, IntPtr.Zero); IntPtr htir = NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_GETNEXTITEM, NativeWindowCommon.TVGN_ROOT, IntPtr.Zero); IntPtr htic = NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_GETNEXTITEM, NativeWindowCommon.TVGN_CHILD, htir); //we actually go into the BFFM_SELCHANGED case three times when the dialog is first shown, and it's only on the third one that we actually scroll, //since before this htic is always zero, so you need to cope with this //- i.e. don't set 'doneScrolling' flag until htic has been non - zero(or until you've gone into the BFFM_SELCHANGED three times). if ((int)htic != 0) { doneScrolling = true; //The only solution I've found that works consistently is to send a TVM_ENSUREVISIBLE to the tree, using TVM_GETNEXTITEM/TVGN_CARET, from BFFM_SELCHANGED. //That works. Every time. NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_ENSUREVISIBLE, 0, htis); //Active the tree view control window inside the folder browser dialog to set the focus on it. NativeWindowCommon.SendMessage(htree, NativeWindowCommon.WM_ACTIVATE, 1, 0); } } } break; } return(0); }
/// <summary> /// Create a cursor using the Native win32 call. /// Note : When we use overloaded constructor of SWF.Cursor(Stream/String) to create a /// cursor for an animated cursor, it throws bad image file exception. /// Hence, we need to use WIN32 API LoadCursorFromFile /// </summary> /// <param name="fileName">cursor file name</param> /// <returns></returns> private Cursor CreateCursor(String fileName) { IntPtr hCursor = NativeWindowCommon.LoadCursorFromFile(fileName); if (!IntPtr.Zero.Equals(hCursor)) { return(new Cursor(hCursor)); } else { throw new Exception(); } }
/// <summary> /// Draw Header section filter /// </summary> /// <param name="hdc"></param> /// <param name="rct"></param> /// <param name="g"></param> public void DrawFilter(IntPtr hdc, NativeWindowCommon.RECT rct) { //Filter line drawing int x = rct.right - FILTER_WIDTH; int bottomY = 0; Header.HeaderRenderer.DrawLine(hdc, new Point(x, bottomY), new Point(x, Header.FilterHeight)); //Filter highlight drawing NativeWindowCommon.RECT rectHighlight = new NativeWindowCommon.RECT() { bottom = Header.FilterHeight, top = 0, left = rct.right - FILTER_WIDTH + 1, right = rct.right + 1 }; if ((FilterColor != Color.Empty) && !Header.OnSectionResize) { if (Header.TitleColor != Color.Empty) { Header.HighlightBrush = NativeWindowCommon.CreateSolidBrush(ColorTranslator.ToWin32(FilterColor)); } else { Header.HighlightBrush = NativeWindowCommon.CreateSolidBrush(ColorTranslator.ToWin32(Color.FromArgb(255, 149, 202, 255))); } NativeWindowCommon.FillRect(hdc, ref rectHighlight, Header.HighlightBrush); NativeWindowCommon.DeleteObject(Header.HighlightBrush); } int filterWidthIcon = FILTER_WIDTH / 3; //Filter arrow drawing NativeWindowCommon.POINT[] points = new NativeWindowCommon.POINT[3]; //right points[0].x = rct.right - filterWidthIcon; points[0].y = rct.top + (rct.bottom - rct.top) / 2 - 2; // center point points[1].x = rct.right - FILTER_WIDTH / 2; points[1].y = points[0].y + filterWidthIcon / 2; // left point points[2].x = points[0].x - filterWidthIcon; points[2].y = points[0].y; NativeWindowCommon.SelectObject(hdc, Header.FilterBrush); NativeWindowCommon.SelectObject(hdc, Header.FilterPen); NativeWindowCommon.Polygon(hdc, points, 3); }
/// <summary> implement ControlPaint.DrawBorder3D. /// This is a basic implementation, using DrawEdge. For now, it is good enough for /// the sunken style we need. /// </summary> /// <param name="graphics"></param> /// <param name="rectangle"></param> /// <param name="style"></param> internal static void DrawBorder3D(Graphics graphics, Rectangle rectangle, Border3DStyle style) { RECT rc = new RECT(); rc.left = rectangle.Left; rc.top = rectangle.Top; rc.right = rectangle.Right; rc.bottom = rectangle.Bottom; IntPtr hdc = graphics.GetHdc(); // Border3DStyle flags are the same values as DrawEdge flags NativeWindowCommon.DrawEdge(hdc, ref rc, (uint)style, NativeWindowCommon.BF_RECT); graphics.ReleaseHdc(hdc); }
/// <summary> /// handle vertical scroll /// </summary> /// <param name="m"></param> private void OnVScroll(ref Message m) { int newValue = Int32.MinValue; NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_VERT); int value = sc.nPos; int nScrollCode = NativeWindowCommon.LoWord((int)m.WParam); switch (nScrollCode) { case NativeScroll.SB_TOP: newValue = 0; break; case NativeScroll.SB_BOTTOM: newValue = sc.nMax; break; case NativeScroll.SB_LINEUP: newValue = value - 1; break; case NativeScroll.SB_LINEDOWN: newValue = value + 1; break; case NativeScroll.SB_PAGEUP: newValue = value - sc.nPage; break; case NativeScroll.SB_PAGEDOWN: newValue = value + sc.nPage; break; case NativeScroll.SB_THUMBPOSITION: EndThumbDrag(); break; case NativeScroll.SB_THUMBTRACK: StartThumbDrag(); newValue = GetThumbTrackVal(sc.nTrackPos); value = GetPrevScrollVal(sc.nPos); break; } if (newValue != Int32.MinValue && newValue != value) { ScrollVertically((ScrollEventType)m.WParam, newValue, value, true); } }
/// <summary> /// Sets the current process as dots per inch (dpi) aware. /// Scaling by Dpi is useful when you want to size a control or form relative to the screen. /// For example, you may want to use dots per inch (DPI) scaling on a control displaying a chart or other graphic /// so that it always occupies a certain percentage of the screen. /// </summary> public static void SetProcessDPIAwareness() { if (System.Environment.OSVersion.Version.Major >= 6) { //If the OS is windows 8.1 or higher i.e windows 10. The minor version is 2. if (System.Environment.OSVersion.Version.Minor >= 2) { NativeWindowCommon.SetProcessDpiAwareness(NativeWindowCommon.PROCESS_DPI_AWARENESS.Process_System_DPI_Aware); } else //The version is vista or later(e.g. Windows 7). On windows 7, the minor version is 1 { NativeWindowCommon.SetProcessDPIAware(); } } }
protected override void Dispose(bool bDisposing) { if (this.hBitmap != IntPtr.Zero) { NativeWindowCommon.DeleteObject(this.hBitmap); this.hBitmap = IntPtr.Zero; } if (bDisposing && this.collection != null) { this.collection.Remove(this); } base.Dispose(bDisposing); }
/// <summary> /// expand all panels /// </summary> public void ExpandAll() { // Suspend painting until all panels are visible NativeWindowCommon.SendMessage(Handle, NativeWindowCommon.WM_SETREDRAW, false, 0); foreach (Panel panel in Panels) { EnsureExpanded(panel); } // Resume painting NativeWindowCommon.SendMessage(Handle, NativeWindowCommon.WM_SETREDRAW, true, 0); Refresh(); // refresh }
/// <summary> /// WindowProc of the drop down list box. /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> protected int DropDownWindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { switch (msg) { case NativeWindowCommon.WM_LBUTTONDOWN: // when the user click on the drop down arise the event if (MouseDownOnDropDownList != null) { MouseDownOnDropDownList(this, new EventArgs()); } break; } return(NativeWindowCommon.CallWindowProc(OriginalDropDownWindowProc, hwnd, (uint)msg, wParam, lParam)); }