/// <summary> /// The actual method that makes API calls to drop the shadow to the window /// </summary> /// <param name="window">Window to which the shadow will be applied</param> /// <returns>True if the method succeeded, false if not</returns> private static bool DropShadow(Window window) { try { WindowInteropHelper helper = new WindowInteropHelper(window); int val = 2; int ret1 = DwmSetWindowAttribute(helper.Handle, 2, ref val, 4); if (ret1 == 0) { Margins m = new Margins { Bottom = 0, Left = 0, Right = 0, Top = 0 }; int ret2 = DwmExtendFrameIntoClientArea(helper.Handle, ref m); return ret2 == 0; } else { return false; } } catch (Exception ex) { // Probably dwmapi.dll not found (incompatible OS) return false; } }
public void Dock(Margins margins, Rect expectedRect) { var sut = new RightDocker(new Size(100, 50)); var actualRect = sut.GetDockingRect(_layoutable.DesiredSize, margins, new Alignments(Alignment.Middle, Alignment.Stretch)); Assert.Equal(expectedRect, actualRect); }
private void SetupShell(Window window) { //Source: http://code-inside.de/blog/2012/11/11/howto-rahmenlose-wpf-apps-mit-schattenwurf/ window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; window.ShowInTaskbar = false; window.Topmost = true; window.SourceInitialized += (o, e) => { if (!Helper.IsWindows7) return; var helper = new WindowInteropHelper(window); var val = 2; DwmSetWindowAttribute(helper.Handle, 2, ref val, 4); var m = new Margins { bottomHeight = -1, leftWidth = -1, rightWidth = -1, topHeight = -1 }; DwmExtendFrameIntoClientArea(helper.Handle, ref m); var hwnd = new WindowInteropHelper(window).Handle; }; window.MouseLeftButtonDown += (o, e) => window.DragMove(); //Track changes on TopMost-settings _Settings.PropertyChanged += (o, e) => { if (e.PropertyName == "AlwaysOnTop") window.Topmost = _Settings.AlwaysOnTop; }; }
protected internal void CalcRect(Rectangle prev, SpriteFont font, Margins margins, Point offset, bool first) { int size = (int)Math.Ceiling(font.MeasureString(Text).X) + margins.Horizontal; if (first) offset.X = 0; headerRect = new Rectangle(prev.Right + offset.X, prev.Top, size, prev.Height); }
public SkinControl(SkinControl source) : base(source) { this.Inherits = source.Inherits; this.DefaultSize = source.DefaultSize; this.MinimumSize = source.MinimumSize; this.OriginMargins = source.OriginMargins; this.ClientMargins = source.ClientMargins; this.ResizerSize = source.ResizerSize; this.Layers = new SkinList<SkinLayer>(source.Layers); this.Attributes = new SkinList<SkinAttribute>(source.Attributes); }
public Rect GetDockingRect(Size sizeToDock, Margins margins, Alignments alignments) { var marginsCutout = margins.AsThickness(); var withoutMargins = OriginalRect.Deflate(marginsCutout); var finalRect = withoutMargins.AlignChild(sizeToDock, Alignment.Start, alignments.Vertical); AccumulatedOffset += sizeToDock.Width; margins.HorizontalMargin = margins.HorizontalMargin.Offset(sizeToDock.Width, 0); return finalRect; }
/// <summary>Enables Aero Glass on a WPF window, no exception thrown if OS does not support DWM.</summary> /// <param name="window">The window to enable glass.</param> /// <param name="margins">The region to add glass.</param> public static void EnableGlass(Window window, Margins margins) { if (Environment.OSVersion.Version.Major < 6) { return; } if (margins.TopHeight == 0 && margins.BottomHeight == 0 && margins.RightWidth == 0 && margins.LeftWidth == 0) { margins = new Margins(true); } if (window == null) { throw new ArgumentNullException("window"); } IntPtr windowHandle = new WindowInteropHelper(window).Handle; if (windowHandle == IntPtr.Zero) { return; } // add Window Proc hook to capture DWM messages HwndSource source = HwndSource.FromHwnd(windowHandle); if (source == null) { throw new FormatException(); } source.AddHook(WndProc); // Set the Background to transparent from Win32 perspective HwndSource handleSource = HwndSource.FromHwnd(windowHandle); if (handleSource != null) { if (handleSource.CompositionTarget != null) { handleSource.CompositionTarget.BackgroundColor = Colors.Transparent; } } // Set the Background to transparent from WPF perspective window.Background = Brushes.Transparent; ResetAeroGlass(margins, windowHandle); }
public SkinLayer(SkinLayer source) : base(source) { if (source != null) { this.Image = new SkinImage(source.Image); this.Width = source.Width; this.Height = source.Height; this.OffsetX = source.OffsetX; this.OffsetY = source.OffsetY; this.Alignment = source.Alignment; this.SizingMargins = source.SizingMargins; this.ContentMargins = source.ContentMargins; this.States = source.States; this.Overlays = source.Overlays; this.Text = new SkinText(source.Text); this.Attributes = new SkinList<SkinAttribute>(source.Attributes); } else { throw new Exception("Parameter for SkinLayer copy constructor cannot be null."); } }
public static bool ExtendGlassFrame(Window window, Thickness margin) { if (!DwmIsCompositionEnabled()) return false; IntPtr hwnd = new WindowInteropHelper(window).Handle; if (hwnd == IntPtr.Zero) throw new InvalidOperationException("The Window must be shown before extending glass."); // Set the background to transparent from both the WPF and Win32 perspectives SolidColorBrush background = new SolidColorBrush(Colors.Red); background.Opacity = 0.5; window.Background = Brushes.Transparent; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; Margins margins = new Margins(margin); DwmExtendFrameIntoClientArea(hwnd, ref margins); return true; }
private void EnableGlass() { if (Environment.OSVersion.Version.Major < 6 || !DwmIsCompositionEnabled()) return; // Get the current window handle var mainWindowPtr = new WindowInteropHelper(this).Handle; var mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); if (mainWindowSrc != null) if (mainWindowSrc.CompositionTarget != null) mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent; else return; else return; Background = Brushes.Transparent; // Set the proper margins for the extended glass part var margins = new Margins { cxLeftWidth = -1, cxRightWidth = -1, cyTopHeight = -1, cyBottomHeight = -1 }; DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); }
public static IEnumerable <FluentLayout> FullSizeOf( [NotNull] this UIView view, [NotNull] UIView parent, [NotNull] IUILayoutSupport topLayoutGuide, [NotNull] IUILayoutSupport bottomLayoutGuide, [NotNull] Margins margins) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (topLayoutGuide == null) { throw new ArgumentNullException(nameof(topLayoutGuide)); } if (bottomLayoutGuide == null) { throw new ArgumentNullException(nameof(bottomLayoutGuide)); } if (margins == null) { throw new ArgumentNullException(nameof(margins)); } var nsTopLayoutGuide = Runtime.GetNSObject(topLayoutGuide.Handle); var nsBottomLayoutGuide = Runtime.GetNSObject(bottomLayoutGuide.Handle); return(new List <FluentLayout> { view.Top().NotNull().EqualTo(margins.Top).NotNull().BottomOf(nsTopLayoutGuide).NotNull().WithIdentifier("Top"), view.Bottom().NotNull().EqualTo(margins.Bottom).NotNull().TopOf(nsBottomLayoutGuide).NotNull().WithIdentifier("Bottom"), view.AtLeftOf(parent, margins.Left).NotNull().WithIdentifier("Left"), view.AtRightOf(parent, margins.Right).NotNull().WithIdentifier("Right") }); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Color hoverColor = Color.FromArgb(255, 0, 0); List <Color> colors = new List <Color>(); GridAddress address = new GridAddress(1, 1); Margins margins = new Margins(); int width = 400; bool labels = true; DA.GetData <Color>(0, ref hoverColor); DA.GetData <GridAddress>(2, ref address); DA.GetData <Margins>(3, ref margins); DA.GetData <int>(4, ref width); DA.GetData <bool>(5, ref labels); // create style PieChartStyle style = new PieChartStyle(); if (DA.GetDataList <Color>(1, colors)) { List <string> hexColors = colors.Select(x => ChartsUtilities.ColorToHexString(Color.FromArgb(x.A, x.R, x.G, x.B))).ToList(); style.Colors = new JavaScriptSerializer().Serialize(hexColors); } else { style.Colors = null; } style.HoverColor = ChartsUtilities.ColorToHexString(hoverColor); style.GridRow = address.X; style.GridColumn = address.Y; style.Width = width; style.Labels = labels; style.Margins = margins; style.SizeX = (int)Math.Ceiling(width / 100d); style.SizeY = (int)Math.Ceiling(width / 100d); DA.SetData(0, style); }
/// <summary> /// 给顾卡打印收费小票 /// </summary> /// <param name="hije"></param> /// <param name="hjch"></param> /// <param name="yfje"></param> /// <param name="list"></param> /// <param name="ibmap"></param> /// <param name="sb"></param> /// <param name="name"></param> /// <param name="cardnumber"></param> /// <param name="time"></param> public static void PirentSH(string hije, string hjch, string yfje, List <shInfoList> list, Image ibmap, string sb, string name, string cardnumber, string time, string gksy) { _beginy = 0; _gksy = gksy; _time = time; _name = name; _cardnumber = cardnumber; _hije = hije; _hjch = hjch; _yfje = yfje; _sb = sb; _list = list; _ibmap = ibmap; //打印预览 PrintPreviewDialog ppd = new PrintPreviewDialog(); PrintDocument pd = new PrintDocument(); //设置边距 Margins margin = new Margins(20, 20, 20, 20); //pd.PrinterSettings.PrinterName = FilterClass.MemberXF; pd.DefaultPageSettings.Margins = margin; //默认纸张 PaperSize pageSize = new PaperSize("First custom size", getYc(58), 5000); pd.DefaultPageSettings.PaperSize = pageSize; //打印事件设置 pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); ppd.Document = pd; ppd.ShowDialog(); try { pd.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); pd.PrintController.OnEndPrint(pd, new PrintEventArgs()); } }
private void printdoc_PrintPage(object sender, PrintPageEventArgs e) { Rectangle rectangle1 = this.pageSetting.Bounds; float single1 = 1f; Margins margins1 = this.pageSetting.Margins.Clone() as Margins; margins1.Left = (int)(margins1.Left * .9f); margins1.Right = (int)(margins1.Right * .9f); margins1.Top = (int)(margins1.Top * .9f); margins1.Bottom = (int)(margins1.Bottom * .9f); // SizeF size1 = this.vectorControl.DocumentSize; Rectangle rectangle2 = rectangle1; rectangle2.Offset(margins1.Left, margins1.Top); rectangle2.Width -= rectangle2.X + margins1.Right; rectangle2.Height -= rectangle2.Y + margins1.Bottom; float single2 = ((float)(this.label8.Height - (2 * this.margin))) / ((float)rectangle1.Height); float single3 = ((float)(this.label8.Width - (2 * this.margin))) / ((float)rectangle1.Width); int num1 = (int)(single1 * margins1.Left); int num2 = (int)(single1 * margins1.Top); e.Graphics.SetClip(rectangle2); e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.TranslateTransform(((float)-this.pos.X) / single3, ((float)-this.pos.Y) / single2); // if (this.radioFit.Checked) // { e.Graphics.TranslateTransform((float)num1, (float)num2); //Ò³±ß¾à // } e.Graphics.ScaleTransform(this.scalex / single3, this.scaley / single2); this.RenderTo(e.Graphics); }
private async void DirectorySearchDialog_Shown(object sender, EventArgs e) { Text = string.Format(Text, ProjectName, Program.VersionString); if (NativeMethods.DwmIsCompositionEnabled()) { _margins = new Margins { Top = 38 }; NativeMethods.DwmExtendFrameIntoClientArea(Handle, ref _margins); } _ftp = new FtpManager(Host, Port, null, Username, Password, null, UsePassiveMode, FtpAssemblyPath, Protocol, NetworkVersion); var node = new TreeNode("Server", 0, 0); serverDataTreeView.Nodes.Add(node); await LoadListAsync("/", node); node.Expand(); }
public static IEnumerable <object[]> Equals_Margin_TestData() { var margins = new Margins(1, 2, 3, 4); yield return(new object[] { margins, margins, true }); yield return(new object[] { margins, new Margins(1, 2, 3, 4), true }); yield return(new object[] { margins, new Margins(2, 2, 3, 4), false }); yield return(new object[] { margins, new Margins(1, 3, 3, 4), false }); yield return(new object[] { margins, new Margins(1, 2, 4, 4), false }); yield return(new object[] { margins, new Margins(1, 2, 3, 5), false }); yield return(new object[] { null, null, true }); yield return(new object[] { null, new Margins(1, 2, 3, 4), false }); yield return(new object[] { new Margins(1, 2, 3, 4), null, false }); }
public UkupnoIzvestaj(IList <RezultatUkupnoExtended> rezultati, Gimnastika gim, bool extended, bool kvalColumn, bool penalty, DataGridView formGrid, string documentName, bool stampanjeKvalifikanata) { DocumentName = documentName; Font itemFont = new Font("Arial", 8); Font itemsHeaderFont = new Font("Arial", 8, FontStyle.Bold); Landscape = extended; if (extended) { Margins = new Margins(40, 40, 50, 50); } else { Margins = new Margins(75, 75, 75, 75); } lista = new UkupnoLista(this, 1, 0f, itemFont, itemsHeaderFont, rezultati, gim, extended, kvalColumn, penalty, formGrid, stampanjeKvalifikanata); }
public RptReport() { _PrintDocument = new PrintDocument(); _Margins = _PrintDocument.DefaultPageSettings.Margins; _PaperSize = _PrintDocument.DefaultPageSettings.PaperSize; if ((_PaperSize.Width < _Margins.Left + _Margins.Right) || (_PaperSize.Height < _Margins.Top + _Margins.Bottom)) { _PaperSize = DIYReport.Print.RptPageSetting.GetPaperSizeByName(_PrintDocument, null, "A4"); } //_ReportDataWidth = _PaperSize.Width - _Margins.Left - _Margins.Right ; _IsLandscape = _PrintDocument.DefaultPageSettings.Landscape; _IsEndUpdate = true; _FillNULLRow = false; _SectionList = new RptSectionList(); _SectionList.Report = this; _SubReports = new Hashtable(); }
private void LoadSettings() { var cfg = AppGlobals.Config.Printing; chkPrintPageFoot.Checked = cfg.PrintPageFoot; chkChangeStartPageNum.Checked = false; txtStartPageNumber.Text = "1"; cboPrintTextManualDoubleSide.SelectedIndex = 0; chkPrintBraille.Checked = cfg.PrintBrailleToBrailler; chkPrintBrailleToFile.Checked = cfg.PrintBrailleToFile; txtBrailleFileName.TextBox.Text = cfg.PrintBrailleToFileName; chkSendPageBreakAtEof.Checked = cfg.PrintBrailleSendPageBreakAtEndOfDoc; lblLinesPerPage.Text = AppGlobals.Config.Braille.LinesPerPage.ToString(); lblCellsPerLine.Text = m_BrDoc.CellsPerLine.ToString(); m_PaperSourceName = cfg.PrintTextPaperSourceName; m_PaperName = cfg.PrintTextPaperName; m_TextFontName = cfg.PrintTextFontName; m_TextFontSize = cfg.PrintTextFontSize; m_OddPageMargins = new Margins(cfg.PrintTextMarginLeft, cfg.PrintTextMarginRight, cfg.PrintTextMarginTop, cfg.PrintTextMarginBottom); m_EvenPageMargins = new Margins(cfg.PrintTextMarginLeft2, cfg.PrintTextMarginRight2, cfg.PrintTextMarginTop2, cfg.PrintTextMarginBottom2); cboPrinters.Items.Clear(); cboPrintersForBraille.Items.Clear(); cboPrintersForBraille.Items.Add(AppGlobals.Config.Printing.BraillePrinterPort); foreach (string s in PrinterSettings.InstalledPrinters) { cboPrinters.Items.Add(s); cboPrintersForBraille.Items.Add(s); } if (!String.IsNullOrEmpty(cfg.DefaultTextPrinter)) { cboPrinters.SelectedIndex = cboPrinters.Items.IndexOf(cfg.DefaultTextPrinter); } if (!String.IsNullOrWhiteSpace(cfg.BraillePrinterName)) { cboPrintersForBraille.Text = cfg.BraillePrinterName; } }
internal static void EnableGlassEffect(IntPtr windowHandle, Margins margins) { try { if (DwmApi.DwmIsCompositionEnabled()) { IntPtr Handle = windowHandle; DwmApi.DwmExtendFrameIntoClientArea(Handle, ref margins); return; } else { //Glass effect is not enabled -> do nothing return; } } catch (DllNotFoundException) { return; } }
/// <summary> /// Gets the margins of the control /// </summary> /// <param name="control">control</param> /// <returns>margins</returns> public static Margins GetMargins(Control control) { Margins margins = new Margins(); if (control != null) { WindowInfo info = new WindowInfo(); info.cbSize = Marshal.SizeOf(info); if (GetWindowInfo(control.Handle, ref info) == false) { throw new InvalidOperationException(); } margins.Left = info.rcClient.left - info.rcWindow.left; margins.Right = info.rcWindow.right - info.rcClient.right; margins.Top = info.rcClient.top - info.rcWindow.top; margins.Bottom = info.rcWindow.bottom - info.rcClient.bottom; } return(margins); }
public PrintOptions() : base() { m_AllPages = true; m_FromPage = 0; m_ToPage = 0; DoubleSide = false; PrintPageFoot = true; ReassignStartPageNumber = false; StartPageNumber = 1; LinesPerPage = Constant.DefaultLinesPerPage; DoubleSideEffect = DoubleSideEffect.None; PaperSourceName = ""; PaperName = "custom"; OddPageMargins = new Margins(); EvenPageMargins = new Margins(); BrUseNewLineForPageBreak = false; BrSendPageBreakAtEndOfDoc = false; }
public UkupnoFinaleKupaIzvestaj(IList <RezultatUkupnoFinaleKupa> rezultati, Gimnastika gim, bool extended, bool kvalColumn, DataGridView formGrid, string documentName) { DocumentName = documentName; extended = false; // TODO3: Ispravi ovo (isto i u UkupnoZbirViseKolaIzvestaj). Font itemFont = new Font("Arial", 8); Font itemsHeaderFont = new Font("Arial", 8, FontStyle.Bold); Landscape = extended; if (extended) { Margins = new Margins(40, 40, 50, 50); } else { Margins = new Margins(75, 75, 75, 75); } lista = new UkupnoFinaleKupaLista(this, 1, 0f, itemFont, itemsHeaderFont, rezultati, gim, extended, kvalColumn, formGrid); }
/// <summary> /// This routine prints one page. It will skip non-printable pages if the user /// selected the "some pages" option on the print dialog. This is called during /// the Print event. /// </summary> /// <param name="g">Graphics object to print to</param> private bool PrintPage(Graphics g) { //// flag for continuing or ending print process //bool HasMorePages = false; //// flag for handling printing some pages rather than all //bool printthispage = false; //// current printing position within one page //float printpos = PrintMargins.Top;// pagesets[currentpageset].margins.Top; //// increment page number & check page range //CurrentPage++; //if ((CurrentPage >= fromPage) && (CurrentPage <= toPage)) // printthispage = true; //// calculate the static vertical space available - this is where we stop printing rows //staticheight = pageHeight - PrintMargins.Top;// FooterHeight - pagesets[currentpageset].margins.Bottom; //// count space used as we work our way down the page //float used = 0; Margins m = printDoc.DefaultPageSettings.Margins; g.DrawImageUnscaled(m_Image, new Point(m.Left, m.Top)); // g.DrawImageUnscaled(m_Image, new Point(PrintMargins.Left, PrintMargins.Top)); //g.DrawImage(m_Image, // new Rectangle( new Point( PrintMargins.Left,PrintMargins.Top), // new Size(m_Image.Width, m_Image.Height))); //----------------------------------------------------------------- // print headers //----------------------------------------------------------------- return(false); }
public void print_view(IWin32Window win) { /* * this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController(); * this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage); * this.printDocument1.Print(); */ this.printd_pos.PrintController = new System.Drawing.Printing.StandardPrintController(); this.printd_pos.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printd_pos_PrintPage); //设置边距 Margins margins = new Margins(32, 5, 30, 5); this.printd_pos.DefaultPageSettings.Margins = margins; this.printd_pos.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("First custom size", getYc(78), 600); //this.printDocument1.PrinterSettings.PrinterName = ""; //Margins margins = new Margins( //this.printv_pos.Document = this.printd_pos; printv_pos.PrintPreviewControl.AutoZoom = false; printv_pos.PrintPreviewControl.Zoom = 1; this.printv_pos.ShowDialog(win); //try //{ // printd_pos.Print(); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); // printd_pos.PrintController.OnEndPrint(printd_pos, new PrintEventArgs()); //} }
/// <summary> /// Excludes a Control from the AeroGlass frame. /// </summary> /// <param name="control">The control to exclude.</param> /// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not /// render properly on top of an AeroGlass frame. </remarks> public void ExcludeControlFromAeroGlass(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if (AeroGlassCompositionEnabled) { Rectangle clientScreen = this.RectangleToScreen(this.ClientRectangle); Rectangle controlScreen = control.RectangleToScreen(control.ClientRectangle); Margins margins = new Margins(); margins.LeftWidth = controlScreen.Left - clientScreen.Left; margins.RightWidth = clientScreen.Right - controlScreen.Right; margins.TopHeight = controlScreen.Top - clientScreen.Top; margins.BottomHeight = clientScreen.Bottom - controlScreen.Bottom; // Extend the Frame into client area DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margins); } }
public static void Export(LocalReport report, bool print = true) { PaperSize paperSize = m_pageSettings.PaperSize; Margins margins = m_pageSettings.Margins; // The device info string defines the page range to print as well as the size of the page. // A start and end page of 0 means generate all pages. string deviceInfo = string.Format( CultureInfo.InvariantCulture, "<DeviceInfo>" + "<OutputFormat>EMF</OutputFormat>" + "<PageWidth>{3}</PageWidth>" + "<PageHeight>{4}</PageHeight>" + "<MarginTop>{0}</MarginTop>" + "<MarginLeft>{2}</MarginLeft>" + "<MarginRight>{2}</MarginRight>" + "<MarginBottom>{3}</MarginBottom>" + "</DeviceInfo>", ToInches(margins.Top), ToInches(margins.Left), ToInches(margins.Right), ToInches(margins.Bottom), ToInches(paperSize.Height), ToInches(paperSize.Width)); Warning[] warnings; m_streams = new List <Stream>(); report.Render("Image", deviceInfo, CreateStream, out warnings); foreach (Stream stream in m_streams) { stream.Position = 0; } if (print) { Print(); } }
private void setShadow() { if (!_aeroEnabled || !EnableShadow) { return; } int v = 2; DwmSetWindowAttribute(Handle, 2, ref v, 4); int marginVal = FixShadowTransparency ? -1 : 1; var margins = new Margins { BottomHeight = marginVal, LeftWidth = marginVal, RightWidth = marginVal, TopHeight = marginVal }; DwmExtendFrameIntoClientArea(Handle, ref margins); }
protected virtual PageSettings ShowPageSetupDialog(System.Drawing.Printing.PrintDocument printDocument_1) { this.ThrowPrintDocumentNullException(printDocument_1); PageSettings defaultPageSettings = new PageSettings(); PageSetupDialog dialog = new PageSetupDialog(); defaultPageSettings = printDocument_1.DefaultPageSettings; try { dialog.Document = printDocument_1; Margins margins = printDocument_1.DefaultPageSettings.Margins; if (RegionInfo.CurrentRegion.IsMetric) { margins = PrinterUnitConvert.Convert(margins, PrinterUnit.Display, PrinterUnit.TenthsOfAMillimeter); } PageSettings settings2 = (PageSettings)printDocument_1.DefaultPageSettings.Clone(); dialog.PageSettings = settings2; dialog.PageSettings.Margins = margins; if (dialog.ShowDialog() == DialogResult.OK) { defaultPageSettings = dialog.PageSettings; printDocument_1.DefaultPageSettings = dialog.PageSettings; } } catch (InvalidPrinterException exception) { this.ShowInvalidPrinterException(exception); } catch (Exception exception2) { this.ShowPrinterException(exception2); } finally { dialog.Dispose(); dialog = null; } return(defaultPageSettings); }
public void print() { try { PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); Margins margins = new Margins(0, 0, 0, 0); pd.DefaultPageSettings.Margins = margins; // Set the printer name. //pd.PrinterSettings.PrinterName = "\\NS5\hpoffice //pd.PrinterSettings.PrinterName = "Zebra New GK420t" pd.Print(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } MessageBox.Show("Done Printing."); }
public static void Glass(Form win, int left = -1, int right = -1, int top = -1, int bottom = -1) { //WindowInteropHelper windowInterop = new WindowInteropHelper(win); //IntPtr windowHandle = windowInterop.Handle; //HwndSource mainWindowSrc = HwndSource.FromHwnd(windowHandle); //mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent; IntPtr windowHandle = win.Handle; Margins margins = GetMargins(windowHandle, left, right, top, bottom); int returnVal = DwmExtendFrameIntoClientArea(windowHandle, ref margins); if ((returnVal < 0)) { throw new NotSupportedException("?5@0F8O 7025@H8;0AL =5C40G=>"); } else { const int dwmwaNcrenderingPolicy = 2; var dwmncrpDisabled = 2; DwmSetWindowAttribute(windowHandle, dwmwaNcrenderingPolicy, ref dwmncrpDisabled, sizeof(int)); } }
private void btnPageSetup_Click(object sender, EventArgs e) { Margins originalMargins = pageSetupDialog.PageSettings.Margins; if (System.Globalization.RegionInfo.CurrentRegion.IsMetric && !MonoHelper.IsRunningOnMono) { // This is necessary because of a bug in PageSetupDialog control. // More information: http://support.microsoft.com/?id=814355 pageSetupDialog.PageSettings.Margins = PrinterUnitConvert.Convert( pageSetupDialog.PageSettings.Margins, PrinterUnit.Display, PrinterUnit.TenthsOfAMillimeter); } if (pageSetupDialog.ShowDialog() == DialogResult.OK) { printPreview.InvalidatePreview(); } else { pageSetupDialog.PageSettings.Margins = originalMargins; } }
// <Snippet1> public void Printing() { try{ streamToPrint = new StreamReader(filePath); try{ printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); pd.PrinterSettings.PrinterName = printer; // Create a new instance of Margins with 1-inch margins. Margins margins = new Margins(100, 100, 100, 100); pd.DefaultPageSettings.Margins = margins; pd.Print(); } finally{ streamToPrint.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { Color barColor = Color.FromArgb(50, 130, 190); Color hoverColor = Color.FromArgb(255, 0, 0); GridAddress address = new GridAddress(1, 1); int width = 1000; int height = 500; string yAxisLabel = "Label"; int tickMarks = 2; bool xRotation = false; Margins margins = new Margins(); DA.GetData <Color>(0, ref barColor); DA.GetData <Color>(1, ref hoverColor); DA.GetData <GridAddress>(2, ref address); DA.GetData <Margins>(3, ref margins); DA.GetData <int>(4, ref width); DA.GetData <int>(5, ref height); DA.GetData <string>(6, ref yAxisLabel); DA.GetData <int>(7, ref tickMarks); DA.GetData <bool>(8, ref xRotation); // create style BarStyle style = new BarStyle(); style.BarColor = barColor; style.BarHoverColor = hoverColor; style.GridRow = address.X; style.GridColumn = address.Y; style.Width = width; style.Height = height; style.YAxisLabel = yAxisLabel; style.TickMarksX = tickMarks; style.xTextRotation = xRotation; style.Margins = margins; DA.SetData(0, style); }
private void LoadReport() { rptViewer.ProcessingMode = ProcessingMode.Local; var pagerSize = new PaperSize() { Height = 1169, Width = 827 }; var margins = new Margins() { Bottom = 50, Left = 50, Right = 50, Top = 50 }; PageSettings ps = new PageSettings(); ps.PaperSize = pagerSize; ps.Margins = margins; ps.PrinterSettings.DefaultPageSettings.PaperSize = pagerSize; ps.PrinterSettings.DefaultPageSettings.Margins = margins; rptViewer.SetPageSettings(ps); rptViewer.LocalReport.ReportPath = ReportPath; rptViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LoadSubreport); rptViewer.LocalReport.DataSources.Clear(); rptViewer.LocalReport.DataSources.Add(GetDataSource()); //var reportMargins = rptViewer.LocalReport.GetDefaultPageSettings().Margins; //reportMargins.Left = 0; //reportMargins.Right = 0; //reportMargins.Top = 0; //reportMargins.Bottom = 0; //rptViewer.LocalReport.GetDefaultPageSettings().PaperSize.Height = pagerSize.Height; //rptViewer.LocalReport.GetDefaultPageSettings().PaperSize.Width = pagerSize.Width; rptViewer.RefreshReport(); }
/// <summary> /// Pie Chart Style /// </summary> /// <param name="HoverColor">Hover over color.</param> /// <param name="Colors">List of optional colors for chart values.</param> /// <param name="Address">Grid Coordinates.</param> /// <param name="Margins">Margins in pixels.</param> /// <param name="Width">Width of chart in pixels.</param> /// <param name="Labels">Boolean value that controls if Labels are displayed.</param> /// <returns name="Style">Pie Chart Style object.</returns> public static PieChartStyle Style( [DefaultArgument("DSCore.Color.ByARGB(1,255,0,0)")] DSCore.Color HoverColor, [DefaultArgumentAttribute("Charts.MiscNodes.GetNull()")] List <DSCore.Color> Colors, [DefaultArgument("Charts.MiscNodes.GetNull()")] GridAddress Address, [DefaultArgument("Charts.MiscNodes.Margins()")] Margins Margins, int Width = 400, bool Labels = true) { PieChartStyle style = new PieChartStyle(); style.Width = Width; style.HoverColor = sColor.FromArgb(HoverColor.Alpha, HoverColor.Red, HoverColor.Green, HoverColor.Blue); style.Labels = Labels; style.Margins = Margins; if (Colors != null) { List <string> hexColors = Colors.Select(x => ChartsUtilities.ColorToHexString(sColor.FromArgb(x.Alpha, x.Red, x.Green, x.Blue))).ToList(); style.Colors = hexColors; } else { style.Colors = null; } if (Address != null) { style.GridRow = Address.X; style.GridColumn = Address.Y; } else { style.GridRow = 1; style.GridColumn = 1; } return(style); }
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) { RectangleF area = printDocument.DefaultPageSettings.PrintableArea; Margins margins = printDocument.DefaultPageSettings.Margins; area.X += margins.Left; area.Y += margins.Top; area.Width = area.Width - margins.Left - margins.Right; area.Height = area.Height - margins.Top - margins.Bottom; if (area.Width > 0 && area.Height > 0) { //BestFit sizing and center to image RectangleF dstRect = new RectangleF(); float aspec = (float)bitmap.Width / (float)bitmap.Height; float pageAspect = (float)area.Width / (float)area.Height; float zoom; if (aspec > pageAspect) { zoom = (area.Width / (float)bitmap.Width); dstRect.Width = area.Width; dstRect.X = area.X; dstRect.Height = (float)Math.Round((dstRect.Width / aspec)); dstRect.Y = (printDocument.DefaultPageSettings.PrintableArea.Height - dstRect.Height) / 2.0f; } else { zoom = ((float)area.Height / (float)bitmap.Height); dstRect.Height = area.Height; dstRect.Y = area.Y; dstRect.Width = (float)Math.Round((dstRect.Height * aspec)); dstRect.X = (printDocument.DefaultPageSettings.PrintableArea.Width - dstRect.Width) / 2.0f; } e.Graphics.DrawImage(bitmap, dstRect); } }
/// <summary> /// 打印小票 /// </summary> public void PrintReceipt(bool isRefund) { isrefund = isRefund; //打印预览 PrintPreviewDialog ppd = new PrintPreviewDialog(); PrintDocument pd = new PrintDocument(); //设置边距 Margins margin = new Margins(20, 20, 20, 20); pd.DefaultPageSettings.Margins = margin; //纸张设置默认 PaperSize pageSize = new PaperSize("First custom size", getYc(58), 600); pd.DefaultPageSettings.PaperSize = pageSize; //打印事件设置 pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); //ppd.Document = pd; //ppd.ShowDialog(); try { PrintController printController = new StandardPrintController(); pd.PrintController = printController; pd.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error); pd.PrintController.OnEndPrint(pd, new PrintEventArgs()); } }
private void printBmpFile(bool isPrintPreview) { PrintDocument pd = new PrintDocument(); //ÉèÖñ߾à Margins margin = new Margins(0, 0, 80, 80); pd.DefaultPageSettings.Margins = margin; pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); try { PageSetupDialog psd = new PageSetupDialog(); psd.Document = pd; psd.PageSettings.Landscape = true; if (isPrintPreview) { //´òÓ¡Ô¤ÀÀ PrintPreviewDialog ppd = new PrintPreviewDialog(); ppd.Document = pd; if (DialogResult.OK == ppd.ShowDialog()) { pd.Print(); } } else { pd.Print(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "´òÓ¡³ö´í", MessageBoxButtons.OK, MessageBoxIcon.Error); pd.PrintController.OnEndPrint(pd, new PrintEventArgs()); } }
private void buttonTisk_Click(object sender, EventArgs e) { buttonNastavit.Focus(); printDocument1.DefaultPageSettings.Landscape = true; pd = new PrintDocument(); Margins margins = new Margins(5, 5, 5, 5); pd.DefaultPageSettings.Margins = margins; ScreenShot(); pd.PrintPage += PrintPage; PrintDialog printDialog1 = new PrintDialog(); printDialog1.Document = pd; Image img = Image.FromFile(main.path + "\\DIMOS\\" + main.poleKaret.IndexOf(karta) + ".png"); if ((double)img.Width > (double)img.Height) // obrazek je širší { pd.DefaultPageSettings.Landscape = true; } else { pd.DefaultPageSettings.Landscape = false; } DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) { pd.Print(); } }
public Margins(Margins edge) : base(edge) { }
private void PositionControls() { if (txtMain != null) { txtMain.Left = channelsVisible ? cmbMain.Width + 1 : 0; txtMain.Width = channelsVisible ? Width - cmbMain.Width - 1 : Width; if (textBoxVisible) { ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top + 4, sbVert.Width + 6, txtMain.Height + 4); sbVert.Height = Height - txtMain.Height - 5; } else { ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top + 4, sbVert.Width + 6, 2); sbVert.Height = Height - 4; } Invalidate(); } }
public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref Margins pMarInset);
protected override void AdjustMargins() { if (captionVisible && borderVisible) { ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.Layers[lrCaption].Height, Skin.ClientMargins.Right, Skin.ClientMargins.Bottom); } else if (!captionVisible && borderVisible) { ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top, Skin.ClientMargins.Right, Skin.ClientMargins.Bottom); } else if (!borderVisible) { ClientMargins = new Margins(0, 0, 0, 0); } if (btnClose != null) { btnClose.Visible = closeButtonVisible && captionVisible && borderVisible; } SetMovableArea(); base.AdjustMargins(); }
public static extern int DwmExtendFrameIntoClientArea(int hWnd, ref Margins Mgns);
public extern static int GetThemeMargins(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, int iPropId, IntPtr rect, out Margins pMargins);
public static Margins Convert(Margins value, PrinterUnit fromUnit, PrinterUnit toUnit) {}
public static Margins FromRectangle(Rectangle rectangle) { var margins = new Margins(); margins.left = rectangle.Left; margins.right = rectangle.Right; margins.top = rectangle.Top; margins.bottom = rectangle.Bottom; return margins; }
internal void SetAnchorMargins() { if (Parent != null) { anchorMargins.Left = Left; anchorMargins.Top = Top; anchorMargins.Right = Parent.VirtualWidth - Width - Left; anchorMargins.Bottom = Parent.VirtualHeight - Height - Top; } else { anchorMargins = new Margins(); } }
internal static extern int DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);
public static Margins FromRectangle(Rectangle rectangle) { var margins = new Margins { left = rectangle.Left, right = rectangle.Right, top = rectangle.Top, bottom = rectangle.Bottom }; return margins; }
protected override void AdjustMargins() { int l = 0; int t = 0; int r = 0; int b = 0; int s = bevelMargin; if (bevelBorder != EBevelBorder.None) { if (bevelStyle != EBevelStyle.Flat) { s += 2; } else { s += 1; } if (bevelBorder == EBevelBorder.Left || bevelBorder == EBevelBorder.All) { l = s; } if (bevelBorder == EBevelBorder.Top || bevelBorder == EBevelBorder.All) { t = s; } if (bevelBorder == EBevelBorder.Right || bevelBorder == EBevelBorder.All) { r = s; } if (bevelBorder == EBevelBorder.Bottom || bevelBorder == EBevelBorder.All) { b = s; } } ClientMargins = new Margins(Skin.ClientMargins.Left + l, Skin.ClientMargins.Top + t, Skin.ClientMargins.Right + r, Skin.ClientMargins.Bottom + b); base.AdjustMargins(); }
private static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);
protected override void AdjustMargins() { base.AdjustMargins(); ClientMargins = new Margins(ClientMargins.Left, ClientMargins.Top, ClientMargins.Right + 16, ClientMargins.Bottom); }
public static extern void DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);
/// <summary> /// Sets value for one or more margins using flags. /// </summary> /// <param name="margin">Margin flags.</param> /// <param name="value">Value to set.</param> public void SetMargins(Margins margin, int value) { if ((margin & Margins.Top) == Margins.Top) TopMargin = value; if ((margin & Margins.Bottom) == Margins.Bottom) BottomMargin = value; if ((margin & Margins.Left) == Margins.Left) LeftMargin = value; if ((margin & Margins.Right) == Margins.Right) RightMargin = value; }
static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);
DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);
public static void SetMargins(Margins _guiMargins, GameObject _gameObject) { _gameObject.transform.localPosition = new Vector3(_gameObject.transform.localPosition.x + (_guiMargins.Left - _guiMargins.Right), _gameObject.transform.localPosition.y + (_guiMargins.Bottom - _guiMargins.Top), 0); }
internal static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref Margins m);