Click here to Skip to main content
15,914,413 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help on setting index of dropdownlist. Pin
macupryk21-Sep-04 12:32
macupryk21-Sep-04 12:32 
GeneralRe: Help on setting index of dropdownlist. Pin
Colin Angus Mackay21-Sep-04 12:47
Colin Angus Mackay21-Sep-04 12:47 
GeneralRe: Help on setting index of dropdownlist. Pin
macupryk21-Sep-04 13:00
macupryk21-Sep-04 13:00 
GeneralRe: Help on setting index of dropdownlist. Pin
Colin Angus Mackay21-Sep-04 13:12
Colin Angus Mackay21-Sep-04 13:12 
GeneralConfigurable font height/width Pin
Yaron K.21-Sep-04 7:44
Yaron K.21-Sep-04 7:44 
GeneralRe: Configurable font height/width Pin
Heath Stewart21-Sep-04 11:33
protectorHeath Stewart21-Sep-04 11:33 
GeneralRe: Configurable font height/width Pin
Yaron K.21-Sep-04 19:01
Yaron K.21-Sep-04 19:01 
GeneralRe: Configurable font height/width Pin
Yaron K.22-Sep-04 22:37
Yaron K.22-Sep-04 22:37 
I think I got it to do what I want. Here is the code

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;

namespace FontSizeTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtH;
private System.Windows.Forms.TextBox txtW;
private System.Windows.Forms.TextBox txtStr;
private System.Windows.Forms.Button btnGo;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.IContainer components;

public Form1()
{
InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.panel2 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtH = new System.Windows.Forms.TextBox();
this.txtW = new System.Windows.Forms.TextBox();
this.txtStr = new System.Windows.Forms.TextBox();
this.btnGo = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// panel2
//
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this.label1);
this.panel2.Controls.Add(this.txtH);
this.panel2.Controls.Add(this.txtW);
this.panel2.Controls.Add(this.txtStr);
this.panel2.Controls.Add(this.btnGo);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 165);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(336, 80);
this.panel2.TabIndex = 12;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.Location = new System.Drawing.Point(164, 30);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(128, 16);
this.label2.TabIndex = 16;
this.label2.Text = "Height (Millimeters)";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.Location = new System.Drawing.Point(20, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 16);
this.label1.TabIndex = 15;
this.label1.Text = "Width (Millimeters)";
//
// txtH
//
this.txtH.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtH.Location = new System.Drawing.Point(164, 54);
this.txtH.Name = "txtH";
this.txtH.Size = new System.Drawing.Size(64, 20);
this.txtH.TabIndex = 14;
this.txtH.Text = "15.00";
//
// txtW
//
this.txtW.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtW.Location = new System.Drawing.Point(20, 54);
this.txtW.Name = "txtW";
this.txtW.Size = new System.Drawing.Size(64, 20);
this.txtW.TabIndex = 13;
this.txtW.Text = "80.00";
//
// txtStr
//
this.txtStr.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtStr.Location = new System.Drawing.Point(20, 6);
this.txtStr.Name = "txtStr";
this.txtStr.Size = new System.Drawing.Size(268, 20);
this.txtStr.TabIndex = 12;
this.txtStr.Text = "This is the test string. change it or the box size";
//
// btnGo
//
this.btnGo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnGo.Location = new System.Drawing.Point(288, 40);
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(48, 32);
this.btnGo.TabIndex = 11;
this.btnGo.Text = "&Go";
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(336, 165);
this.pictureBox1.TabIndex = 13;
this.pictureBox1.TabStop = false;
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(336, 245);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}


void PrintScale(
Graphics gfx,
float widthMM, float heightMM, string text,
Brush color, float xMM, float yMM)
{
xMM /= widthMM;
yMM /= heightMM;
gfx.ScaleTransform(widthMM, heightMM, MatrixOrder.Append);
gfx.DrawString(text, new Font(Font.FontFamily, 1),color,xMM,yMM);

//restore
gfx.ScaleTransform(1/widthMM, 1/heightMM);//, MatrixOrder.Append);
}

void DoPaint2 (System.Windows.Forms.PaintEventArgs e)
{
SizeF sz;

string str5 = txtStr.Text;
int strLen = str5.Length;
float boxW=float.Parse(txtW.Text), boxH=float.Parse(txtH.Text);
float charW, charH;
float scaleX, scaleY;
Pen pen ;

e.Graphics.PageUnit = GraphicsUnit.Millimeter;

sz = e.Graphics.MeasureString(str5,new Font(Font.FontFamily,1)); //Find string length using font of size 1

charH = sz.Height; // character height
charW = sz.Width / strLen; // avg. character width
scaleY = boxH / charH;
scaleX = (boxW/strLen) / charW;

pen = new Pen(Brushes.Red,0.2f);
e.Graphics.DrawRectangle(pen, 5f,5f,boxW,boxH);

PrintScale(e.Graphics,scaleX,scaleY,str5, Brushes.Black,5f,5f);
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
try
{
DoPaint2 (e);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}

private void btnGo_Click(object sender, System.EventArgs e)
{
pictureBox1.Refresh();
}

}
}

Generalproblem with c# (help required) Pin
Anonymous21-Sep-04 7:30
Anonymous21-Sep-04 7:30 
GeneralRe: problem with c# (help required) Pin
tdciDoug21-Sep-04 10:39
tdciDoug21-Sep-04 10:39 
GeneralRe: problem with c# (help required) Pin
Christian Graus21-Sep-04 10:44
protectorChristian Graus21-Sep-04 10:44 
GeneralHelp with books Pin
krisst_k21-Sep-04 7:21
krisst_k21-Sep-04 7:21 
GeneralRe: Help with books Pin
Werdna22-Sep-04 6:18
Werdna22-Sep-04 6:18 
GeneralC# Downloader Pin
shiraztk21-Sep-04 7:11
shiraztk21-Sep-04 7:11 
GeneralRe: C# Downloader Pin
Dave Kreskowiak21-Sep-04 8:34
mveDave Kreskowiak21-Sep-04 8:34 
GeneralRe: C# Downloader Pin
Alex Korchemniy21-Sep-04 10:24
Alex Korchemniy21-Sep-04 10:24 
GeneralRe: C# Downloader Pin
Heath Stewart21-Sep-04 11:16
protectorHeath Stewart21-Sep-04 11:16 
GeneralRe: C# Downloader Pin
shiraztk21-Sep-04 18:03
shiraztk21-Sep-04 18:03 
GeneralRe: C# Downloader Pin
Heath Stewart22-Sep-04 6:46
protectorHeath Stewart22-Sep-04 6:46 
GeneralDatabase access freezing main application Pin
Jon G21-Sep-04 6:02
Jon G21-Sep-04 6:02 
GeneralRe: Database access freezing main application Pin
Nick Parker21-Sep-04 6:56
protectorNick Parker21-Sep-04 6:56 
GeneralRe: Database access freezing main application Pin
Jon G21-Sep-04 7:09
Jon G21-Sep-04 7:09 
GeneralSubscribing multiple forms to a single Resize event Pin
Bisbal21-Sep-04 5:16
sussBisbal21-Sep-04 5:16 
GeneralRe: Subscribing multiple forms to a single Resize event Pin
Heath Stewart21-Sep-04 7:08
protectorHeath Stewart21-Sep-04 7:08 
GeneralRe: Subscribing multiple forms to a single Resize event Pin
Bisbal22-Sep-04 4:46
sussBisbal22-Sep-04 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.