1. Tag Results
groupbox (2)
1 - 2 of 2
How to print the barcode in Windows Forms?
Syncfusion WinForms Barcode control  helps rendering barcodes in desktop application. The control can be merged with any desktop application and easy to encode text using the supported symbol types. The basic structure of a barcode consists of a leading and trailing quiet zone, a start pattern, one or more data characters, optionally one or two check characters, and a stop pattern. Using this control, you can print the barcode in Windows Forms. Steps to print the barcode programmatically: Create a new C# Windows Forms application project. Install the Syncfusion.SfBarcode.Windows NuGet package as reference to your .NET Framework application from NuGet.org. Include the following namespaces in the Form1.Designer.cs file.// [C# Code] using System.Drawing; using System.Drawing.Printing; using Syncfusion.Windows.Forms.Barcode; using System.Windows.Forms;   ' [VB Code] Imports System.Drawing Imports System.Drawing.Printing Imports Syncfusion.Windows.Forms.Barcode Imports System.Windows.Forms   Use the following code snippet to print the barcode.// [C# Code] //Initialize the Barcode control SfBarcode barcode = new SfBarcode(); //Set the barcode symbology type barcode.Symbology = BarcodeSymbolType.Code128A; //Set the input text barcode.Text = textBox1.Text; //Set the barcode size barcode.Size = pictureBox1.Size; //Export the Barcode control as image pictureBox1.Image = barcode.ToImage(); bitmap = new Bitmap(barcode.ToImage()); //Initialize the print document PrintDocument printDocument = new PrintDocument(); PrintDialog pdialog = new PrintDialog(); if (pdialog.ShowDialog() == DialogResult.OK) {     printDocument.PrinterSettings.PrinterName = pdialog.PrinterSettings.PrinterName;     //Triggers to print current page     printDocument.PrintPage += printDocument_PrintPage;     printDocument.Print(); }   // Event handler to save the PrintDocument page as image void printDocument_PrintPage(object sender, PrintPageEventArgs e) {     //Draw barcode into PDF page     e.Graphics.DrawImage(bitmap, 0, 0);     e.HasMorePages = false; }   ' [VB Code] 'Initialize the Barcode control Dim barcode As New SfBarcode() 'Set the barcode symbology type barcode.Symbology = BarcodeSymbolType.Code128A 'Set the input text barcode.Text = TextBox1.Text 'Set the barcode size barcode.Size = PictureBox1.Size 'Export the Barcode control as image PictureBox1.Image = barcode.ToImage() Bitmap = New Bitmap(barcode.ToImage()) 'Initialize the print document Dim printDocument As New PrintDocument() Dim pdialog As New PrintDialog() If pdialog.ShowDialog() = DialogResult.OK Then     printDocument.PrinterSettings.PrinterName = pdialog.PrinterSettings.PrinterName     'Triggers to print current page     AddHandler printDocument.PrintPage, AddressOf printDocument_PrintPage     printDocument.Print() End If   'Event handler to save the PrintDocument page as image Private Sub printDocument_PrintPage(sender As Object, e As PrintPageEventArgs)     'Draw barcode into PDF page     e.Graphics.DrawImage(Bitmap, 0, 0)     e.HasMorePages = False End Sub   Download the complete work sample from BarcodeSample.zip. Take a moment to peruse the documentation, where you can find barcode customization, symbology settings for 1D and 2D barcodes with code examples. Refer here to explore the barcode control for Windows Forms. Note:Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.        
How to achieve the GroupBox appearance in Gradient panel?
GroupBox appearance can be achieved by creating the custom control from the Gradient Panel.   The following code example demonstrates the same. C# /// <summary> /// Overrides the paint event. /// </summary> /// <param name="e">The PaintEventArgs contains the event data.</param> protected override void OnPaint(PaintEventArgs e) {     base.OnPaint(e);     PaintBackGround(e.Graphics);     PaintHeaderText(e.Graphics); }   /// <summary> /// This method helps paint the title of the GradientPanelAdv. /// </summary> /// <param name="g">The Graphics object for paint event handler.</param> private void PaintHeaderText(System.Drawing.Graphics g) {     //To check whether if string has something     if (this.HeaderText == string.Empty) { return; }       //To set graphics smoothing mode to Anit-Alias     g.SmoothingMode = SmoothingMode.AntiAlias;       //To declare the variables     SizeF StringSize = g.MeasureString(this.HeaderText, this.Font);     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();     System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor);     System.Drawing.Brush BackgroundBrush = new SolidBrush(this.BackColor);     System.Drawing.SolidBrush TextColorBrush = new SolidBrush(this.ForeColor);                path.AddRectangle(new Rectangle(this.ClientRectangle.X + 20, this.ClientRectangle.Y + 5, (int)Math.Ceiling(StringSize.Width) + 10, (int)Math.Ceiling(StringSize.Height)));                 if (this.BackgroundColor.GradientStyle == GradientStyle.None)     {         //To paint text rectangle         g.FillPath(BackgroundBrush, path);     }                 //To draw the header text     g.DrawString(this.HeaderText, this.Font, TextColorBrush, 26, 5);       // To destroy Graphic Objects     if (path != null) { path.Dispose(); }     if (BorderBrush != null) { BorderBrush.Dispose(); }     if (BackgroundBrush != null) { BackgroundBrush.Dispose(); }     if (TextColorBrush != null) { TextColorBrush.Dispose(); } }   /// <summary> /// To paint the background of the GradientPanelExt. /// </summary> /// <param name="g">The Graphics object for paint event handler.</param> private void PaintBackGround(System.Drawing.Graphics g) {     //To set Graphics smoothing mode to Anit-Alias     g.SmoothingMode = SmoothingMode.AntiAlias;       //To declare Variables     int ArcWidth = 20; int ArcHeight = 20;     int ArcX1 = 0; int ArcX2 = this.Width - (ArcWidth + 1);     int ArcY1 = 10; int ArcY2 = this.Height - (ArcHeight + 1);       System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();     System.Drawing.Brush BorderBrush = new SolidBrush(this.BorderColor);     System.Drawing.Pen BorderPen = new Pen(BorderBrush, this.BorderThickness);                 //To create rounded rectangle path     graphicsPath.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, 90); // Top Left     graphicsPath.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, 90); //Top Right     graphicsPath.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, 90); //Bottom Right     graphicsPath.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, 90); //Bottom Left     graphicsPath.CloseAllFigures();                 //To draw a border     g.DrawPath(BorderPen, graphicsPath);       //To destroy Graphic Objects     if (graphicsPath != null) { graphicsPath.Dispose(); }     if (BorderBrush != null) { BorderBrush.Dispose(); }     if (BorderPen != null) { BorderPen.Dispose(); } }   VB ''' <summary> ''' Overrides the paint event ''' </summary> ''' <param name="e"> The PaintEventArgs contains the event data.</param> Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)  MyBase.OnPaint(e)  PaintBackGround(e.Graphics)  PaintHeaderText(e.Graphics) End Sub   ''' <summary> ''' This method helps paint the title of the GradientPanelAdv. ''' </summary> ''' <param name="g">The Graphics object for paint event handler.</param> Private Sub PaintHeaderText(ByVal g As System.Drawing.Graphics)  'To check whether if string has something  If Me.HeaderText = String.Empty Then   Return  End If    'To set graphics smoothing mode to Anit-Alias  g.SmoothingMode = SmoothingMode.AntiAlias    'To declare the variables  Dim StringSize As SizeF = g.MeasureString(Me.HeaderText, Me.Font)  Dim path As New System.Drawing.Drawing2D.GraphicsPath()  Dim BorderBrush As System.Drawing.Brush = New SolidBrush(Me.BorderColor)  Dim BackgroundBrush As System.Drawing.Brush = New SolidBrush(Me.BackColor)  Dim TextColorBrush As System.Drawing.SolidBrush = New SolidBrush(Me.ForeColor)    path.AddRectangle(New Rectangle(Me.ClientRectangle.X + 20, Me.ClientRectangle.Y + 5, CInt(Fix(Math.Ceiling(StringSize.Width))) + 10, CInt(Fix(Math.Ceiling(StringSize.Height)))))    If Me.BackgroundColor.GradientStyle = GradientStyle.None Then   'To paint text rectangle   g.FillPath(BackgroundBrush, path)  End If    'To draw the header text  g.DrawString(Me.HeaderText, Me.Font, TextColorBrush, 26, 5)    ' To destroy Graphic Objects  If path IsNot Nothing Then   path.Dispose()  End If  If BorderBrush IsNot Nothing Then   BorderBrush.Dispose()  End If  If BackgroundBrush IsNot Nothing Then   BackgroundBrush.Dispose()  End If  If TextColorBrush IsNot Nothing Then   TextColorBrush.Dispose()  End If End Sub   ''' <summary> ''' To paint the background of the GradientPanelExt. ''' </summary> ''' <param name="g">The Graphics object for paint event handler.</param> Private Sub PaintBackGround(ByVal g As System.Drawing.Graphics)  'To set Graphics smoothing mode to Anit-Alias  g.SmoothingMode = SmoothingMode.AntiAlias    'To declare Variables  Dim ArcWidth As Integer = 20  Dim ArcHeight As Integer = 20  Dim ArcX1 As Integer = 0  Dim ArcX2 As Integer = Me.Width - (ArcWidth + 1)  Dim ArcY1 As Integer = 10  Dim ArcY2 As Integer = Me.Height - (ArcHeight + 1)    Dim graphicsPath As New System.Drawing.Drawing2D.GraphicsPath()  Dim BorderBrush As System.Drawing.Brush = New SolidBrush(Me.BorderColor)  Dim BorderPen As System.Drawing.Pen = New Pen(BorderBrush, Me.BorderThickness)    'To create rounded rectangle path  graphicsPath.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, 90) ' Top Left  graphicsPath.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, 90) 'Top Right  graphicsPath.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, 90) 'Bottom Right  graphicsPath.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, 90) 'Bottom Left  graphicsPath.CloseAllFigures()    'To draw a border  g.DrawPath(BorderPen, graphicsPath)    'To destroy Graphic Objects  If graphicsPath IsNot Nothing Then   graphicsPath.Dispose()  End If  If BorderBrush IsNot Nothing Then   BorderBrush.Dispose()  End If  If BorderPen IsNot Nothing Then   BorderPen.Dispose()  End If End Sub   Figure 1: GradientPanel customization. Sample Links:   C#: GradientPanel_GroupBoxAppearance_C# VB: GradientPanel_GroupBoxAppearance_VB
No articles found
No articles found
1 of 1 pages (2 items)