Remove text box border in C#, VB.NET
Syncfusion® Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. It also, converts Excel documents to PDF files. Using this library, you can remove the border line for an Excel text box.
Steps to remove the border line of a text box, programmatically:
Step 1: Create a new C# console application project.
Create a new C# console application project
Step 2: Install the Syncfusion.XlsIO.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.
Install NuGet package to the project
Step 3: The border line for an Excel text box can be removed by disabling the Visible property available under the IShapeLineFormat interface.
C#
// Remove the border line for text box chart.TextBoxes[0].Line.Visible = false;
VB.NET
'Remove the border line for text box chart.TextBoxes(0).Line.Visible = False
Step 4: Add an Excel file to you project and make it an embedded resource using the following steps.
- In Visual Studio, click the Project menu and select Add Existing Item. Find and select the Excel file you want to add to your project.
- In the Solution Explorer window, right-click on the Excel file you just added to your project and select Properties from the popup menu. The Properties tool window appears.
- In the Properties window, change the Build Action property to Embedded Resource.
- Build the project. The Excel file will be compiled into your project’s assembly.
Step 5: Include the following namespaces in Program.cs file.
C#
using Syncfusion.XlsIO; using System.IO; using System.Reflection;
VB.NET
Imports Syncfusion.XlsIO Imports System.IO Imports System.Reflection
Step 6: Include the following code snippet in main method of Program.cs file to remove the border line of an Excel text box.
C#
using (ExcelEngine excelEngine = new ExcelEngine()) { // Initialize the Excel application object IApplication application = excelEngine.Excel; // Load an existing Excel document into IWorkbook Assembly assembly = typeof(Program).GetTypeInfo().Assembly; Stream inputStream = assembly.GetManifestResourceStream("RemoveBorder.Sample.xlsx"); IWorkbook workbook = application.Workbooks.Open(inputStream); // Get the first worksheet in the workbook into IWorksheet IWorksheet worksheet = workbook.Worksheets[0]; // Get the chart in the worksheet into IChartShape IChartShape chart = workbook.Worksheets[0].Charts[0]; // Add a text box in the chart chart.TextBoxes.AddTextBox(1, 1, 100, 200); // Set the position for the text box chart.TextBoxes[0].Top = 850; chart.TextBoxes[0].Left = 765; // Add text for the text box chart.TextBoxes[0].Text = "Yearly Profit"; // Remove the border line for text box chart.TextBoxes[0].Line.Visible = false; // Save the Excel document workbook.SaveAs("Output.xlsx"); }
VB.NET
Using excelEngine As ExcelEngine = New ExcelEngine() 'Initialize the Excel application object Dim application As IApplication = excelEngine.Excel 'Load an existing Excel document into IWorkbook Dim assembly As Assembly = GetType(Module1).GetTypeInfo.Assembly Dim inputStream As Stream = assembly.GetManifestResourceStream("RemoveBorder.Sample.xlsx") Dim workbook As IWorkbook = application.Workbooks.Open(inputStream) 'Get the first worksheet in the workbook into IWorksheet Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Get the chart in the worksheet into IChartShape Dim chart As IChartShape = workbook.Worksheets(0).Charts(0) 'Add a text box in the chart chart.TextBoxes.AddTextBox(1, 1, 100, 200) 'Set the position for the text box chart.TextBoxes(0).Top = 850 chart.TextBoxes(0).Left = 765 'Add text for the text box chart.TextBoxes(0).Text = "Yearly Profit" 'Remove the border line for text box chart.TextBoxes(0).Line.Visible = False 'Save the Excel document workbook.SaveAs("Output.xlsx") End Using
A complete working sample of how to remove the border line for an Excel text box can be downloaded from RemoveBorder.zip.
By executing the program, you will get the output Excel file as follows.
Output Excel document
Take a moment to peruse the documentation, where you will find other options like form controls, comments, auto shapes, group shapes, and OLE objects will code samples.
Click here to explore the rich set of Syncfusion® Excel (XlsIO) library features.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion
I hope you enjoyed learning about Remove text box border in C#, VB.NET.
You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion® components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!