PBTutil 1.0.0

dotnet add package PBTutil --version 1.0.0
NuGet\Install-Package PBTutil -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PBTutil" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PBTutil --version 1.0.0
#r "nuget: PBTutil, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PBTutil as a Cake Addin
#addin nuget:?package=PBTutil&version=1.0.0

// Install PBTutil as a Cake Tool
#tool nuget:?package=PBTutil&version=1.0.0

PBTutils is a library for Winforms users to facilitate putting text into images and picturebox controls. It contains the following functions:

Point DrawCenterLineString(string text, ...) Draws text in the center of the current line and returns new text position in Point format.

void DrawCenterString(string text, ...) Draws text in the center of the image or picturebox.

Point DrawOutlinedString(string text, ...) Draws text with outline and fill colors and returns the new text position in Point format.

Point DrawStringC(string text, ...) Draws text and returns the new text position (to the right of the string) in Point format.

Point DrawStringR(string text, ...) Draws text and returns the new text position (on the next "line") in Point format.

Size GetTextSize(string text, ...) Returns the size needed to draw text.

Point MakeCenterLine(string text, ...) Returns the point needed to draw the text in the center of the current line.

Point MakeCenter(string text, ...) Returns the point needed to draw the text in the center of the image or picturebox.


The following functions set the various parameters used by the previous functions:

void SetPictureBox(PictureBox? picturebox) void SetImage(Image? image) void SetPosition(Point? point) void SetFont(Font? font) void SetFontFamily(FontFamily? fontfamily) void SetFontStyle(FontStyle? fontstyle) void SetFontName(string fontname) void SetFontSize(float? fontsize) void SetSize(Size? size) void SetColor(Color? color) void SetBrush(SolidBrush? brush) void SetPen(Pen? pen) void SetClear(bool cleararea) void SetBackColor(Color? backcolor) void SetBackBrush(SolidBrush? backbrush) void SetBackPen(Pen? backpen) void SetOutlineColor(Color? outlinecolor) void SetOutlineBrush(SolidBrush? outlinebrush) void SetOutlinePen(Pen? outlinepen) void SetOutlineSize(int? outlinesize)


Notice that all the main functions above had a ", ...)" to them. This was to indicate the optional parameters, which are equal to the above Set functions. In order, these are:

PictureBox? picturebox = null Image? image = null Point? position = null Font? font = null FontFamily? fontfamily = null FontStyle? fontstyle = null string? fontname = null float? fontsize = null Size? size = null Color? color = null SolidBrush? brush = null Pen? pen = null bool cleararea = false Color? backcolor = null SolidBrush? backbrush = null Pen? backpen = null Color? outlinecolor = null SolidBrush? outlinebrush = null Pen? outlinepen = null int? outlinesize = null

You can use any number of these optional parameters or only define them using Set... functions as above. You MUST define either picturebox or image in order to do anything. The rest of these will either be computed by what values it has or given defaults as below:

position = new Point(0, 0); font = new Font("Courier New",16) fontfamily = new FontFamily("Courier New") fontname = "Courier New" fontsize = 16 size is special in that it is computed only during operation and is not otherwise needed, it is the size of the current text in the current font. color = Color.Black brush = new SolidBrush(Color.Black) pen = new Pen(Color.Black) cleararea = false backcolor = Color.White backbrush = new SolidBrush(Color.White) backpen = new Pen(Color.White) outlinecolor = Color.Gray outlinebrush = new SolidBrush(Color.Gray) outlinepen = new Pen(Color.Gray) outlinesize = 1

From these defaults, you can tell that only a few of the parameters actually need to be set. For instance,

Bitmap bitmap = new(400, 400); //makes a 400 by 400 bitmap Point pos = new(1, 12); //set current position pos = DrawCenterLineString("centered", image = bitmap, position = pos, fontname = "Arial Black", fontsize = 20, fontstyle = FontStyle.Bold);

This code will create a bitmap, set a position of 1, 12, draw the text "centered" in the middle of the "line" in the font Arial Black with a font size of 20 and in bold. After execution, pos will be set to 0 for horizontal and 12 + height of the text for vertical. In this way, you can easily follow it with more commands, letting PBTutils keep track of the position for you. After this, you'd simply want to say:

pictureBox1.Image = bitmap; //set pictureBox1's image to be bitmap pictureBox1.Invalidate(); //tell windows to repaint pictureBox1

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 144 6/13/2023